diff --git a/crates/ui-egui/src/panels.rs b/crates/ui-egui/src/panels.rs index 52649d6400..7e18b51179 100644 --- a/crates/ui-egui/src/panels.rs +++ b/crates/ui-egui/src/panels.rs @@ -167,9 +167,10 @@ fn corner_kind_row(app: &mut VectorcraftApp, ui: &mut Ui, n: &Node) { } /// A select of the corner kinds named `name`, showing `current` (blank for None), as wide as its -/// widest kind, so it fits beside a corner's radius field. Returns the kind picked. +/// widest kind, so it fits beside a corner's radius field. Returns the kind chosen, not one only +/// highlighted in the open list. fn corner_select(ui: &mut Ui, name: &'static str, current: Option, entries: &[Entry]) -> Option { - Select::new(name, Bind::given(current.map_or(Mixed::Mixed, Mixed::Same)), entries).sizing(Sizing::Content).show(ui).value().copied() + Select::new(name, Bind::given(current.map_or(Mixed::Mixed, Mixed::Same)), entries).sizing(Sizing::Content).show(ui).events.committed().copied() } /// Set `kind` on corner `corner` (every corner for None) of each selected live rectangle diff --git a/crates/ui-egui/src/panels/transform/tests.rs b/crates/ui-egui/src/panels/transform/tests.rs index bfad19d09b..a5f37234e1 100644 --- a/crates/ui-egui/src/panels/transform/tests.rs +++ b/crates/ui-egui/src/panels/transform/tests.rs @@ -158,6 +158,72 @@ fn a_rectangle_shows_linked_and_unlinked_corner_types() { assert!(!p.shows("Corner") && p.shows("Top Left Corner") && p.shows("Bottom Left Corner")); } +/// Checks a live rectangle's Corner menu `menu` drawn by `draw`, with Corner Radius linked +/// (`single`) or not: a kind highlighted in the open menu leaves the rectangle as it is, Escape +/// closes the menu with the kind and the undo history unchanged, and Enter sets the highlighted +/// kind, on the corners `changed` marks, as one undo step. +fn check_corner_kind_menu(draw: fn(&mut VectorcraftApp, &mut Ui), single: bool, menu: &str, changed: [bool; 4]) { + use craft::ui::contract::Role; + use egui::{Key, Modifiers}; + use vectorcraft_doc::{LiveCorners, NodeId}; + use vectorcraft_geom::shapes::CornerKind; + let mut app = new_app(); + let id = app.run("shape.rectangle", json!({"x": 50, "y": 50, "width": 120, "height": 80, "radius": 10})).unwrap()["id"].as_u64().unwrap(); + set_pref(&mut app, "singleCornerRadius", single); + let mut p = Panel::new(app, draw); + let kinds = |p: &Panel| { + let app = p.app(); + let corners = LiveCorners::of(app.session.active().unwrap().doc.node(NodeId(id)).unwrap()).unwrap(); + [0, 1, 2, 3].map(|k| corners.kind(k)) + }; + let original = p.app().session.active().unwrap().doc.clone(); + assert_eq!(kinds(&p), [CornerKind::ALL[0]; 4]); + let undo = undo_depth(&p.app()); + + p.click_role(menu, Role::COMBO_BOX); + p.key(Key::ArrowDown, Modifiers::NONE); + assert!(p.app().session.active().unwrap().doc == original, "{menu}: highlighting a kind leaves the rectangle as it was"); + p.key(Key::Escape, Modifiers::NONE); + assert!(p.shows(menu), "{menu}: the panel still shows the menu after Escape"); + assert!(p.app().session.active().unwrap().doc == original, "{menu}: Escape leaves the rectangle as it was"); + assert_eq!(undo_depth(&p.app()), undo, "{menu}: Escape records no undo step"); + + p.click_role(menu, Role::COMBO_BOX); + p.key(Key::ArrowDown, Modifiers::NONE); + p.key(Key::Enter, Modifiers::NONE); + let expected = changed.map(|c| if c { CornerKind::ALL[1] } else { CornerKind::ALL[0] }); + assert_eq!(kinds(&p), expected, "{menu}: Enter sets the highlighted kind"); + assert_eq!(undo_depth(&p.app()), undo + 1, "{menu}: the kind is one undo step"); +} + +/// The Transform panel's Corner menu for all four corners of a live rectangle applies only the +/// kind chosen. +#[test] +fn transform_panel_rectangle_corner_kind_applies_only_when_chosen() { + check_corner_kind_menu(show, true, "Corner", [true; 4]); +} + +/// The Transform panel's Corner menu for one corner of a live rectangle applies only the kind +/// chosen. +#[test] +fn transform_panel_single_rectangle_corner_kind_applies_only_when_chosen() { + check_corner_kind_menu(show, false, "Top Right Corner", [false, true, false, false]); +} + +/// The Properties panel's Corner menu for all four corners of a live rectangle applies only the +/// kind chosen. +#[test] +fn properties_panel_rectangle_corner_kind_applies_only_when_chosen() { + check_corner_kind_menu(crate::panels::properties::transform_section, true, "Corner", [true; 4]); +} + +/// The Properties panel's Corner menu for one corner of a live rectangle applies only the kind +/// chosen. +#[test] +fn properties_panel_single_rectangle_corner_kind_applies_only_when_chosen() { + check_corner_kind_menu(crate::panels::properties::transform_section, false, "Top Right Corner", [false, true, false, false]); +} + /// The four corner labels of an unlinked Corner Radius, in the Transform panel and in the /// Properties panel, start at one edge of their column whatever their widths, and the radius /// fields after them line up.