From 64dfd6ca1474d48278c3ce44e2d7691a3a188e5e Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Mon, 16 Nov 2026 04:50:48 -0800 Subject: [PATCH] Repeat: dragging a Radial Repeat's splitter hides instances and the others keep their places With one radial repeat selected, the Selection tool shows a splitter on its circle, half a step past the last instance shown. Dragging it back around the circle hides the instances it passes, and dragging it forward shows them again; one instance stays shown at least. The instances left keep their places: the repeat keeps the count shown in instances and spaces them a full circle's step apart with endAngle, and the full circle's count is read back from that step. Each drag previews and commits object.repeat.options as one undo step, Escape cancels it, and a drag that ends where it began leaves no undo step. There is no splitter when the step does not divide a full turn, for one instance to a turn or with a radius of 0. The radius handle of a single instance sits opposite it. --- crates/tools/src/repeat_radial.rs | 286 +++++++++++++++++++-- crates/ui-egui/src/canvas/tests.rs | 87 +++++++ crates/ui-egui/src/canvas/tool_overlays.rs | 14 +- docs/gaps.md | 2 +- docs/target-app-parity.md | 1 + docs/ui-parity.md | 2 +- 6 files changed, 367 insertions(+), 25 deletions(-) diff --git a/crates/tools/src/repeat_radial.rs b/crates/tools/src/repeat_radial.rs index 05eafc8d1b..42a9f4395f 100644 --- a/crates/tools/src/repeat_radial.rs +++ b/crates/tools/src/repeat_radial.rs @@ -1,8 +1,14 @@ -//! Radial Repeat's on-canvas handles: a handle below the repeat adds or removes instances, and a -//! handle on the circle the instances sit on sets its radius, as the public "Create radial -//! repeats" page describes. Drawing and hit testing share the document-space geometry of +//! Radial Repeat's on-canvas handles: a handle below the repeat adds or removes instances, a +//! handle on the circle the instances sit on sets its radius, and a splitter on the circle hides +//! instances at the end of the ring while the others keep their places, as the public "Create +//! radial repeats" page describes. Drawing and hit testing share the document-space geometry of //! [`RadialHandles::of`]; a drag previews the existing Repeat Options command and commits as one //! undo step. +//! +//! A split ring is kept in the repeat's existing options: `instances` counts the instances shown, +//! and `endAngle` places them a full ring's step apart from `startAngle` (one step past it for a +//! single instance). The full ring's slot count is read back from that step, so dragging the +//! splitter forward shows the hidden instances again. use serde_json::{Value, json}; use vectorcraft_doc::{Document, NodeId, NodeKind, OrientedBox, RepeatKind, Selection}; use vectorcraft_geom::{Affine, Point, Rect, Vec2}; @@ -10,7 +16,7 @@ use vectorcraft_geom::{Affine, Point, Rect, Vec2}; use crate::bbox::Handle; use crate::{Action, Cursor, Mods, ToolContext}; -/// The radius of the instances and radius handles (screen points). +/// The radius of the instances, radius and splitter handles (screen points). pub const HANDLE_RADIUS: f32 = 5.0; /// How far (screen points) the instances handle sits below the bounding box, clear of its own @@ -34,6 +40,61 @@ pub enum RadialPart { /// On the circle, between the first two instances: drag outward for a larger radius, inward /// for a smaller one. Radius, + /// On the circle, half a step past the last instance shown: drag it back around the circle to + /// hide the instances it passes, forward to show them again. + Splitter, +} + +/// The full ring a radial repeat's instances sit on. +#[derive(Clone, Copy, Debug, PartialEq)] +struct Ring { + /// The instances a full turn holds at the repeat's step. + slots: u32, + /// Degrees from one instance to the next (negative when the instances run the other way). + step: f64, +} + +impl Ring { + /// The ring of `instances` laid out from `start` to `end` degrees, when their step fits a + /// whole number of times (2 to 1,000, and no fewer than the instances) in a full turn. + fn of(instances: u32, start: f64, end: f64) -> Option { + let step = instance_step(instances, end - start); + let slots = 360.0 / step.abs(); + let whole = slots.round(); + ((slots - whole).abs() < 1e-6 && (2.0..=MAX_INSTANCES).contains(&whole) && whole >= f64::from(instances)) + .then(|| Self { slots: whole as u32, step: (360.0 / whole).copysign(step) }) + } + + /// The Repeat Options that show the first `shown` instances of the ring (1 to all of them), + /// laid out from `start` degrees. + fn options(&self, shown: u32, start: f64) -> Value { + let shown = shown.clamp(1, self.slots.max(1)); + let sweep = if shown == self.slots { 360.0_f64.copysign(self.step) } else { self.step * f64::from(shown.saturating_sub(1).max(1)) }; + json!({ "instances": shown, "endAngle": start + sweep }) + } + + /// The instances shown with the splitter `turn` degrees around the ring from the first + /// instance: those it has passed, one at least and the full ring at most. + fn shown(&self, turn: f64) -> u32 { + let k = (turn / self.step.abs()).floor() + 1.0; + if k.is_nan() { 1 } else { k.clamp(1.0, f64::from(self.slots)) as u32 } + } +} + +/// Degrees between neighboring instances, as `repeat_transforms` spaces `instances` over `sweep`. +fn instance_step(instances: u32, sweep: f64) -> f64 { + let full = (sweep.abs() - 360.0).abs() < 1e-9; + if full || instances <= 1 { sweep / f64::from(instances.max(1)) } else { sweep / f64::from(instances - 1) } +} + +/// `v` turned by `deg` degrees as `repeat_transforms` turns the instances. +fn turned(v: Vec2, deg: f64) -> Vec2 { + (Affine::rotate(deg.to_radians()) * v.to_point()).to_vec2() +} + +/// The direction of `v` in counter-clockwise screen degrees. +fn screen_angle(v: Vec2) -> f64 { + (-v.y).atan2(v.x).to_degrees() } /// The controls of a selected radial repeat, in document space. @@ -48,8 +109,13 @@ pub struct RadialHandles { out: Vec2, /// Document points of drag for each instance. step: f64, + start_angle: f64, + ring: Option, pub instances_at: Point, pub radius_at: Point, + /// Where the splitter is: none when the instances' step does not divide a full turn, for a + /// single instance to a turn, or with a radius of 0. + pub splitter_at: Option, } impl RadialHandles { @@ -78,12 +144,14 @@ impl RadialHandles { if d.hypot() < 1e-9 { d = Vec2::new(0.0, -1.0); } - let sweep = end_angle - start_angle; - let full = (sweep.abs() - 360.0).abs() < 1e-9; - let step = if full || instances == 1 { sweep / f64::from(instances) } else { sweep / f64::from(instances - 1) }; - // Halfway between the first two instances (opposite the only one of a full turn). - let out = (Affine::rotate((start_angle + step / 2.0).to_radians()) * d.normalize().to_point()).to_vec2(); + let first = turned(d.normalize(), start_angle); + let step = instance_step(instances, end_angle - start_angle); + // Halfway between the first two instances; opposite a single one. + let out = turned(first, if instances == 1 { 180.0 } else { step / 2.0 }); let radius = radius.max(0.0); + let ring = Ring::of(instances, start_angle, end_angle); + // Half a step past the last instance shown. + let splitter_at = ring.filter(|_| radius > 0.0).map(|r| center + turned(first, r.step * (f64::from(instances) - 0.5)) * radius); let frame = match frame { Some(f) => aabb(f.corners())?, None => n.geometric_bounds_with(&doc.symbol_boxes())?, @@ -95,15 +163,20 @@ impl RadialHandles { radius, out, step: INSTANCE_STEP / zoom, + start_angle, + ring, instances_at: Point::new(frame.center().x, frame.y1 + HANDLE_GAP / zoom), radius_at: center + out * radius, + splitter_at: splitter_at.filter(|p| finite(*p)), }; (finite(h.instances_at) && finite(h.radius_at) && h.step.is_finite() && h.step > 0.0).then_some(h) } - /// Both controls with where they are. - pub fn parts(&self) -> [(RadialPart, Point); 2] { - [(RadialPart::Instances, self.instances_at), (RadialPart::Radius, self.radius_at)] + /// The controls with where they are. + pub fn parts(&self) -> Vec<(RadialPart, Point)> { + let mut parts = vec![(RadialPart::Instances, self.instances_at), (RadialPart::Radius, self.radius_at)]; + parts.extend(self.splitter_at.map(|at| (RadialPart::Splitter, at))); + parts } /// The control under `p` (the nearer within reach) and the repeat's controls, unless a @@ -120,7 +193,8 @@ impl RadialHandles { } /// The Repeat Options that dragging `part` by `d` (document points) from the press gives; - /// none when the drag is too far to measure. + /// none when the drag is too far to measure. The splitter's options are those it shows at the + /// press. fn options(&self, part: RadialPart, d: Vec2) -> Option { match part { RadialPart::Instances => { @@ -133,12 +207,31 @@ impl RadialHandles { let r = ((self.radius + d.dot(self.out)).max(0.0) * 100.0).round() / 100.0; r.is_finite().then(|| json!({ "radius": r })) } + RadialPart::Splitter => self.ring.map(|r| r.options(self.instances, self.start_angle)), } } + /// Degrees around the ring from the first instance to the splitter, in the direction the + /// instances run. + fn splitter_turn(&self) -> f64 { + self.ring.map_or(0.0, |r| (f64::from(self.instances) - 0.5) * r.step.abs()) + } + + /// The direction of `p` from the center in degrees, as the instances are turned; none at the + /// center. + fn bearing(&self, p: Point) -> Option { + let v = p - self.center; + (finite(p) && v.hypot() > 1e-9).then(|| v.y.atan2(v.x).to_degrees()) + } + /// The direction (counter-clockwise degrees) in which the radius handle moves the circle out. fn out_angle(&self) -> f64 { - (-self.out.y).atan2(self.out.x).to_degrees() + screen_angle(self.out) + } + + /// The direction (counter-clockwise degrees) along the circle at the splitter. + fn splitter_angle(&self) -> f64 { + self.splitter_at.map_or(0.0, |at| screen_angle(at - self.center) + 90.0) } } @@ -153,11 +246,12 @@ fn finite(p: Point) -> bool { } /// The resize cursor of `part`, turned with the view: up and down for the instances handle, along -/// the line from the center for the radius handle. +/// the line from the center for the radius handle, and along the circle for the splitter. fn part_cursor(cx: &ToolContext, h: &RadialHandles, part: RadialPart) -> Cursor { match part { RadialPart::Instances => crate::select::handle_cursor(Handle::Bottom, -cx.view_angle()), RadialPart::Radius => crate::select::handle_cursor(Handle::Right, h.out_angle() - cx.view_angle()), + RadialPart::Splitter => crate::select::handle_cursor(Handle::Right, h.splitter_angle() - cx.view_angle()), } } @@ -176,6 +270,10 @@ pub struct RadialDrag { /// The options the press found, and the last ones previewed. from: Value, last: Option, + /// For the splitter: its degrees around the ring from the first instance, and the pointer's + /// last direction from the center. + turn: f64, + bearing: Option, } impl RadialDrag { @@ -185,7 +283,7 @@ impl RadialDrag { } let (handles, part) = RadialHandles::hit(cx, p)?; let from = handles.options(part, Vec2::ZERO)?; - Some(Self { handles, part, start: p, from, last: None }) + Some(Self { handles, part, start: p, from, last: None, turn: handles.splitter_turn(), bearing: handles.bearing(p) }) } /// Whether the drag has changed the repeat (and so previews it). @@ -197,13 +295,30 @@ impl RadialDrag { part_cursor(cx, &self.handles, self.part) } + /// The options of the splitter with the pointer at `p`: it follows the pointer around the + /// circle, each move counted by the shorter way round. + fn split(&mut self, p: Point) -> Option { + let ring = self.handles.ring?; + if let Some(b) = self.handles.bearing(p) { + if let Some(last) = self.bearing { + self.turn += ((b - last + 180.0).rem_euclid(360.0) - 180.0) * ring.step.signum(); + } + self.bearing = Some(b); + } + Some(ring.options(ring.shown(self.turn), self.handles.start_angle)) + } + /// Preview the options the pointer at `p` gives, when they change; the first change opens /// the undo step. pub fn drag(&mut self, p: Point) -> Vec { if !finite(p) { return vec![]; } - let Some(v) = self.handles.options(self.part, p - self.start) else { return vec![] }; + let v = match self.part { + RadialPart::Splitter => self.split(p), + part => self.handles.options(part, p - self.start), + }; + let Some(v) = v else { return vec![] }; if self.last.as_ref().unwrap_or(&self.from) == &v { return vec![]; } @@ -266,13 +381,44 @@ mod tests { }) } + /// The point on the 100 pt circle about (150, 250) at `deg` degrees clockwise from straight up. + fn on_circle(deg: f64) -> Point { + let a = deg.to_radians(); + Point::new(150.0 + 100.0 * a.sin(), 250.0 - 100.0 * a.cos()) + } + + /// Apply the `instances` and `endAngle` of a preview to the repeat. + fn apply(doc: &mut Document, selection: &Selection, v: &Value) { + let n = v["instances"].as_u64().unwrap() as u32; + let end = v["endAngle"].as_f64().unwrap(); + set(doc, selection, |i, _, _, e| (*i, *e) = (n, end)); + } + + /// Where the repeat's instances are, in paint order. + fn transforms(doc: &Document, selection: &Selection) -> Vec { + let NodeKind::Repeat(spec) = &doc.node(selection.objects[0]).unwrap().kind else { panic!("a repeat") }; + spec.transforms(Some(doc)) + } + + /// Drag the splitter from `from` to `to` degrees clockwise from straight up, 5° a move, and + /// return the last preview. + fn sweep(d: &mut RadialDrag, from: f64, to: f64) -> Option { + let mut last = None; + let moves = ((to - from).abs() / 5.0).ceil() as i32; + for k in 1..=moves { + if let Some(v) = preview(&d.drag(on_circle(from + (to - from) * f64::from(k) / f64::from(moves)))) { + last = Some(v.clone()); + } + } + last + } + #[test] fn the_handles_sit_below_the_repeat_and_on_its_circle_at_every_zoom() { let (doc, selection) = radial(); // Halfway between the first instance (straight up from the center) and the second, 45° // clockwise from it. - let half = 22.5_f64.to_radians(); - let on_circle = Point::new(150.0 + 100.0 * half.sin(), 250.0 - 100.0 * half.cos()); + let on_circle = on_circle(22.5); for zoom in [0.02, 1.0, 4.0] { let h = RadialHandles::of(&doc, &selection, None, zoom).unwrap(); assert!(near(h.instances_at, Point::new(150.0, 400.0 + HANDLE_GAP / zoom)), "{zoom}: {:?}", h.instances_at); @@ -433,4 +579,106 @@ mod tests { // The radius handle points 22.5° clockwise from straight up: the up-and-down cursor. assert_eq!(cursor(&c, h.radius_at), Some(Cursor::ResizeV)); } + + #[test] + fn the_splitter_sits_half_a_step_past_the_last_instance_shown() { + let (mut doc, selection) = radial(); + // A full ring of eight: between the last instance (315°) and the first. + for zoom in [0.02, 1.0, 4.0] { + let h = RadialHandles::of(&doc, &selection, None, zoom).unwrap(); + assert!(near(h.splitter_at.unwrap(), on_circle(337.5)), "{zoom}: {:?}", h.splitter_at); + assert!(h.parts().contains(&(RadialPart::Splitter, h.splitter_at.unwrap()))); + } + // Five of the eight shown: past the fifth (180°). + set(&mut doc, &selection, |n, _, _, e| (*n, *e) = (5, 180.0)); + let h = RadialHandles::of(&doc, &selection, None, 1.0).unwrap(); + assert!(near(h.splitter_at.unwrap(), on_circle(202.5)), "{:?}", h.splitter_at); + // The instances running the other way from 90°: three of six, the splitter at -60 - 30. + set(&mut doc, &selection, |n, _, a, e| (*n, *a, *e) = (3, 90.0, -30.0)); + let h = RadialHandles::of(&doc, &selection, None, 1.0).unwrap(); + assert!(near(h.splitter_at.unwrap(), on_circle(-60.0)), "{:?}", h.splitter_at); + // One of the eight shown: half a step past it, and the radius handle opposite it. + set(&mut doc, &selection, |n, _, a, e| (*n, *a, *e) = (1, 0.0, 45.0)); + let h = RadialHandles::of(&doc, &selection, None, 1.0).unwrap(); + assert!(near(h.splitter_at.unwrap(), on_circle(22.5)), "{:?}", h.splitter_at); + assert!(near(h.radius_at, on_circle(180.0)), "{:?}", h.radius_at); + } + + #[test] + fn no_splitter_where_the_ring_cannot_be_split() { + let (mut doc, selection) = radial(); + // A single instance to a full turn, no turn at all, a step that does not divide a full + // turn, and a radius of 0. + for (n, end, r) in [(1, 360.0, 100.0), (2, 0.0, 100.0), (3, 100.0, 100.0), (8, 360.0, 0.0), (8, f64::MAX, 100.0)] { + set(&mut doc, &selection, |i, rad, _, e| (*i, *rad, *e) = (n, r, end)); + let h = RadialHandles::of(&doc, &selection, None, 1.0).unwrap(); + assert_eq!(h.splitter_at, None, "{n} over {end}° at {r}"); + assert!(!h.parts().iter().any(|(p, _)| *p == RadialPart::Splitter)); + } + // Two instances to a turn can be split. + set(&mut doc, &selection, |i, rad, _, e| (*i, *rad, *e) = (2, 100.0, 360.0)); + assert!(RadialHandles::of(&doc, &selection, None, 1.0).unwrap().splitter_at.is_some()); + } + + #[test] + fn dragging_the_splitter_hides_instances_and_the_others_keep_their_places() { + let (mut doc, selection) = radial(); + let full = transforms(&doc, &selection); + assert_eq!(full.len(), 8); + let paint = paint(); + let (v, mut d) = { + let c = cx(&doc, &selection, &paint); + let h = RadialHandles::of(&doc, &selection, crate::select::selection_box(&c), 1.0).unwrap(); + let mut d = RadialDrag::hit(&c, h.splitter_at.unwrap(), Mods::default()).unwrap(); + assert!(cursor(&c, h.splitter_at.unwrap()).is_some()); + // Back to 320°, short of the last instance: nothing changes. + assert_eq!(sweep(&mut d, 337.5, 320.0), None); + assert!(!d.adjusting()); + // Back past the last instance (315°): seven shown, the full ring's step apart. + let out = d.drag(on_circle(300.0)); + assert!(matches!(out.first(), Some(Action::Begin(l)) if l == "Repeat Options"), "{out:?}"); + let v = preview(&out).unwrap().clone(); + assert_eq!(v, json!({"instances": 7, "endAngle": 270.0})); + (v, d) + }; + apply(&mut doc, &selection, &v); + let seven = transforms(&doc, &selection); + assert_eq!(seven.len(), 7); + for (k, (a, b)) in seven.iter().zip(&full).enumerate() { + assert!(a.as_coeffs().iter().zip(b.as_coeffs()).all(|(x, y)| (x - y).abs() < 1e-9), "instance {k} kept its place"); + } + // Further back, past 0°: one shown at least. + assert_eq!(sweep(&mut d, 300.0, -200.0), Some(json!({"instances": 1, "endAngle": 45.0}))); + // Forward again, past the start of the ring: all eight, a full turn. + assert_eq!(sweep(&mut d, -200.0, 400.0), Some(json!({"instances": 8, "endAngle": 360.0}))); + assert!(matches!(d.finish().as_slice(), [Action::Cancel]), "back where it began: no undo step"); + + // From the seven shown, forward past 315°: the eighth shows again where it was. + let c = cx(&doc, &selection, &paint); + let h = RadialHandles::of(&doc, &selection, crate::select::selection_box(&c), 1.0).unwrap(); + assert!(near(h.splitter_at.unwrap(), on_circle(292.5))); + let mut d = RadialDrag::hit(&c, h.splitter_at.unwrap(), Mods::default()).unwrap(); + let v = sweep(&mut d, 292.5, 330.0).unwrap(); + assert_eq!(v, json!({"instances": 8, "endAngle": 360.0})); + assert!(matches!(d.finish().as_slice(), [Action::Commit])); + let mut d = RadialDrag::hit(&c, h.splitter_at.unwrap(), Mods::default()).unwrap(); + assert!(d.drag(h.center).is_empty(), "the center gives no direction"); + assert_eq!(sweep(&mut d, 292.5, 250.0), Some(json!({"instances": 6, "endAngle": 225.0}))); + assert!(matches!(d.cancel().as_slice(), [Action::Cancel])); + apply(&mut doc, &selection, &v); + assert_eq!(transforms(&doc, &selection), full); + } + + #[test] + fn the_instances_handle_spreads_a_split_ring_over_the_same_arc() { + let (mut doc, selection) = radial(); + // Seven of eight shown: the handle sets the count alone, as for any partial repeat. + set(&mut doc, &selection, |n, _, _, e| (*n, *e) = (7, 270.0)); + let paint = paint(); + let c = cx(&doc, &selection, &paint); + let h = RadialHandles::of(&doc, &selection, crate::select::selection_box(&c), 1.0).unwrap(); + let mut d = RadialDrag::hit(&c, h.instances_at, Mods::default()).unwrap(); + assert_eq!(preview(&d.drag(h.instances_at + Vec2::new(0.0, 32.0))), Some(&json!({"instances": 9}))); + assert!(matches!(d.finish().as_slice(), [Action::Commit])); + } } diff --git a/crates/ui-egui/src/canvas/tests.rs b/crates/ui-egui/src/canvas/tests.rs index 3c58442e5e..885ba3dcc6 100644 --- a/crates/ui-egui/src/canvas/tests.rs +++ b/crates/ui-egui/src/canvas/tests.rs @@ -4920,6 +4920,93 @@ fn radial_repeat_handles_set_instances_and_radius_in_one_undo_step_each() { assert_eq!(radial(&app).0, 6, "the instances step is the one before"); } +/// A selected radial repeat draws its splitter on its circle. In a zoomed view turned 30°, +/// dragging the splitter back around the circle past two instances hides them while the other +/// four stay where they were, as one undo step; Escape puts a drag back. +#[test] +fn radial_repeat_splitter_hides_instances_in_one_undo_step() { + use vectorcraft_geom::Affine; + use vectorcraft_tools::repeat_radial::{HANDLE_RADIUS, RadialHandles}; + let mut app = VectorcraftApp::new(Session::new(), Default::default()); + app.run("file.new", json!({"width": 400, "height": 300})).unwrap(); + app.run("shape.rectangle", json!({"x": 180, "y": 40, "width": 40, "height": 40})).unwrap(); + app.run("object.repeat.radial", json!({"instances": 6, "radius": 60})).unwrap(); + app.ui.task_bar = false; + app.ui.view.rulers = false; + let ctx = egui::Context::default(); + frame(&mut app, &ctx, vec![]); + app.view_mut().unwrap().zoom = 1.5; + app.view_mut().unwrap().rotation = 30.0; + frame(&mut app, &ctx, vec![]); + // Instances shown, end angle and where the instances are. + let radial = |app: &VectorcraftApp| { + let st = app.session.active().unwrap(); + let n = st.doc.node(st.selection.objects[0]).unwrap(); + let vectorcraft_doc::NodeKind::Repeat(spec) = &n.kind else { panic!("a repeat") }; + let vectorcraft_doc::RepeatKind::Radial { instances, end_angle, .. } = spec.kind else { panic!("a radial repeat") }; + (instances, end_angle, spec.transforms(Some(&st.doc))) + }; + let handles = |app: &mut VectorcraftApp| { + let frame = app.selection_box(); + let st = app.session.active().unwrap(); + RadialHandles::of(&st.doc, &st.selection, frame, app.view().unwrap().zoom).unwrap() + }; + // `h`'s splitter turned `deg` degrees about the center (positive: the way the instances run). + let around = + |h: &RadialHandles, deg: f64| h.center + (Affine::rotate(deg.to_radians()) * (h.splitter_at.unwrap() - h.center).to_point()).to_vec2(); + let before = radial(&app); + assert_eq!((before.0, before.1, before.2.len()), (6, 360.0, 6)); + let h = handles(&mut app); + let xf = Xf::new(app.canvas_rect.unwrap(), app.view().unwrap()); + let drawn = shapes(&mut app, &ctx); + let at = xf.to_screen(h.splitter_at.unwrap()); + assert!( + drawn.iter().any(|s| matches!(s, Shape::Circle(c) if c.center.distance(at) < 0.01 && c.radius == HANDLE_RADIUS)), + "the splitter is drawn" + ); + frame(&mut app, &ctx, vec![]); + let button = |pos, pressed| egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() }; + let drag = |app: &mut VectorcraftApp, from: Pos2, to: Pos2| { + frame(app, &ctx, vec![egui::Event::PointerMoved(from), button(from, true)]); + for k in 1..=4 { + frame(app, &ctx, vec![egui::Event::PointerMoved(from + (to - from) * k as f32 / 4.0)]); + } + }; + let release = |app: &mut VectorcraftApp, at: Pos2| frame(app, &ctx, vec![button(at, false)]); + // Back 120° (two instances 60° apart): four shown, the rest in place. + let to = xf.to_screen(around(&h, -120.0)); + drag(&mut app, xf.to_screen(h.splitter_at.unwrap()), to); + assert_eq!(radial(&app).0, 4, "the drag previews"); + release(&mut app, to); + let after = radial(&app); + assert_eq!((after.0, after.1, after.2.len()), (4, 180.0, 4)); + for (k, (a, b)) in after.2.iter().zip(&before.2).enumerate() { + assert!(a.as_coeffs().iter().zip(b.as_coeffs()).all(|(x, y)| (x - y).abs() < 1e-9), "instance {k} stays where it was"); + } + app.run("edit.undo", json!({})).unwrap(); + assert_eq!((radial(&app).0, radial(&app).1), (6, 360.0), "one undo step"); + app.run("edit.redo", json!({})).unwrap(); + assert_eq!((radial(&app).0, radial(&app).1), (4, 180.0)); + // Escape during a drag forward puts the split back and leaves no undo step. + frame(&mut app, &ctx, vec![]); + let h = handles(&mut app); + let to = xf.to_screen(around(&h, 120.0)); + drag(&mut app, xf.to_screen(h.splitter_at.unwrap()), to); + assert_eq!((radial(&app).0, radial(&app).1), (6, 360.0), "the drag previews"); + let escape = egui::Event::Key { key: egui::Key::Escape, physical_key: None, pressed: true, repeat: false, modifiers: Default::default() }; + let screen = egui::Rect::from_min_size(Pos2::ZERO, vec2(800.0, 600.0)); + let mut full = ctx.run_ui(egui::RawInput { screen_rect: Some(screen), events: vec![escape], ..Default::default() }, |ui| { + crate::shortcuts::handle(&mut app, ui.ctx()); + show(&mut app, ui) + }); + full.textures_delta.clear(); + assert_eq!((radial(&app).0, radial(&app).1), (4, 180.0)); + release(&mut app, to); + assert_eq!(radial(&app).0, 4, "the release after Escape changes nothing"); + app.run("edit.undo", json!({})).unwrap(); + assert_eq!((radial(&app).0, radial(&app).1), (6, 360.0), "the split was the step before"); +} + /// While a symbol with 9-slice guides is edited, the canvas draws its four guides dotted across /// its art, with ruler guides hidden too, and none once the mode ends. Dragging the left guide in /// a zoomed view moves that guide alone, as one undo step. diff --git a/crates/ui-egui/src/canvas/tool_overlays.rs b/crates/ui-egui/src/canvas/tool_overlays.rs index b05259f8f6..bc94f19e2b 100644 --- a/crates/ui-egui/src/canvas/tool_overlays.rs +++ b/crates/ui-egui/src/canvas/tool_overlays.rs @@ -535,10 +535,11 @@ pub(super) fn grid_repeat_overlay(app: &mut VectorcraftApp, p: &egui::Painter, x } } -/// A selected radial repeat's circle with its radius handle on it, and its instances handle below -/// it, at the places the Selection tool's hit testing finds them. +/// A selected radial repeat's circle with its radius handle and its splitter on it, and its +/// instances handle below it, at the places the Selection tool's hit testing finds them. The +/// splitter also has a short line across the circle. pub(super) fn radial_repeat_overlay(app: &mut VectorcraftApp, p: &egui::Painter, xf: &Xf) { - use vectorcraft_tools::repeat_radial::{HANDLE_RADIUS, RadialHandles}; + use vectorcraft_tools::repeat_radial::{HANDLE_RADIUS, RadialHandles, RadialPart}; if app.session.tool_id() != "selection" || !app.ui.view.bounding_box { return; } @@ -552,8 +553,13 @@ pub(super) fn radial_repeat_overlay(app: &mut VectorcraftApp, p: &egui::Painter, p.circle_stroke(c, r, Stroke::new(3.0, t.measure_bg)); p.circle_stroke(c, r, Stroke::new(1.0, t.selection)); } - for (_, at) in h.parts() { + for (part, at) in h.parts() { let c = xf.to_screen(at); + let across = (c - xf.to_screen(h.center)).normalized() * (HANDLE_RADIUS + 4.0); + if part == RadialPart::Splitter && c.is_finite() && across.is_finite() { + p.line_segment([c - across, c + across], Stroke::new(3.0, t.measure_bg)); + p.line_segment([c - across, c + across], Stroke::new(1.5, t.selection)); + } if c.is_finite() { p.circle_filled(c, HANDLE_RADIUS, t.measure_bg); p.circle_stroke(c, HANDLE_RADIUS, Stroke::new(2.0, t.selection)); diff --git a/docs/gaps.md b/docs/gaps.md index 088912552d..c7647a212d 100644 --- a/docs/gaps.md +++ b/docs/gaps.md @@ -139,7 +139,7 @@ macOS cursor delivery (#2292) is narrowed to a native host adapter using the exi - **Done:** the selection tools take a clipping path (a clip group's or a layer's clipping mask) on its outline, within the selection tolerance, before the art it clips, so Direct Selection reshapes a mask where the art covers its edge; Select Behind lists the same, and the eyedropper and the tools that act on what is drawn are unchanged. Broader G1 estimates unchanged. - **Done:** one selected clip group's Properties panel has Edit Clipping Path and Edit Contents at its top, which select its clipping path or its clipped art for the selection tools (public doc cited in target-app-parity.md). Broader G1 estimates unchanged. - **Done:** the Properties panel has the additional contextual controls of the public Properties panel overview: Blend Options in Quick Actions for one blend with the Blend tool, Merge Live Paint for a Live Paint group selected with more paths to merge (Live Paint Make and Merge refuse type, images and other objects that aren't paths, which used to vanish among the group's sources), the Width Profile list in Appearance with the Width tool or a variable-width stroke, an applied effect's Delete icon beside fx (with several effects it opens the Appearance panel), and Corner and Corner Radius for corners selected with Direct Selection (public doc cited in target-app-parity.md). Broader G1 estimates unchanged. -- **Done (#2691):** a selected Grid Repeat ([public page](https://helpx.adobe.com/illustrator/desktop/paint-and-fill/create-and-edit-patterns/set-grid-repeat-options.html)) shows a handle below the grid, one right of it and one past its bottom-right corner: dragging them adds or removes rows, columns or both (1 to 500). A slider between the first two columns and one between the first two rows set the horizontal and vertical spacing, staying halfway across the gap under the pointer. Each drag is one undo step through `object.repeat.options` and Escape cancels it; the controls hide with the edges or the bounding box, and bounding-box handles keep priority where they meet. A selected Radial Repeat ([public page](https://helpx.adobe.com/illustrator/desktop/paint-and-fill/create-and-edit-patterns/create-radial-repeats.html)) shows a handle below it, dragged down for more instances and up for fewer (16 px each, 1 to 1,000), and a handle on its circle between the first two instances, dragged outward or inward for a larger or smaller radius (0 or more); the same undo, Escape, visibility and priority rules apply. The radial splitter remains. Estimates unchanged. +- **Done (#2691):** a selected Grid Repeat ([public page](https://helpx.adobe.com/illustrator/desktop/paint-and-fill/create-and-edit-patterns/set-grid-repeat-options.html)) shows a handle below the grid, one right of it and one past its bottom-right corner: dragging them adds or removes rows, columns or both (1 to 500). A slider between the first two columns and one between the first two rows set the horizontal and vertical spacing, staying halfway across the gap under the pointer. Each drag is one undo step through `object.repeat.options` and Escape cancels it; the controls hide with the edges or the bounding box, and bounding-box handles keep priority where they meet. A selected Radial Repeat ([public page](https://helpx.adobe.com/illustrator/desktop/paint-and-fill/create-and-edit-patterns/create-radial-repeats.html)) shows a handle below it, dragged down for more instances and up for fewer (16 px each, 1 to 1,000), and a handle on its circle between the first two instances, dragged outward or inward for a larger or smaller radius (0 or more); the same undo, Escape, visibility and priority rules apply. Its splitter sits on the circle half a step past the last instance shown: dragging it back around the circle hides the instances it passes, the others keeping their places, and dragging it forward shows them again (one instance at least; VectorCraft's own rules). On a split circle, as on any partial one, the instances handle changes the count alone and spreads the instances over the same arc. Estimates unchanged. - **Done (#2651):** Object › Repeat › Options… for a Grid Repeat has a Preview checkbox ([public page](https://helpx.adobe.com/illustrator/desktop/paint-and-fill/create-and-edit-patterns/set-grid-repeat-options.html)): while it is on the repeat on the canvas follows the fields, Cancel puts the original back without a history step and OK keeps the previewed values as one undo step. Radial and Mirror Repeat Options have none, as their public pages list none. Estimate unchanged. - **Done (#2877):** a selected Mirror Repeat shows its axis: drag the line or the center handle to move it, an end handle to rotate it (Shift: 45°); each drag is one undo step and Escape cancels it. Bounding-box handles take priority over the axis line; the center and end handles keep their actions. Broader G1 estimates unchanged. diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 3222960ef2..1fd3920773 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -642,6 +642,7 @@ since 2026-10-01. - **Graph section in the Properties panel:** with one graph selected, or series of one graph picked with Group Selection, the Properties panel shows a Graph section. Its Graph Type… button opens the dialog of Object › Graph › Type… ([Format pie graphs](https://helpx.adobe.com/illustrator/desktop/automate-visualize-data/visualize-data/format-pie-graphs.html)). Its Graph Data… button opens the dialog of Object › Graph › Data…; this button is VectorCraft's own. Column… shows when every series it would change draws columns or bars, and Marker… when every one draws lines, scatter points or radar lines; this is VectorCraft's own rule. Regression tests in `crates/ui-egui/src/panels/properties/tests.rs`. Scores unchanged. - **Selected Grid Repeat handles (#2691):** `tools/src/repeat_grid.rs` tests place the handles outside the grid at zoom 0.5, 1 and 4, preview rows, columns and spacing, leave no undo step for a drag that ends where it began, and give bounding-box handles priority; a headless canvas regression drags the row handle two tiles down in a zoomed view (3 → 5 rows, the source unchanged, one Undo back) and the column-spacing slider. Scores and hours unchanged. - **Selected Radial Repeat handles:** `tools/src/repeat_radial.rs` tests place the instances handle below the repeat and the radius handle on its circle between the first two instances at zoom 0.02, 1 and 4 (opposite a single instance, at the center with a radius of 0), step the count by whole instances within 1 to 1,000, set the radius from the outward part of a drag and stop it at 0, hide the handles for a locked, hidden or invalid repeat, leave no undo step for a drag that ends where it began, and give bounding-box handles priority; a headless canvas regression in a zoomed view turned 30° drags the instances handle (6 → 8 instances, the source unchanged, one Undo back) and the radius handle (60 → 80 pt), and Escape puts a radius drag back. Scores and hours unchanged. +- **Radial Repeat splitter:** dragging the splitter on a selected radial repeat's circle back hides the instances it passes, and the others keep their places ([Create radial repeats](https://helpx.adobe.com/illustrator/desktop/paint-and-fill/create-and-edit-patterns/create-radial-repeats.html)). The repeat keeps the instances shown in `instances` and spaces them a full circle's step apart with `endAngle`, so dragging the splitter forward shows the hidden ones again; the splitter's place half a step past the last instance shown and its limit of one instance shown are VectorCraft's own rules, and on a split circle the instances handle changes the count alone, as on any partial one. `tools/src/repeat_radial.rs` tests place the splitter at zoom 0.02, 1 and 4 and on rings running either way, hide it where the step does not divide a full turn, for one instance to a turn and with a radius of 0, and check that the instances left match the first ones of the full ring; a headless canvas regression in a zoomed view turned 30° drags the splitter back past two of six instances as one undo step, and Escape puts a drag back. Scores and hours unchanged. - **Selected Mirror Repeat handles:** a headless canvas regression creates the default mirror repeat and drags its Top bounding-box handle where the axis crosses it; the repeat grows vertically while its width stays fixed. Existing mirror-axis checks cover center movement and end-handle hit priority. The focused UI mirror tests pass. Scores and hours unchanged. - **Transform effect options (#885):** Effect › Distort & Transform › Transform… has visible Transform Objects, Transform Patterns and Scale Strokes & Effects checkboxes (`distort.transform` params `objects`, `patterns`, `strokes`; files without them draw as before). With Transform Objects off the geometry stays and makes no copies; Scale Strokes & Effects scales stroke weights, dashes and the fills' and strokes' effect distances by the mean scale, and Transform Patterns moves pattern tiles, each copy `k` by the transformation `k` times. Such objects draw, export and expand through the same per-copy art, so the canvas and Expand Appearance agree (engine `tests_transformfx`, effects `tests_transformfx`, the dialog test). A Transform effect in a fill's or stroke's own effects applies the same options to that fill or stroke: its weight and dashes and its pattern follow the transformation, and with copies each copy is an object of its own; the canvas, export, Expand Appearance and Use Preview Bounds use the same art (effects `tests_transformfx`). The effects listed after it in that fill's or stroke's list keep their own distances and apply to the transformed art and to each copy, as an object's later effects do after the object's Transform effect: a Drop Shadow after it keeps its offset, an Offset Path after it offsets by its own distance, and an SVG filter after it keeps its scale and the origin of its user space. With Transform Objects off, the effects before it keep their distances too. Before, Scale Strokes & Effects scaled a fill's or stroke's later effects by the mean scale, so existing documents with such effects draw differently. Effects apply in the order they are listed ([Appearance attributes](https://helpx.adobe.com/illustrator/desktop/special-effects-styles/apply-graphic-styles/appearance-attributes-in-illustrator.html)); how the two options treat the effects after a fill's or stroke's own Transform effect is VectorCraft's own rule, following that order (effects `tests::rasterfollow::a_fills_own_transform_leaves_the_shadow_after_it`, `tests::rasterfollow::a_fills_own_transform_leaves_the_offset_after_it`, `tests::rasterfollow::a_fills_own_transform_leaves_the_svg_filter_after_it`, `tests::transformfx::a_fills_own_transform_with_scale_strokes_and_effects_leaves_its_later_effects`; engine `plugins::a_transform_after_a_painted_fill_effect_leaves_the_later_shadow_on_every_paint`). Public reference: [Scale objects](https://helpx.adobe.com/illustrator/desktop/manage-objects/reshape-transform-objects/scale-objects.html), [How to apply effects](https://helpx.adobe.com/illustrator/using/effects.html), [Distort and transform effects](https://helpx.adobe.com/illustrator/desktop/manage-objects/reshape-transform-objects/distort-and-transform-effects-in-illustrator.html). Scores and hours unchanged. - **Raster effects before a Transform effect:** effects apply in the order they are listed ([Appearance attributes](https://helpx.adobe.com/illustrator/desktop/special-effects-styles/apply-graphic-styles/appearance-attributes-in-illustrator.html)). A Drop Shadow, glow, blur, Feather or pixel filter listed before a Transform effect in the same list (an object's effects, or a fill's or stroke's own) now follows that Transform effect: its sizes scale by the mean scale, and a Drop Shadow's offset turns, reflects and scales with the art. VectorCraft applies this rule with Scale Strokes & Effects on or off. Before, such an effect was drawn at its own distances around the transformed art. The canvas, export, Expand Appearance, Object › Expand, Outline Stroke and the 3D effects use the same values (effects `tests::rasterfollow`; render `a_transform_after_a_drop_shadow_scales_the_shadow_with_the_art`; engine `objexpand::a_shadow_before_a_transform_expands_as_the_canvas_draws_it`, `outlinestroke::a_shadow_before_a_transform_outlines_as_the_canvas_draws_it`). Not yet: a Transform effect that makes copies or moves at random leaves the raster effects before it as they are. The light direction of Underpainting, Rough Pastels, Conté Crayon, Bas Relief, Plaster and Texturizer and the stroke direction of Sprayed Strokes and Graphic Pen now turn and reflect with such a Transform effect, each set to the nearest of its menu's choices (at a tie, the one clockwise of it; VectorCraft's own rule), and Color Halftone's four screen angles turn and reflect with the art ([Distort and transform effects](https://helpx.adobe.com/illustrator/desktop/manage-objects/reshape-transform-objects/distort-and-transform-effects-in-illustrator.html); effects `tests::rasterfollow::bas_relief_light_follows_rotation_and_reflection` and the tests after it). Not yet: filters whose strokes or patterns run along fixed page axes without a direction setting (Angled Strokes, Crosshatch, Mezzotint's lines, Halftone Pattern's lines, Grain's horizontal and vertical types, De-Interlace) keep those axes, and an uneven scale or a shear sets a direction from the one vector it maps, not a skewed pattern. Scores and hours unchanged. diff --git a/docs/ui-parity.md b/docs/ui-parity.md index 8c104ff5bc..8059d8f3af 100644 --- a/docs/ui-parity.md +++ b/docs/ui-parity.md @@ -395,7 +395,7 @@ next unit in the order a right-click on a ruler lists them, from Feet back to Po | Command search: Up and Down move through the results, Enter runs the highlighted one | done | #1798 (#1757) | | Learn panel: Window › Learn and Explore tutorials on the app bar open it; For you holds a Quick skill guide card, Skills lists VectorCraft's own skills with progress rings that fill and counts of tutorials finished, a tutorial shows its numbered steps with a check box each that marks the step done once its sample is open, a finished tutorial has a check mark, Back goes up a level; a tool's name in a step is a link that marks the tool where the toolbars show it (its button, its group's flyout, a torn-off strip, a toolbar made with New Toolbar or the All Tools drawer) without choosing it; View more opens the tutorial's practice sample as a new untitled document, Finish tutorial then marks it finished with all its steps, and Next Up shows the next tutorial in the same skill; Reset progress clears the progress (no video) | done | [the help page](https://helpx.adobe.com/illustrator/desktop/get-started/learn-the-basics/learn-skills-quick-skill-guide.html); `learn.list`, `learn.tab`, `learn.skills`, `learn.skill`, `learn.show`, `learn.back`, `learn.locateTool`, `learn.openSample`, `learn.markStep`, `learn.finish`, `learn.next`, `learn.resetProgress`; the mark's look and 3-second lifetime, marking steps by hand, keeping the progress in the preferences and Reset progress are VectorCraft's own rules; `panels::learn::tests`, `toolbar::tests` | | Pathfinder panel: a group selected alone counts its nested shapes, so an expanded stroked object keeps the Shape Modes enabled | done | #1642 (#1635) | -| Selected Grid Repeat shows row, column and corner handles and spacing sliders; bounding-box handles take priority where they meet | done | #2691, `tools/src/repeat_grid.rs`; [public behavior reference](https://helpx.adobe.com/illustrator/desktop/paint-and-fill/create-and-edit-patterns/set-grid-repeat-options.html); drags preview and commit `object.repeat.options` as one undo step, Escape cancels; a selected Radial Repeat shows an instances handle below it (16 px of drag per instance, 1 to 1,000) and a radius handle on its circle the same way (`tools/src/repeat_radial.rs`; [public behavior reference](https://helpx.adobe.com/illustrator/desktop/paint-and-fill/create-and-edit-patterns/create-radial-repeats.html)); its splitter has no handle yet | +| Selected Grid Repeat shows row, column and corner handles and spacing sliders; bounding-box handles take priority where they meet | done | #2691, `tools/src/repeat_grid.rs`; [public behavior reference](https://helpx.adobe.com/illustrator/desktop/paint-and-fill/create-and-edit-patterns/set-grid-repeat-options.html); drags preview and commit `object.repeat.options` as one undo step, Escape cancels; a selected Radial Repeat shows an instances handle below it (16 px of drag per instance, 1 to 1,000) and a radius handle on its circle the same way (`tools/src/repeat_radial.rs`; [public behavior reference](https://helpx.adobe.com/illustrator/desktop/paint-and-fill/create-and-edit-patterns/create-radial-repeats.html)), and a splitter on its circle that hides the instances it is dragged back past while the others keep their places, and shows them again when dragged forward (its place half a step past the last instance shown and its limit of one instance shown are VectorCraft's own rules) | | Grid Repeat Options (Object › Repeat › Options…) has a Preview checkbox: the repeat on the canvas follows the fields while the dialog is open, Cancel puts the original back without a history step, OK keeps the previewed values as one undo step | done | #2651; [public behavior reference](https://helpx.adobe.com/illustrator/desktop/paint-and-fill/create-and-edit-patterns/set-grid-repeat-options.html) lists the Preview option for the grid options only, so Radial and Mirror Repeat Options have none; `dialogs/command.rs` tests | | Type on a Path Options (Type › Type on a Path › Type on a Path Options…, or a double-click on the Type on a Path tools) has a Preview checkbox, off when it opens: the selected type on a path follows Effect, Flip, Align to Path and Spacing while the dialog is open, Cancel puts it back without a history step, OK keeps the previewed values as one undo step | done | #5360; the [public page](https://helpx.adobe.com/illustrator/using/creating-type-path.html) lists the dialog's options, and public tutorials of the dialog show its Preview checkbox; `tests/pathtype.rs` | | Graph Type (Object › Graph › Type…, or a double-click on a graph tool) is a dialog of its own: a menu at the top shows Graph Options or the page of an axis; Graph Options has a button per graph type, Value Axis with Separate Scales, the Style checkboxes (Add Drop Shadow, Add Legend Across Top, First Row in Front, First Column in Front) and the options of the type picked (Column or Bar Width and Cluster Width; Mark Data Points, Connect Data Points, Edge-to-Edge Lines and Draw Filled Lines; a pie graph's Legend, Position and Sort); the Value Axis page (Left Axis and Right Axis with the value axis on both sides) has Tick Values with Override Calculated Values, Tick Marks and Add Labels, and the Category Axis page has Tick Marks with Draw Tick Marks Between Labels; with series picked by Group Selection the type and value axis go to those series | done | Public pages: [graph types](https://helpx.adobe.com/illustrator/desktop/automate-visualize-data/visualize-data/change-graph-types.html), [value axes](https://helpx.adobe.com/illustrator/desktop/automate-visualize-data/visualize-data/change-graph-value-axes.html), [columns, bars and lines](https://helpx.adobe.com/illustrator/desktop/automate-visualize-data/visualize-data/format-columns-bars-and-lines.html), [pie graphs](https://helpx.adobe.com/illustrator/desktop/automate-visualize-data/visualize-data/format-pie-graphs.html), [separate scales](https://helpx.adobe.com/illustrator/desktop/automate-visualize-data/visualize-data/assign-different-scales-to-value-axes.html), [combined types](https://helpx.adobe.com/illustrator/desktop/automate-visualize-data/visualize-data/combine-different-graph-types.html). The options dimmed for a type, the pages listed and the Legend checkbox are VectorCraft's own rules. Dialog `graphType`; `dialogs/graph_type.rs` and its tests |