diff --git a/crates/ui-egui/src/panels.rs b/crates/ui-egui/src/panels.rs index 2d1ea7cfb9..aaabbaa41e 100644 --- a/crates/ui-egui/src/panels.rs +++ b/crates/ui-egui/src/panels.rs @@ -155,13 +155,17 @@ pub(crate) fn corner_radius_row(app: &mut VectorcraftApp, ui: &mut Ui, n: &Node) } /// The Corner select of a live rectangle whose corners share one radius field: the kind of all -/// four corners, also while some of them are Direct-Selected, blank when they differ. A pick sets -/// it on every corner of each selected live rectangle ([`set_rectangle_kinds`]). +/// four corners, also while some of them are Direct-Selected, blank when they differ. It is one +/// number cell wide, as the Corner Radius field above it is. A pick sets it on every corner of each +/// selected live rectangle ([`set_rectangle_kinds`]). fn corner_kind_row(app: &mut VectorcraftApp, ui: &mut Ui, n: &Node) { let Some(lc) = LiveCorners::of(n) else { return }; let entries = corner_entries(); - let current = lc.style(&lc.all()).1; - let picked = Field::new(tl!("Corner")).show(ui, |ui, _| corner_select(ui, tl!("Corner"), current, &entries)).inner.flatten(); + let current = lc.style(&lc.all()).1.map_or(Mixed::Mixed, Mixed::Same); + let picked = Field::new(tl!("Corner")) + .show(ui, |ui, _| Select::new(tl!("Corner"), Bind::given(current), &entries).number_cell().show(ui).events.committed().copied()) + .inner + .flatten(); if let Some(kind) = picked { set_rectangle_kinds(app, kind, None); } diff --git a/crates/ui-egui/src/panels/properties/transform_section.rs b/crates/ui-egui/src/panels/properties/transform_section.rs index ad887865dc..042d6165dd 100644 --- a/crates/ui-egui/src/panels/properties/transform_section.rs +++ b/crates/ui-egui/src/panels/properties/transform_section.rs @@ -105,11 +105,12 @@ pub(super) fn corner_rows(app: &mut VectorcraftApp, ui: &mut Ui) { Row::new().show(ui, |ui, _| panels::corners_link(app, ui)); return; } - // The corners differ in kind: no entry is the value. + // The corners differ in kind: no entry is the value. The select is one number cell wide, as + // the Corner Radius field under it is. let kind = picked.kind.map_or(Mixed::Mixed, Mixed::Same); let entries = panels::corner_entries(); let chosen = Field::new(tl!("Corner")) - .show(ui, |ui, _| Select::new(tl!("Corner"), Bind::given(kind), &entries).show(ui).events.committed().copied()) + .show(ui, |ui, _| Select::new(tl!("Corner"), Bind::given(kind), &entries).number_cell().show(ui).events.committed().copied()) .inner; if let Some(Some(kind)) = chosen { panels::set_picked_corners(app, &picked, json!({"kind": kind})); diff --git a/crates/ui-egui/src/panels/transform/shape.rs b/crates/ui-egui/src/panels/transform/shape.rs index f9cc3a64ab..8530a90390 100644 --- a/crates/ui-egui/src/panels/transform/shape.rs +++ b/crates/ui-egui/src/panels/transform/shape.rs @@ -229,12 +229,13 @@ fn sides_row(app: &mut VectorcraftApp, ui: &mut Ui, sides: u32) { } } -/// The polygon's Corner type select, blank while `kind` is `None` (the corners differ). +/// The polygon's Corner type select, blank while `kind` is `None` (the corners differ), one number cell wide as the +/// number fields of its column are. fn corner_kind_row(app: &mut VectorcraftApp, ui: &mut Ui, kind: Option) { let entries = corner_entries(); let mut edit = None; Field::new(tl!("Corner")).show(ui, |ui, _| { - edit = Some(Select::new(tl!("Corner"), Bind::given(kind.map_or(Mixed::Mixed, Mixed::Same)), &entries).show(ui)); + edit = Some(Select::new(tl!("Corner"), Bind::given(kind.map_or(Mixed::Mixed, Mixed::Same)), &entries).number_cell().show(ui)); }); if let Some(edit) = edit { apply_edits(app, &edit, EditPath::Scope, |app, k, _| set_live_shape(app, json!({ "kind": k }))); diff --git a/crates/ui-egui/src/panels/transform/tests.rs b/crates/ui-egui/src/panels/transform/tests.rs index a5f37234e1..fa4b550289 100644 --- a/crates/ui-egui/src/panels/transform/tests.rs +++ b/crates/ui-egui/src/panels/transform/tests.rs @@ -246,6 +246,66 @@ fn unlinked_corner_labels_start_in_one_column() { } } +/// An app with a live rectangle selected whose Corner Radius is linked. +fn linked_rectangle_app() -> VectorcraftApp { + let mut app = new_app(); + app.run("shape.rectangle", json!({"x": 50, "y": 50, "width": 120, "height": 80, "radius": 10})).unwrap(); + set_pref(&mut app, "singleCornerRadius", true); + app +} + +/// An app with the Direct Selection tool chosen and corner 2 of a star selected. +fn star_corner_app() -> VectorcraftApp { + let mut app = new_app(); + let star = app.run("shape.star", json!({"cx": 200, "cy": 150, "radius1": 80, "radius2": 40})).unwrap()["id"].as_u64().unwrap(); + app.select_tool("directSelection"); + app.run("select.anchors", json!({"id": star, "anchors": [[0, 2]], "mode": "set"})).unwrap(); + app +} + +/// A Corner select in a column of number fields is one number cell wide, as the Corner Radius field of its column +/// is: a live rectangle's linked Corner and a live polygon's Corner, in the Transform panel and the Properties panel's +/// Transform section, and the Corner of a path's Direct-Selected corners in the Properties panel. Each still opens, +/// and Enter sets the kind highlighted in its list on the corner it reads. +#[test] +fn corner_selects_are_as_wide_as_the_corner_radius_field() { + use craft::ui::contract::Role; + use egui::{Key, Modifiers}; + use vectorcraft_doc::LiveCorners; + use vectorcraft_geom::shapes::CornerKind; + type Draw = fn(&mut VectorcraftApp, &mut Ui); + /// A case's name, the app it starts from, the panel it draws and the corner whose kind it reads. + type Case = (&'static str, fn() -> VectorcraftApp, Draw, usize); + let transform = show as Draw; + let properties = crate::panels::properties::transform_section as Draw; + let cases: [Case; 5] = [ + ("Transform panel, linked rectangle", linked_rectangle_app, transform, 0), + ("Properties panel, linked rectangle", linked_rectangle_app, properties, 0), + ("Transform panel, polygon", || polygon_app(6), transform, 0), + ("Properties panel, polygon", || polygon_app(6), properties, 0), + ("Properties panel, Direct-Selected corner", star_corner_app, crate::panels::properties::show, 2), + ]; + for (case, app, draw, corner) in cases { + let mut p = Panel::new(app(), draw); + let select = p.rect_role("Corner", Role::COMBO_BOX); + let field = p.rect_role("Corner Radius", Role::SPIN_BUTTON); + assert!( + (select.width() - field.width()).abs() < 0.5, + "{case}: the Corner select is {} wide, the Corner Radius field {}", + select.width(), + field.width() + ); + let kind = |p: &Panel| LiveCorners::of(&first_selected(&p.app()).unwrap()).unwrap().kind(corner); + assert_eq!(kind(&p), CornerKind::ALL[0], "{case}"); + let undo = undo_depth(&p.app()); + p.click_role("Corner", Role::COMBO_BOX); + p.key(Key::ArrowDown, Modifiers::NONE); + p.key(Key::Enter, Modifiers::NONE); + assert_eq!(kind(&p), CornerKind::ALL[1], "{case}: Enter sets the highlighted kind"); + assert_eq!(undo_depth(&p.app()), undo + 1, "{case}: the kind is one undo step"); + } +} + /// A corner kind set with no live rectangle selected leaves the selected polygon, the document and /// its undo history as they are. #[test]