diff --git a/crates/ui-egui/src/panels/color_wheel.rs b/crates/ui-egui/src/panels/color_wheel.rs index 2a2a95d7ad..4886a04696 100644 --- a/crates/ui-egui/src/panels/color_wheel.rs +++ b/crates/ui-egui/src/panels/color_wheel.rs @@ -176,18 +176,20 @@ pub(crate) fn set(settings: &mut Settings, p: &Value, cms: &Cms) -> Result<(), S } /// The panel menu: Wheel View and Box View, Box Channel while the box shows, and OKLCH Sliders. +/// Each item runs `ui.colorWheel` through the app's command entry point; a checked view or channel +/// runs nothing. pub fn menu(app: &mut VectorcraftApp, ui: &mut Ui) { let set = app.ui.color_wheel.clone(); for (label, view) in [(tl!("Wheel View"), View::Wheel), (tl!("Box View"), View::Box)] { - if menu_item(ui, label, true, set.view == view) { - command(app, &json!({ "view": view.id() })).ok(); + if menu_item(ui, label, true, set.view == view) && set.view != view { + run(app, json!({ "view": view.id() })); } } ui.add_enabled_ui(set.view == View::Box, |ui| { ui.menu_button(format!(" {}", tl!("Box Channel")), |ui| { for ch in Channel::ALL { - if menu_item(ui, ch.name(), true, ch == set.channel) { - command(app, &json!({ "channel": ch.id() })).ok(); + if menu_item(ui, ch.name(), true, ch == set.channel) && ch != set.channel { + run(app, json!({ "channel": ch.id() })); } } }); @@ -198,9 +200,14 @@ pub fn menu(app: &mut VectorcraftApp, ui: &mut Ui) { let enabled = on || cms::active().rgb_is_srgb(); if widgets::menu_item_hint(ui, tl!("OKLCH Sliders"), enabled, on, tl!("OKLCH needs sRGB as the working RGB space")) { let sliders = if on { Sliders::None } else { Sliders::Oklch }; - if let Err(e) = app.run("ui.colorWheel", json!({ "sliders": sliders.id() })) { - app.status(e); - } + run(app, json!({ "sliders": sliders.id() })); + } +} + +/// Run `ui.colorWheel` with `p` from the panel menu, and show an error in the status bar. +fn run(app: &mut VectorcraftApp, p: Value) { + if let Err(e) = app.run("ui.colorWheel", p) { + app.status(e); } } diff --git a/crates/ui-egui/src/panels/tests_color_wheel_box.rs b/crates/ui-egui/src/panels/tests_color_wheel_box.rs index 2e0e6ae1a5..00eac74e97 100644 --- a/crates/ui-egui/src/panels/tests_color_wheel_box.rs +++ b/crates/ui-egui/src/panels/tests_color_wheel_box.rs @@ -300,7 +300,7 @@ fn the_settings_are_kept_and_read_leniently() { } /// The panel menu lists Wheel View and Box View with the shown one checked, and Box Channel; its -/// items set the view and the channel. +/// items set the view and the channel through the app's command entry point. #[test] fn the_panel_menu_switches_the_view_and_the_channel() { let mut app = app(json!("#ff0000"), "hue"); @@ -320,10 +320,17 @@ fn the_panel_menu_switches_the_view_and_the_channel() { ); h.run_steps(3); assert!(h.query_by_label("✓ Wheel View").is_some()); + let commands = h.state().run_count; h.get_by_label(" Box View").click(); h.run_steps(2); assert_eq!(h.state().ui.color_wheel.view, View::Box); + assert_eq!(h.state().run_count, commands.wrapping_add(1), "Box View runs one ui.colorWheel command"); assert!(h.query_by_label("✓ Box View").is_some()); + // The checked item runs nothing. + h.get_by_label("✓ Box View").click(); + h.run_steps(2); + assert_eq!(h.state().run_count, commands.wrapping_add(1), "the checked Box View runs no command"); + assert_eq!(h.state().ui.color_wheel.view, View::Box); } /// Every channel's box puts each color back where it reads it, and the strip's value is the