diff --git a/crates/ui-egui/src/panels/transform/shape.rs b/crates/ui-egui/src/panels/transform/shape.rs index 447a161be9..f9cc3a64ab 100644 --- a/crates/ui-egui/src/panels/transform/shape.rs +++ b/crates/ui-egui/src/panels/transform/shape.rs @@ -1,6 +1,8 @@ //! The Transform panel's live-shape rows: the Rectangle, Polygon, Ellipse and Line Properties, also shown by the //! Properties panel and the Contextual Task Bar. +use std::ops::RangeInclusive; + use craft::behavior::Mixed; use craft::ui::buttons::Button; use craft::ui::contract::{Bind, Bracket, Props as _, Show as _, ShowContainer as _}; @@ -8,6 +10,7 @@ use craft::ui::form::Field; use craft::ui::layout_components::{Row, Stack}; use craft::ui::pickers::Select; use craft::ui::text::{NumberField, link_toggle}; +use craft::ui::value_drag::Slider; use egui::Ui; use serde_json::{Value, json}; use vectorcraft_doc::{LiveShape, Node, NodeKind}; @@ -25,10 +28,11 @@ enum Quantity { Degrees, /// A length in the document's general unit. Length, - /// A polygon's side count: a whole number from 3 to 1000. - Sides, } +/// The side counts Polygon Properties' Sides slider spans; the field beside it takes 3 to 1000. +const SIDES_SLIDER: RangeInclusive = 3.0..=20.0; + /// A live rectangle's, polygon's, ellipse's or line's properties (Transform and Properties panels, and for the /// first three the Contextual Task Bar). `headed` adds the Rectangle and Polygon Properties headings; an ellipse's /// and a line's heading always show. Returns false, drawing nothing, for other live shapes, and for a line unless @@ -75,7 +79,6 @@ fn number_row(app: &mut VectorcraftApp, ui: &mut Ui, label: &'static str, value: let field = match quantity { Quantity::Length => NumberField::length(label, bind, general_lengths(app)), Quantity::Degrees => NumberField::new(label, bind).unit("°").commit_decimals(1), - Quantity::Sides => NumberField::new(label, bind).range(3.0..=1000.0).fixed_decimals(0), }; edit = Some(field.show(ui).edit); }); @@ -172,13 +175,13 @@ fn pie_rows(app: &mut VectorcraftApp, ui: &mut Ui, pie: (f64, f64)) { } } -/// A live polygon's Polygon Properties: its side count, angle (counterclockwise), corner type and radius, radius -/// (centre to vertex) and side length, and Make Sides Equal, which an uneven scale enables. +/// A live polygon's Polygon Properties: its side count (a field and a slider), angle (counterclockwise), corner +/// type and radius, radius (center to vertex) and side length, and Make Sides Equal, which an uneven scale enables. fn polygon_rows(app: &mut VectorcraftApp, ui: &mut Ui, n: &Node, live: &LiveShape) { let LiveShape::Polygon { sides, .. } = live else { return }; let radius = live.polygon_radius(); let side = radius.map(|r| 2.0 * r * (std::f64::consts::PI / f64::from((*sides).max(3))).sin()); - number_row(app, ui, tl!("Sides"), Some(f64::from(*sides)), Quantity::Sides, |s| json!({ "sides": s as u64 })); + sides_row(app, ui, *sides); angle_row(app, ui, live, "polygonAngle"); corner_kind_row(app, ui, corner_style(app, n).1); Field::new(tl!("Corner Radius")).show(ui, |ui, _| corner_radius_field(app, ui, n)); @@ -189,6 +192,43 @@ fn polygon_rows(app: &mut VectorcraftApp, ui: &mut Ui, n: &Node, live: &LiveShap } } +/// Polygon Properties' Sides row for a polygon of `sides` sides: a field that takes 3 to 1000, and after it a slider +/// over [`SIDES_SLIDER`]. A typed count is one undo step. A slider drag previews the count and its release records +/// one undo step; Escape during the drag puts the count back. A click on the rail or an arrow key sets the count in +/// one undo step. A count above 20 puts the thumb at the rail's right end, and screen readers read the real count. +fn sides_row(app: &mut VectorcraftApp, ui: &mut Ui, sides: u32) { + let label = tl!("Sides"); + let count = f64::from(sides); + let (mut typed, mut slid) = (None, None); + Field::new(label).show(ui, |ui, _| { + Row::new().show(ui, |ui, _| { + typed = Some(NumberField::new(label, Bind::given(Some(count))).range(3.0..=1000.0).fixed_decimals(0).id_salt("field").show(ui).edit); + let (lo, hi) = (*SIDES_SLIDER.start(), *SIDES_SLIDER.end()); + slid = Some( + Slider::new(Bind::given(count.clamp(lo, hi)), SIDES_SLIDER) + .step(1.0) + .short(true) + .value_text(sides.to_string()) + .label(label) + .id_salt("slider") + .show(ui), + ); + }); + }); + if let Some(edit) = typed { + apply_edits(app, &edit, EditPath::Scope, |app, v, _| { + if let Some(v) = v { + set_live_shape(app, json!({ "sides": *v as u64 })); + } + }); + } + if let Some(edit) = slid { + apply_edits(app, &edit, EditPath::Preview, |app, v, phase| { + crate::panels::live_run(app, "Live Shape Properties", "object.setLiveShape", json!({ "sides": v.round() as u64 }), phase); + }); + } +} + /// The polygon's Corner type select, blank while `kind` is `None` (the corners differ). fn corner_kind_row(app: &mut VectorcraftApp, ui: &mut Ui, kind: Option) { let entries = corner_entries(); diff --git a/crates/ui-egui/src/panels/transform/tests.rs b/crates/ui-egui/src/panels/transform/tests.rs index 6e7e50be24..86408d5b90 100644 --- a/crates/ui-egui/src/panels/transform/tests.rs +++ b/crates/ui-egui/src/panels/transform/tests.rs @@ -963,3 +963,93 @@ fn a_frame_after_a_shape_shows_the_transform_panel() { assert_eq!(crate::panel_docking::visible(&app, "transform"), on, "on: {on}"); } } + +/// The selected live polygon's side count. +fn polygon_sides(app: &VectorcraftApp) -> u32 { + match &first_selected(app).unwrap().kind { + NodeKind::Path { live: Some(l), .. } => match **l { + LiveShape::Polygon { sides, .. } => sides, + ref k => panic!("{k:?}"), + }, + k => panic!("{k:?}"), + } +} + +/// An app with a live polygon of `sides` sides selected. +fn polygon_app(sides: u32) -> VectorcraftApp { + let mut app = new_app(); + app.run("shape.polygon", json!({"cx": 150, "cy": 150, "radius": 50, "sides": 6})).unwrap(); + if sides != 6 { + app.run("object.setLiveShape", json!({ "sides": sides })).unwrap(); + } + app +} + +fn undo_depth(app: &VectorcraftApp) -> usize { + app.session.doc().unwrap().history.undo.len() +} + +/// Polygon Properties' Sides row has a slider after its field, in the Transform panel and the Properties panel's +/// Transform section; screen readers read the side count from it. +#[test] +fn polygon_sides_slider_is_shared_by_transform_and_properties() { + use craft::ui::contract::Role; + for draw in [show as fn(&mut VectorcraftApp, &mut Ui), crate::panels::properties::transform_section] { + let p = Panel::new(polygon_app(6), draw); + assert_eq!(p.value_role("Sides", Role::SLIDER).as_deref(), Some("6")); + assert!(p.rect_role("Sides", Role::SLIDER).left() >= p.rect_role("Sides", Role::SPIN_BUTTON).right(), "the slider follows the field"); + } +} + +/// A count past the slider's 20 stays as it is while the panel is drawn, and the field and screen readers show it. +/// A click on the rail then sets a count from 3 to 20 in one undo step, and an arrow key steps it by one in one +/// undo step. +#[test] +fn polygon_sides_above_slider_range_remain_editable() { + use craft::ui::contract::Role; + let mut p = Panel::new(polygon_app(50), show); + let depth = undo_depth(&p.app()); + let revision = p.app().session.active().unwrap().revision; + p.frame(); + assert_eq!(polygon_sides(&p.app()), 50); + assert_eq!(p.app().session.active().unwrap().revision, revision, "drawing the slider leaves the document as it is"); + assert_eq!(p.value_role("Sides", Role::SLIDER).as_deref(), Some("50")); + assert_eq!(p.value_role("Sides", Role::SPIN_BUTTON).as_deref(), Some("50")); + p.click_role("Sides", Role::SLIDER); + let clicked = polygon_sides(&p.app()); + assert!((3..=20).contains(&clicked), "{clicked}"); + assert_eq!(undo_depth(&p.app()), depth + 1, "a click on the rail is one undo step"); + p.key(egui::Key::ArrowRight, egui::Modifiers::NONE); + assert_eq!(polygon_sides(&p.app()), clicked + 1); + assert_eq!(undo_depth(&p.app()), depth + 2, "a key step is one undo step"); + p.app().run("edit.undo", json!({})).unwrap(); + assert_eq!(polygon_sides(&p.app()), clicked); +} + +/// A drag on the Sides slider previews the side count and its release records one undo step, which Undo takes +/// back. Escape during a drag puts the polygon back, and its release then records nothing. +#[test] +fn polygon_sides_slider_drag_is_one_undo_step() { + use craft::ui::contract::Role; + let mut p = Panel::new(polygon_app(6), show); + let depth = undo_depth(&p.app()); + p.drag_hold_role("Sides", Role::SLIDER, egui::vec2(40.0, 0.0)); + assert!(p.app().session.in_interaction(), "the drag is in progress"); + let dragged = polygon_sides(&p.app()); + assert!(dragged > 6, "the drag previews the count: {dragged}"); + assert_eq!(undo_depth(&p.app()), depth); + p.release(); + assert!(!p.app().session.in_interaction(), "the release ends the drag"); + assert_eq!(polygon_sides(&p.app()), dragged); + assert_eq!(undo_depth(&p.app()), depth + 1, "the whole drag is one undo step"); + p.app().run("edit.undo", json!({})).unwrap(); + assert_eq!(polygon_sides(&p.app()), 6); + p.drag_hold_role("Sides", Role::SLIDER, egui::vec2(40.0, 0.0)); + assert!(polygon_sides(&p.app()) > 6); + p.key(egui::Key::Escape, egui::Modifiers::NONE); + assert!(!p.app().session.in_interaction(), "Escape ends the drag"); + assert_eq!(polygon_sides(&p.app()), 6, "Escape puts the count back"); + p.release(); + assert_eq!(polygon_sides(&p.app()), 6); + assert_eq!(undo_depth(&p.app()), depth, "a canceled drag records no undo step"); +} diff --git a/crates/ui-egui/src/tests/panel_harness.rs b/crates/ui-egui/src/tests/panel_harness.rs index c48710edc3..0b36cec615 100644 --- a/crates/ui-egui/src/tests/panel_harness.rs +++ b/crates/ui-egui/src/tests/panel_harness.rs @@ -322,6 +322,12 @@ impl Panel { self.fixture.tree().value_of(self.look(name).node).map(str::to_owned) } + /// The value text of the control of `role` named `name`, where nodes of other roles share the name (a slider + /// beside its number box). + pub(crate) fn value_role(&self, name: &str, role: craft::ui::contract::Role) -> Option { + self.fixture.tree().value_of(self.look_role(name, role).node).map(str::to_owned) + } + /// The description of the control named `name` (a list row's trailing texts). pub(crate) fn description(&self, name: &str) -> Option { self.fixture.tree().description_of(self.look(name).node).map(str::to_owned) diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 3f8279313c..036f5b1b53 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1524,6 +1524,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur View › Hide Edges hides the Live Corners widgets, the bounding box and the type widget, and the selection tools then do not answer a press on them or change the cursor over them. - **Rectangle Properties corner type:** a live rectangle's Rectangle Properties (Transform panel, the Properties panel's Transform section and the Contextual Task Bar's Shape Properties) have a Corner menu with Round, Inverted Round and Chamfer. With Corner Radius linked, one menu sets the kind of every corner of each selected rectangle, also corners with no radius, and shows blank when the shown rectangle's kinds differ; unlinked, each corner's row has its own menu beside its radius field, or under it in a panel too narrow for both; the unlinked radius fields and menus leave other selected paths and polygons as they are. A pick is one undo step, and picking the kind the corners already have adds none (`object.setLiveShape {kind, rectanglesOnly, corners}`); an action that records them acts on the rectangles selected when it plays. The help page says a rectangle's corner type can be set for each corner or for all of them at once ([the help page](https://helpx.adobe.com/illustrator/desktop/draw-shapes-and-paths/modify-live-shapes/live-shape-properties.html)); tying the number of menus to the Corner Radius link, the blank value and the undo steps are VectorCraft's own rules (`a_rectangle_shows_linked_and_unlinked_corner_types`, `the_shape_properties_popup_changes_a_rectangle_corner_type`, `the_linked_corner_menu_sets_every_selected_rectangle`, `the_unlinked_corner_menus_fit_a_narrow_panel`, `an_unlinked_corner_radius_leaves_other_selected_shapes`, `a_rectangle_corner_kind_without_a_selected_rectangle_changes_nothing`, `rectangle_kind_menu_targets_all_or_one_corner_and_skips_noop_undo`, `rectangles_only_sets_the_selected_rectangles_when_an_action_plays`, `a_radius_reaches_a_rectangle_that_already_draws_it`). - **Polygon side widget:** a selected live polygon shows a small diamond beside the middle of the right side of its bounding box, with the Selection tool and with the Rectangle, Rounded Rectangle, Ellipse, Polygon and Star tools, while the bounding box and the edges are shown. Dragging the widget sets the polygon's side count, from 3 to 11, as [the help page](https://helpx.adobe.com/illustrator/desktop/draw-shapes-and-paths/modify-live-shapes/add-or-remove-sides-from-polygons.html) describes; typed counts in the Transform panel and `object.setLiveShape` still go from 3 to 1000. A drag down adds one side and a drag up removes one for every 12 screen pixels along the box's own vertical axis, and the pointer shows the count while measurement labels are on. A polygon of more than 11 sides keeps its count until the drag goes up, which gives it 11. The drag sends `object.setLiveShape {sides}`, so the polygon keeps its center, radius and rotation; the release adds one undo step when the count changed and none when it ends where it began, and Escape puts the count back. The widget's look and place, the drag direction, the step and the rule for more than 11 sides are VectorCraft's own (`crates/tools/src/sidewidget.rs`). + - **Polygon side slider:** Polygon Properties (Transform panel, the Properties panel's Transform section and the Contextual Task Bar's Shape Properties) have a Sides slider after the Sides field, over 3 to 20 sides. [The help page](https://helpx.adobe.com/illustrator/using/live-shapes.html) gives the slider that range and leaves larger counts, up to 1000, to the typed field, which still takes 3 to 1000. A drag previews the count through `object.setLiveShape {sides}` and its release adds one undo step; Escape during the drag puts the count back and adds no undo step. A click on the rail or an arrow key on it sets the count in one undo step. A count above 20 shows the handle at the rail's right end, and screen readers and the field show the real count, until the rail moves. The slider's place, the rule for counts above 20 and the undo steps are VectorCraft's own (`polygon_sides_slider_is_shared_by_transform_and_properties`, `polygon_sides_above_slider_range_remain_editable`, `polygon_sides_slider_drag_is_one_undo_step`). - **Hide/Show Shape Widgets:** with the Rectangle, Rounded Rectangle, Ellipse, Polygon or Star tool, the Control bar shows a Hide Shape Widgets button, which reads Show Shape Widgets while the widgets are hidden (`view.shapeWidgets {on?}`). [The help page](https://helpx.adobe.com/illustrator/using/live-shapes.html) describes this Control panel button, offered with any live shape drawing tool, as switching the on-canvas widgets of selected shapes off and on. While they are hidden, a selected live rectangle's or polygon's corner widgets, a live ellipse's pie widgets and a live polygon's side widget are not drawn, and the Selection tool and those shape tools do not answer a press, a double-click or the cursor on their place (a shape tool draws from there). The bounding box and its handles, the center point and Direct Selection's corner widgets (View › Hide Corner Widget) stay as they are. The setting is on by default, kept with the interface state across sessions and tool switches, and adds no undo step. Its scope beyond the shape tools, its default and what it leaves shown are VectorCraft's own rules (tests `hidden_shape_widgets_leave_the_bounding_box`, `the_shape_tools_control_bar_hides_and_shows_the_shape_widgets`, `shape_widgets_command_toggles_and_takes_on`, `hidden_shape_widgets_do_not_answer_a_shape_tool` and `hidden_shape_widgets_leave_direct_selections_corners`). - **Blend spine Anchor Point tool (#2544):** on a selected blend, dragging a spine corner makes symmetric Smooth handles; the tool displays and picks existing spine handles when switched to, drags one independently or retracts it on click, and clicking a point with handles retracts both. The spine is edited live without moving its key objects. Windows native canvas checks and screenshots reviewed: symmetric and independent handles, corner/retraction, Shift constraints and perpendicular reshaping, tool switching, key preservation, Undo/Redo, save/reopen, hidden handles and overlapping Path/Blend priority (PR #2643). Behaviour reference: [public path-editing documentation](https://helpx.adobe.com/illustrator/using/adjust-path-segments.html). - **Anchor Point tool, Alt-drag on a handle:** with the Anchor Point tool chosen, dragging a direction handle with Alt (Option) held links it with the opposite handle and makes the anchor smooth, on a path and on a selected blend's spine, as [the help page](https://helpx.adobe.com/illustrator/desktop/draw-shapes-and-paths/modify-paths/create-smooth-paths-with-the-smooth-tool.html) describes; a drag without Alt still moves one handle on its own (`path.setHandle` and `object.blend.spine.moveAnchor` with `link`). VectorCraft's own rules: the opposite handle keeps its length; a retracted one is pulled out to the dragged handle's length where a segment leaves the anchor on its side and stays retracted at an open end; Shift with Alt keeps the 45° steps; an Alt-click still retracts the handle; the Pen with Alt keeps moving a handle on its own. Tests: `anchor_point_alt_drag_links_*` in `crates/tools/src/draw2/anchor/tests.rs`, `a_linked_handle_makes_the_anchor_smooth` in `crates/engine/src/tests/anchor_edit_work.rs`, `a_linked_spine_handle_makes_the_point_smooth` in `crates/engine/src/tests/blendspine.rs`.