From 2b61bdc7520f75987de5b6a025598b5f21ead919 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 29 Nov 2026 03:38:29 -0800 Subject: [PATCH] Arrange Tools: Offset Objects chains the selection in a row or a column with a set gap MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Object › Plug-ins › Arrange Tools › Offset Objects… (addon.arrange.offset) puts the selected objects one after another in a row (left to right) or a column (top to bottom), each a gap past the one before it; a negative gap overlaps them. The order is the stacking order from the back or the position (left or top edges), and Reverse Order runs it the other way. The first object stays where it is, and the others move only along the row or column, keeping their place across it. Objects are measured by their visual bounds, a clipping group by its mask. One undo step, none when nothing moves; bad params are refused. The dialog has Direction, Gap, Order and Reverse Order with Preview. Docs: docs/mcp.md, docs/ui-parity.md, docs/target-app-parity.md, ROADMAP. --- ROADMAP.md | 1 + crates/engine/src/cmd/addons/arrange.rs | 50 ++++++- crates/engine/src/cmd/addons/arrange/tests.rs | 128 ++++++++++++++++++ crates/engine/src/cmd/plugin_call/reviewed.rs | 1 + crates/engine/tests/command_sweep.rs | 2 + crates/ui-egui/src/addons/arrange.rs | 27 +++- crates/ui-egui/src/addons/arrange/tests.rs | 54 ++++++++ docs/mcp.md | 6 +- docs/target-app-parity.md | 4 + docs/ui-parity.md | 1 + 10 files changed, 268 insertions(+), 6 deletions(-) diff --git a/ROADMAP.md b/ROADMAP.md index d40c33e9e1..c743448b07 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -163,6 +163,7 @@ Ranked; detail in [docs/roadmap.md](docs/roadmap.md) and [docs/gaps.md](docs/gap - 2026-11-01: Expand Dashes into Paths joins the Path Precision Tools add-on (Object › Plug-ins › Path Precision Tools): each selected path's dashed stroke becomes separate open paths, one per dash, laid out exactly as the stroke draws them (pattern, offset, Align Dashes to Corners and Path Ends), each keeping the stroke with the dashes off, so the gaps are real gaps for cutters and plotters, as one undo step (`addon.pathtools.expandDashes`, #4922). - 2026-11-01: Randomize Opacity joins the Arrange Tools add-on (Object › Plug-ins › Arrange Tools): each selected object gets its own opacity at random between a minimum and a maximum percent, with a seed that repeats the result, as one undo step (`addon.arrange.randomizeOpacity`, #4925). - 2026-11-01: Sort Objects joins the Arrange Tools add-on (Object › Plug-ins › Arrange Tools): the selected objects are sorted by width, height, area, position, opacity or stacking order (small to large, large to small or at random) and take another of those in that order, trading their values or stepping them evenly, as one undo step (`addon.arrange.sort`, #4917). +- 2026-11-29: Offset Objects joins the Arrange Tools add-on (Object › Plug-ins › Arrange Tools): the selected objects are chained one after another in a row or a column with a set gap (negative to overlap them), in stacking order or by position, either way; the first stays in place and the others move only along the row or column, as one undo step (`addon.arrange.offset`). A VectorCraft addition: headline numbers unchanged. - 2026-11-15: Tangent Circle joins the Path Precision Tools add-on (Object › Plug-ins › Path Precision Tools): the circles that touch two selected paths or compound paths at a set radius, or three of them (up to eight for three circles), touching each outline without crossing it; circles, rotated ellipses and other paths alike. A dialog that previews every circle or one picked by number, the current paint, one undo step (`addon.pathtools.tangentCircle`). A VectorCraft addition: headline numbers unchanged. - 2026-11-17: Add Bounding Rectangle and Add Bounding Circle join the Path Precision Tools add-on (Object › Plug-ins › Path Precision Tools): a live rectangle on the selection's geometric bounding box, or the smallest live circle that holds its outlines, around the whole selection or around each object, with the current paint and one undo step; the menu items open a dialog with Offset, One per Object and Preview (`addon.pathtools.boundingRectangle`, `addon.pathtools.boundingCircle`, #6966). A VectorCraft addition: headline numbers unchanged. - 2026-11-22: Add Inscribed Circle joins the Path Precision Tools add-on (Object › Plug-ins › Path Precision Tools): the largest live circle inside each selected closed path or compound path, in the area it fills under its fill rule, with the current paint and one undo step (`addon.pathtools.inscribedCircle`, #6966). A VectorCraft addition: headline numbers unchanged. diff --git a/crates/engine/src/cmd/addons/arrange.rs b/crates/engine/src/cmd/addons/arrange.rs index f81d7a599a..a25f341d1c 100644 --- a/crates/engine/src/cmd/addons/arrange.rs +++ b/crates/engine/src/cmd/addons/arrange.rs @@ -1,5 +1,6 @@ //! Arrange Tools (`addon.arrange.*`), a built-in add-on: Arrange in Grid lays the selected objects -//! out in rows and columns, a row or a column; Swap Objects swaps the places (and sizes) of two; +//! out in rows and columns, a row or a column; Offset Objects chains them one after another in a +//! row or a column with a set gap, the first staying in place; Swap Objects swaps the places (and sizes) of two; //! Replace with Top Object puts a copy of the topmost selected object in place of each of the //! others; and Set Size of Each gives every selected object an exact width and height. Places and //! sizes are measured and set as `object.setBounds` does. Group Overlapping Objects groups the @@ -17,7 +18,7 @@ use std::sync::Arc; use serde_json::{Value, json}; use vectorcraft_color::recolor::Rng; use vectorcraft_doc::{Node, NodeId, OrientedBox}; -use vectorcraft_geom::{Affine, Point, Rect}; +use vectorcraft_geom::{Affine, Point, Rect, Vec2}; use vectorcraft_render::effects; use super::super::appearance::series_children_in_paint_order; @@ -52,6 +53,15 @@ pub fn specs() -> Vec { has_selection, grid ), + cmd!( + "addon.arrange.offset", + "Offset Objects", + ["Object", "Plug-ins", "Arrange Tools"], + None, + "{direction?: \"row\" (left to right) | \"column\" (top to bottom) (\"row\"), gap?: pt −1000000..1000000 (10; negative: the objects overlap), order?: \"stacking\" (stacking order, from the back) | \"position\" (by left edge in a row, by top edge in a column; equal edges keep their stacking order) (\"stacking\"), reverse?: false (true: the order runs the other way)} chain the selected objects (the top-level ones) one after another in that order, as one undo step: the first stays where it is, and each later one moves only along the direction, so that its left (top) edge is `gap` past the right (bottom) edge of the one before it; its place across the direction stays. Everything is measured by visual bounds (strokes and effects as drawn; a clipping group by its mask). A run that moves nothing makes no step → {count}", + has_multi, + offset + ), cmd!( "addon.arrange.swap", "Swap Objects", @@ -228,6 +238,42 @@ fn grid(s: &mut Session, p: &Value) -> Result { Ok(json!({ "count": n })) } +fn offset(s: &mut Session, p: &Value) -> Result { + const C: &str = "addon.arrange.offset"; + let row = choice(p, C, "direction", &["row", "column"])?.unwrap_or("row") == "row"; + let gap = number_in(p, "gap", 10.0, (-LIMIT, LIMIT), C)?; + let by_position = choice(p, C, "order", &["stacking", "position"])?.unwrap_or("stacking") == "position"; + let reverse = switch_or(p, "reverse", false, C)?; + let roots = selected_roots(s)?; + let d = &s.doc()?.doc; + // The objects in stacking order from the back, each with its leading and trailing edge along the direction. + let mut items: Vec<(NodeId, f64, f64)> = roots + .iter() + .filter_map(|id| { + let b = effects::preview::bounds_of(d, &[*id], true)?; + Some(if row { (*id, b.x0, b.x1) } else { (*id, b.y0, b.y1) }) + }) + .collect(); + if by_position { + items.sort_by(|a, b| a.1.total_cmp(&b.1)); + } + if reverse { + items.reverse(); + } + // The first stays; each later one starts `gap` past where the one before it now ends. + let mut end: Option = None; + let xfs: Vec<(NodeId, Affine)> = items + .iter() + .map(|&(id, start, finish)| { + let shift = end.map_or(0.0, |e| e + gap - start); + end = Some(finish + shift); + (id, Affine::translate(if row { Vec2::new(shift, 0.0) } else { Vec2::new(0.0, shift) })) + }) + .collect(); + transform_each(s, "Offset Objects", false, &xfs)?; + Ok(json!({ "count": items.len() })) +} + fn swap(s: &mut Session, p: &Value) -> Result { const C: &str = "addon.arrange.swap"; let size = switch_or(p, "size", false, C)?; diff --git a/crates/engine/src/cmd/addons/arrange/tests.rs b/crates/engine/src/cmd/addons/arrange/tests.rs index 759f6f321e..498a927898 100644 --- a/crates/engine/src/cmd/addons/arrange/tests.rs +++ b/crates/engine/src/cmd/addons/arrange/tests.rs @@ -106,6 +106,134 @@ fn grid_measures_visual_bounds() { assert!(near(bounds(&s, b), (24.0, 0.0, 20.0, 20.0)), "{:?}", bounds(&s, b)); } +#[test] +fn offset_chains_a_row_in_stacking_order_from_the_first_in_place() { + let mut s = session(); + let a = rect(&mut s, 100.0, 50.0, 20.0, 10.0); + let b = rect(&mut s, 0.0, 200.0, 40.0, 30.0); + let c = rect(&mut s, 300.0, 0.0, 10.0, 10.0); + select(&mut s, &[c, a, b]); + let n = steps(&s); + let r = s.execute("addon.arrange.offset", &json!({"gap": 5})).unwrap(); + assert_eq!(r["count"], json!(3)); + assert_eq!(steps(&s), n + 1, "one undo step"); + // From the back: a stays, b starts 5 past a's right edge, c 5 past b's; each keeps its y. + assert!(near(bounds(&s, a), (100.0, 50.0, 20.0, 10.0)), "{:?}", bounds(&s, a)); + assert!(near(bounds(&s, b), (125.0, 200.0, 40.0, 30.0)), "{:?}", bounds(&s, b)); + assert!(near(bounds(&s, c), (170.0, 0.0, 10.0, 10.0)), "{:?}", bounds(&s, c)); + s.execute("edit.undo", &json!({})).unwrap(); + assert!(near(bounds(&s, b), (0.0, 200.0, 40.0, 30.0))); + assert!(near(bounds(&s, c), (300.0, 0.0, 10.0, 10.0))); + // Reversed: c stays, then b, then a. The gap defaults to 10. + s.execute("addon.arrange.offset", &json!({"reverse": true})).unwrap(); + assert!(near(bounds(&s, c), (300.0, 0.0, 10.0, 10.0)), "{:?}", bounds(&s, c)); + assert!(near(bounds(&s, b), (320.0, 200.0, 40.0, 30.0)), "{:?}", bounds(&s, b)); + assert!(near(bounds(&s, a), (370.0, 50.0, 20.0, 10.0)), "{:?}", bounds(&s, a)); +} + +#[test] +fn offset_chains_a_column_by_position_either_way_and_overlaps_with_a_negative_gap() { + let mut s = session(); + let a = rect(&mut s, 0.0, 100.0, 10.0, 20.0); + let b = rect(&mut s, 50.0, 0.0, 10.0, 10.0); + let c = rect(&mut s, 100.0, 40.0, 10.0, 30.0); + select(&mut s, &[a, b, c]); + // Top to bottom: b, c, a; each 5 into the one before it, keeping its x. + s.execute("addon.arrange.offset", &json!({"direction": "column", "order": "position", "gap": -5})).unwrap(); + assert!(near(bounds(&s, b), (50.0, 0.0, 10.0, 10.0)), "{:?}", bounds(&s, b)); + assert!(near(bounds(&s, c), (100.0, 5.0, 10.0, 30.0)), "{:?}", bounds(&s, c)); + assert!(near(bounds(&s, a), (0.0, 30.0, 10.0, 20.0)), "{:?}", bounds(&s, a)); + s.execute("edit.undo", &json!({})).unwrap(); + // Bottom to top: a stays, then c, then b. + s.execute("addon.arrange.offset", &json!({"direction": "column", "order": "position", "reverse": true, "gap": 0})).unwrap(); + assert!(near(bounds(&s, a), (0.0, 100.0, 10.0, 20.0)), "{:?}", bounds(&s, a)); + assert!(near(bounds(&s, c), (100.0, 120.0, 10.0, 30.0)), "{:?}", bounds(&s, c)); + assert!(near(bounds(&s, b), (50.0, 150.0, 10.0, 10.0)), "{:?}", bounds(&s, b)); + s.execute("edit.undo", &json!({})).unwrap(); + // Left to right in a row: a, b, c. + s.execute("addon.arrange.offset", &json!({"order": "position", "gap": 1})).unwrap(); + assert!(near(bounds(&s, a), (0.0, 100.0, 10.0, 20.0)), "{:?}", bounds(&s, a)); + assert!(near(bounds(&s, b), (11.0, 0.0, 10.0, 10.0)), "{:?}", bounds(&s, b)); + assert!(near(bounds(&s, c), (22.0, 40.0, 10.0, 30.0)), "{:?}", bounds(&s, c)); +} + +#[test] +fn offset_measures_visual_bounds_and_clipping_groups_by_their_mask() { + let mut s = session(); + let a = rect(&mut s, 0.0, 0.0, 20.0, 20.0); + let b = rect(&mut s, 100.0, 0.0, 20.0, 20.0); + select(&mut s, &[a, b]); + s.execute("paint.setStroke", &json!({"color": "#000000"})).unwrap(); + s.execute("stroke.set", &json!({"weight": 4})).unwrap(); + s.execute("addon.arrange.offset", &json!({"gap": 0})).unwrap(); + // Visual boxes 24 wide, touching. + assert!(near(bounds(&s, b), (24.0, 0.0, 20.0, 20.0)), "{:?}", bounds(&s, b)); + let mut s = session(); + let a = rect(&mut s, 0.0, 0.0, 20.0, 20.0); + // A 200 wide object clipped to a 30 wide mask at x 100. + let clipped = rect(&mut s, 50.0, 50.0, 200.0, 10.0); + let mask = rect(&mut s, 100.0, 40.0, 30.0, 30.0); + select(&mut s, &[clipped, mask]); + s.execute("object.clippingMask.make", &json!({})).unwrap(); + let group = s.doc().unwrap().selection.objects[0]; + let c = rect(&mut s, 300.0, 0.0, 10.0, 10.0); + select(&mut s, &[a, group, c]); + s.execute("addon.arrange.offset", &json!({"gap": 0})).unwrap(); + // The mask starts at a's right edge, and c at the mask's. + assert!(near(bounds(&s, mask), (20.0, 40.0, 30.0, 30.0)), "{:?}", bounds(&s, mask)); + assert!(near(bounds(&s, clipped), (-30.0, 50.0, 200.0, 10.0)), "{:?}", bounds(&s, clipped)); + assert!(near(bounds(&s, c), (50.0, 0.0, 10.0, 10.0)), "{:?}", bounds(&s, c)); +} + +#[test] +fn offset_makes_no_step_when_nothing_moves_and_skips_locked_objects() { + let mut s = session(); + let a = rect(&mut s, 0.0, 0.0, 20.0, 20.0); + let b = rect(&mut s, 30.0, 50.0, 20.0, 20.0); + select(&mut s, &[a]); + assert!(!enabled(&s, "addon.arrange.offset"), "off with one object"); + select(&mut s, &[a, b]); + assert!(enabled(&s, "addon.arrange.offset")); + // Already 10 apart in a row. + let n = steps(&s); + s.execute("addon.arrange.offset", &json!({})).unwrap(); + assert_eq!(steps(&s), n, "no step when nothing moves"); + // Two objects in one group are one object: nothing to chain. + s.execute("object.group", &json!({})).unwrap(); + s.execute("select.all", &json!({})).unwrap(); + assert!(!enabled(&s, "addon.arrange.offset"), "off with one group"); + refuses(&mut s, "addon.arrange.offset", &[json!({"gap": 50})]); + s.execute("edit.undo", &json!({})).unwrap(); + let c = rect(&mut s, 200.0, 200.0, 10.0, 10.0); + select(&mut s, &[b]); + s.execute("object.lock", &json!({})).unwrap(); + s.execute("select.all", &json!({})).unwrap(); + s.execute("addon.arrange.offset", &json!({"gap": 0})).unwrap(); + assert!(near(bounds(&s, b), (30.0, 50.0, 20.0, 20.0)), "the locked object stays, {:?}", bounds(&s, b)); + assert!(near(bounds(&s, c), (20.0, 200.0, 10.0, 10.0)), "{:?}", bounds(&s, c)); +} + +#[test] +fn offset_refuses_bad_params() { + let mut s = session(); + let a = rect(&mut s, 0.0, 0.0, 20.0, 10.0); + let b = rect(&mut s, 100.0, 100.0, 40.0, 40.0); + select(&mut s, &[a, b]); + refuses( + &mut s, + "addon.arrange.offset", + &[ + json!({"direction": "diagonal"}), + json!({"direction": 1}), + json!({"gap": 1e7}), + json!({"gap": -1e7}), + json!({"gap": "10"}), + json!({"order": "size"}), + json!({"reverse": "yes"}), + ], + ); +} + #[test] fn swap_trades_places_and_optionally_sizes() { let mut s = session(); diff --git a/crates/engine/src/cmd/plugin_call/reviewed.rs b/crates/engine/src/cmd/plugin_call/reviewed.rs index c2699f219c..9849a22077 100644 --- a/crates/engine/src/cmd/plugin_call/reviewed.rs +++ b/crates/engine/src/cmd/plugin_call/reviewed.rs @@ -6,6 +6,7 @@ pub(super) const ALLOWED: &[&str] = &[ "addon.arrange.grid", "addon.arrange.groupOverlapping", + "addon.arrange.offset", "addon.arrange.randomizeOpacity", "addon.arrange.replace", "addon.arrange.size", diff --git a/crates/engine/tests/command_sweep.rs b/crates/engine/tests/command_sweep.rs index 462641b953..c98cd9278e 100644 --- a/crates/engine/tests/command_sweep.rs +++ b/crates/engine/tests/command_sweep.rs @@ -995,6 +995,8 @@ fn structured_junk() { ("addon.arrange.grid", json!({"columns": u64::MAX, "gapX": 1e6, "gapY": -1e6, "centerOnArtboard": true})), ("addon.arrange.grid", json!({"layout": "row", "gapX": f64::MAX, "columns": -1})), ("addon.arrange.grid", json!({"layout": "column", "gapX": -1e6})), + ("addon.arrange.offset", json!({"direction": "column", "gap": -1e6, "order": "position", "reverse": true})), + ("addon.arrange.offset", json!({"direction": "diagonal", "gap": f64::MAX, "order": 3, "reverse": "x"})), ("addon.arrange.swap", json!({"size": true, "scaleStrokes": true})), ("addon.arrange.replace", json!({"fit": "proportional", "keep": true})), ("addon.arrange.replace", json!({"fit": "bounds", "scaleStrokes": true})), diff --git a/crates/ui-egui/src/addons/arrange.rs b/crates/ui-egui/src/addons/arrange.rs index a26f5f7a28..ccd32bd7aa 100644 --- a/crates/ui-egui/src/addons/arrange.rs +++ b/crates/ui-egui/src/addons/arrange.rs @@ -1,5 +1,5 @@ //! Arrange Tools in the interface: its submenu (Object › Plug-ins › Arrange Tools); the dialogs of -//! Arrange in Grid, Replace with Top Object, Set Size of Each, Randomize Opacity and Sort Objects, +//! Arrange in Grid, Offset Objects, Replace with Top Object, Set Size of Each, Randomize Opacity and Sort Objects, //! which preview on the canvas and run their `addon.arrange.*` command on OK; Group Overlapping //! Objects; and Zoom to Selection ([`ZOOM`]), which fits the active view to the selection. @@ -22,19 +22,21 @@ use crate::menus::{Sep, c, cp}; /// Zoom to Selection: a view command, since the view is the interface's. pub const ZOOM: &str = "addon.arrange.zoomSelection"; const GRID: &str = "addon.arrange.grid"; +const OFFSET: &str = "addon.arrange.offset"; const REPLACE: &str = "addon.arrange.replace"; const SIZE: &str = "addon.arrange.size"; const OPACITY: &str = "addon.arrange.randomizeOpacity"; const SORT: &str = "addon.arrange.sort"; /// Each dialog's command and heading. -const DIALOGS: [(&str, &str); 5] = [ +const DIALOGS: [(&str, &str); 6] = [ (GRID, "Arrange in Grid"), + (OFFSET, "Offset Objects"), (REPLACE, "Replace with Top Object"), (SIZE, "Set Size of Each"), (OPACITY, "Randomize Opacity"), (SORT, "Sort Objects"), ]; -/// The widths and heights Set Size of Each takes (pt), and the gaps Arrange in Grid takes. +/// The widths and heights Set Size of Each takes (pt), and the gaps Arrange in Grid and Offset Objects take. const SIZES: std::ops::RangeInclusive = 0.001..=1e6; const GAPS: std::ops::RangeInclusive = -1e6..=1e6; /// The seeds the Randomize Opacity dialog offers. @@ -56,6 +58,7 @@ const ATTRIBUTES: [(&str, &str); 7] = [ pub fn menu() -> Vec { vec![ c("Arrange in Grid…", GRID), + c("Offset Objects…", OFFSET), cp("Swap Objects", "addon.arrange.swap", json!({})), cp("Swap Objects and Sizes", "addon.arrange.swap", json!({ "size": true })), c("Replace with Top Object…", REPLACE), @@ -69,6 +72,7 @@ pub fn menu() -> Vec { } static GRID_SPEC: Spec = Spec { command: GRID, params: grid_params, found: None }; +static OFFSET_SPEC: Spec = Spec { command: OFFSET, params: offset_params, found: None }; static REPLACE_SPEC: Spec = Spec { command: REPLACE, params: replace_params, found: None }; static SIZE_SPEC: Spec = Spec { command: SIZE, params: size_params, found: None }; static OPACITY_SPEC: Spec = Spec { command: OPACITY, params: opacity_params, found: None }; @@ -116,6 +120,17 @@ fn grid_rows(lengths: LengthUnits) -> Vec { ] } +fn offset_rows(lengths: LengthUnits) -> Vec { + let directions = [("row", "Row (Left to Right)"), ("column", "Column (Top to Bottom)")]; + let orders = [("stacking", "Stacking Order"), ("position", "Position")]; + vec![ + choice("direction", "Direction:", &directions, "row"), + length("gap", "Gap:", 10.0, GAPS, lengths), + choice("order", "Order:", &orders, "stacking"), + check("reverse", "Reverse Order", false), + ] +} + fn replace_rows() -> Vec { let fits = [("keep", "Actual Size"), ("bounds", "Bounds"), ("proportional", "Bounds (Fit Proportionally)")]; vec![choice("fit", "Size:", &fits, "keep"), check("keep", "Keep Original", false), scale_strokes()] @@ -156,6 +171,10 @@ fn grid_params(fields: &DialogFields) -> Value { Value::Object(form::json_of(&grid_rows(POINTS), fields)) } +fn offset_params(fields: &DialogFields) -> Value { + Value::Object(form::json_of(&offset_rows(POINTS), fields)) +} + fn replace_params(fields: &DialogFields) -> Value { Value::Object(form::json_of(&replace_rows(), fields)) } @@ -196,6 +215,7 @@ pub(crate) fn open(app: &mut VectorcraftApp, id: &str) -> Option (offset_rows(lengths), json!({ "direction": "row", "gap": 10, "order": "stacking", "reverse": false })), REPLACE => (replace_rows(), json!({ "fit": "keep", "keep": false, "scaleStrokes": strokes })), // A new seed each time the document has changed, so running it again varies the result. OPACITY => (opacity_rows(), json!({ "min": 30, "max": 100, "seed": st.revision % SEEDS })), @@ -223,6 +243,7 @@ pub(crate) fn open(app: &mut VectorcraftApp, id: &str) -> Option super::dialogs::open(app, &GRID_SPEC, fields, move |fields| dialog(GRID, grid_rows(lengths)).values(Bind::bound(fields))), + OFFSET => super::dialogs::open(app, &OFFSET_SPEC, fields, move |fields| dialog(OFFSET, offset_rows(lengths)).values(Bind::bound(fields))), REPLACE => super::dialogs::open(app, &REPLACE_SPEC, fields, |fields| dialog(REPLACE, replace_rows()).values(Bind::bound(fields))), OPACITY => super::dialogs::open(app, &OPACITY_SPEC, fields, |fields| { let (min, max) = (fields.number("min").unwrap_or(0.0), fields.number("max").unwrap_or(100.0)); diff --git a/crates/ui-egui/src/addons/arrange/tests.rs b/crates/ui-egui/src/addons/arrange/tests.rs index 420bfdb01d..e0c0e693d3 100644 --- a/crates/ui-egui/src/addons/arrange/tests.rs +++ b/crates/ui-egui/src/addons/arrange/tests.rs @@ -61,6 +61,60 @@ fn real_grid_edits_reach_the_preview_and_confirmed_geometry() { assert!(!app.any_dialog_open()); } +fn steps(app: &VectorcraftApp) -> usize { + app.session.doc().unwrap().history.undo.len() +} + +#[test] +fn real_offset_edits_reach_the_preview_and_ok_applies_them_as_one_step() { + let (app, a, b) = app(); + let n = steps(&app); + let mut panel = Harness::new(app, crate::tests::picks::dialogs); + click(&mut panel.app(), "Offset Objects…"); + type_number(&mut panel, "Gap", "3"); + let id = host::dialog_id(&panel.app()); + assert_eq!(host::read(&panel.app(), id, |f| f.number("gap")), Some(3.0)); + { + // From the back: a stays and b starts 3 past its right edge, keeping its y. + let app = panel.app(); + assert_eq!((bounds(&app, a).x0, bounds(&app, a).y0), (0.0, 0.0)); + assert_eq!((bounds(&app, b).x0, bounds(&app, b).y0), (23.0, 100.0)); + } + panel.focus("Reverse Order"); + panel.key(egui::Key::Space, egui::Modifiers::NONE); + panel.frame(); + let preview = { + // Reversed: b stays and a starts 3 past b's right edge, keeping its y. + let app = panel.app(); + assert_eq!((bounds(&app, b).x0, bounds(&app, b).y0), (100.0, 100.0)); + assert_eq!((bounds(&app, a).x0, bounds(&app, a).y0), (143.0, 0.0)); + (bounds(&app, a), bounds(&app, b)) + }; + panel.click("OK"); + panel.frame(); + let app = panel.app(); + assert_eq!((bounds(&app, a), bounds(&app, b)), preview); + assert_eq!(steps(&app), n + 1, "one undo step"); + assert!(!app.any_dialog_open()); +} + +#[test] +fn real_offset_cancel_puts_the_objects_back() { + let (app, a, b) = app(); + let n = steps(&app); + let before = (bounds(&app, a), bounds(&app, b)); + let mut panel = Harness::new(app, crate::tests::picks::dialogs); + click(&mut panel.app(), "Offset Objects…"); + type_number(&mut panel, "Gap", "50"); + assert_eq!(bounds(&panel.app(), b).x0, 70.0, "the preview moves b"); + panel.click("Cancel"); + panel.frame(); + let app = panel.app(); + assert_eq!((bounds(&app, a), bounds(&app, b)), before); + assert_eq!(steps(&app), n); + assert!(!app.any_dialog_open()); +} + #[test] fn real_size_keyboard_edits_keep_unticked_sides_unchanged() { let (app, a, b) = app(); diff --git a/docs/mcp.md b/docs/mcp.md index d698534089..fbd68a9bca 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -17430,11 +17430,12 @@ images and patterns keep their colours. → `{changed, swatches: [the document s Arrange Tools is a built-in add-on that lays out, swaps, replaces and sizes selected objects: its commands are `addon.arrange.*`, and in the desktop app it lives in Object › Plug-ins › Arrange Tools. Each command acts on the top-level selected objects and is one undo step; a run that moves nothing makes no step. Places and sizes are measured -as `object.setBounds` measures them (Use Preview Bounds), except Arrange in Grid, which uses visual bounds. +as `object.setBounds` measures them (Use Preview Bounds), except Arrange in Grid and Offset Objects, which use visual bounds. | Command | Parameters (default) | Does | |---|---|---| | `addon.arrange.grid` | `layout`: `grid`, `row`, `column` (`grid`); `columns`: 1…10000 (⌈√count⌉, never more than the count); `gapX` pt (10), `gapY` pt (`gapX`), each −1000000…1000000; `centerOnArtboard` (false) | Lays the objects out in their stacking order from the back, left to right and top to bottom. Each cell is as wide as the widest object in its column and as tall as the tallest in its row, and each object is centred in its cell. The grid starts at the selection's top-left, or is centred on the artboard under the selection's centre (the first artboard when none is there). → `{count}` | +| `addon.arrange.offset` | `direction`: `row` (left to right), `column` (top to bottom) (`row`); `gap` pt, −1000000…1000000 (10; negative overlaps the objects); `order`: `stacking` (stacking order from the back), `position` (by left edge in a row, by top edge in a column; equal edges keep their stacking order) (`stacking`); `reverse` (false) | Chains the objects one after another in that order: the first stays where it is, and each later one moves only along the direction so that its left (top) edge is `gap` past the right (bottom) edge of the one before it; its place across the direction stays. Measured by visual bounds, a clipping group by its mask. Needs two objects or more. → `{count}` | | `addon.arrange.swap` | `size` (false); `scaleStrokes` (the Scale Strokes & Effects preference) | Swaps the bounds centres of exactly two selected objects (off otherwise); with `size`, each also takes the other's width and height. | | `addon.arrange.replace` | `fit`: `keep`, `bounds` (the replaced object's width and height), `proportional` (fits inside them) (`keep`); `scaleStrokes`; `keep` (false) | Puts a copy of the topmost selected object centred on each of the other selected objects, in that object's place in the stacking order; the replaced objects are deleted unless `keep` (the copy then goes right above each). Needs two objects or more; the copies are selected. → `{ids}` | | `addon.arrange.size` | `width`, `height` pt, 0.001…1000000 (at least one); `proportional` (false: a side not given stays; true: it follows the given one in proportion); `reference` 0…8 (4, the centre); `scaleStrokes` | Gives every selected object that width and height, keeping its reference point in place (the 9-point grid row by row from the top-left). | @@ -17447,9 +17448,12 @@ active view so the selection's visual bounds fill the window with a margin, as ` and fails with nothing selected. Arrange in Grid…, Replace with Top Object…, Set Size of Each…, Randomize Opacity… and Sort Objects… open dialogs (`ui.menuDialog {command}`, dialog kinds `arrangeGrid`, `arrangeReplace`, `arrangeSize`, `arrangeOpacity` and `arrangeSort`) whose fields are the command's parameters, with Preview (Randomize Opacity's seed, and Sort Objects' `seed`, which is not shown, start new whenever the document has changed); Set Size of Each's `__width` and `__height` say which sizes OK applies. +Offset Objects… opens one the same way (`ui.menuDialog {command: "addon.arrange.offset"}`), with Direction, Gap, Order +and Reverse Order. ```json {"name":"run_command","arguments":{"command":"addon.arrange.grid","params":{"columns":4,"gapX":12,"gapY":12}}} +{"name":"run_command","arguments":{"command":"addon.arrange.offset","params":{"direction":"column","gap":6,"order":"position"}}} {"name":"run_command","arguments":{"command":"addon.arrange.replace","params":{"fit":"proportional"}}} {"name":"run_command","arguments":{"command":"addon.arrange.size","params":{"width":72,"proportional":true}}} ``` diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 032041c2a1..001f3a2ecb 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -3156,6 +3156,10 @@ A VectorCraft addition, not a feature of the reference app, so no area score mov A VectorCraft addition, not a feature of the reference app, so no area score moves. Object › Plug-ins › Arrange Tools › Sort Objects… sorts the top-level selected objects (or `ids`, at most 20000) by one attribute (width, height, area, x or y position, opacity or stacking order; small to large, large to small, or a random order from a seed) and gives them another in that order, the first the smallest value: the objects trade the values they have, or with Distribute Evenly the values step evenly from the smallest to the largest. Lining objects up left to right by size, restacking them so the largest is at the back, or giving them heights that step with their x position are each one run. Sizes and places are measured and set as `object.setBounds` measures them (Use Preview Bounds); a width, height or area changes about each object's centre (an area in proportion), and stacking order trades places only among objects of the same layer or group. One undo step; no step when nothing changes. Tests: `sort_*` in `cmd::addons::arrange::tests` in `vectorcraft-engine` (each attribute sorted by and applied, both directions, distribute, layers kept apart, the seeded random order, `ids`, no step when in order, bad params), `sort_objects_opens_its_dialog_and_runs_on_ok` in `vectorcraft-ui-egui` and `command_sweep`. Commands: `docs/mcp.md` › Arrange Tools add-on. +## Arrange Tools add-on: Offset Objects (2026-11-29) + +A VectorCraft addition, so no area score moves. Object › Plug-ins › Arrange Tools › Offset Objects… chains the top-level selected objects one after another in a row (left to right) or a column (top to bottom) with a gap of −1000000 to 1000000 pt (10 by default; a negative gap overlaps them). The order is the stacking order from the back, or the position (left edges in a row, top edges in a column), and Reverse Order runs it the other way. The first object stays where it is; each later one moves only along the row or column so that it starts the gap past the end of the one before it, and keeps its place across it. Objects are measured by their visual bounds, a clipping group by its mask. One undo step; no step when nothing moves. Tests: `offset_*` in `cmd::addons::arrange::tests` in `vectorcraft-engine` (row and column, both orders and reversed, a negative gap, strokes and clipping groups, no step, locked objects left out, bad params), `real_offset_*` in `vectorcraft-ui-egui` and `command_sweep`. Commands: `docs/mcp.md` › Arrange Tools add-on. + ## Type Tools add-on: Text Tweaker (2026-11-03) A VectorCraft addition, not a feature of the reference app, so no area score moves. Object › Plug-ins › Type Tools › Text Tweaker… gives one character attribute (size, baseline shift, character rotation, horizontal or vertical scale, tracking, leading or stroke weight) to the selected characters letter by letter, from a start value to an end value along a straight ramp, an ease in and out, a bow, a spike or at random with a seed, while the text stays live and editable (#4924). With Block enabled, a leading ramp sets Line Gap from the first changed character instead of varying leading across the text. Values are set as the Character panel sets them, in its units and ranges, so scaled type takes the sizes shown; spaces and line breaks are skipped unless asked for, each type object gets its own ramp, the range is the Type tool's selection or all the text of the selected type objects, and the run is one undo step from a dialog with Preview. Tests: `cmd::addons::typetools::tests` in `vectorcraft-engine` (each shape, each attribute, skipped spaces, ranges, one ramp per object, seeded random values, scaled type, one undo step, bad params refused), `addons::typetools::tests` in `vectorcraft-ui-egui` (the submenu, the dialog, Preview and Cancel, OK) and `command_sweep`. Commands: `docs/mcp.md` › Type Tools add-on. diff --git a/docs/ui-parity.md b/docs/ui-parity.md index 453bda832d..ac20453f86 100644 --- a/docs/ui-parity.md +++ b/docs/ui-parity.md @@ -567,6 +567,7 @@ next unit in the order a right-click on a ruler lists them, from Feet back to Po | Arrange Tools add-on (VectorCraft addition): Object › Plug-ins › Arrange Tools › Group Overlapping Objects groups the selected objects whose visual bounds overlap or touch (chains included, within one layer or group), each group at its frontmost member's stacking place, one undo step | done | #4928; `addon.arrange.groupOverlapping`, `crates/engine/src/cmd/addons/arrange.rs` and its tests; not a feature of the reference app, so it is not scored | | Arrange Tools add-on (VectorCraft addition): Object › Plug-ins › Arrange Tools › Randomize Opacity… gives each selected object its own opacity at random between Minimum and Maximum (%), with a Seed that repeats it and Preview, one undo step | done | #4925; `addon.arrange.randomizeOpacity`, `crates/engine/src/cmd/addons/arrange.rs`, `crates/ui-egui/src/addons/arrange.rs` and their tests; not a feature of the reference app, so it is not scored | | Arrange Tools add-on (VectorCraft addition): Object › Plug-ins › Arrange Tools › Sort Objects… sorts the selected objects by Sort By (width, height, area, X or Y position, opacity, stacking order) in an Order (Small to Large, Large to Small, Random) and gives them Apply To in that order, trading the values or with Distribute Evenly; Scale Strokes & Effects; Preview; one undo step | done | #4917; `addon.arrange.sort`, `crates/engine/src/cmd/addons/arrange.rs`, `crates/ui-egui/src/addons/arrange.rs` and their tests; not a feature of the reference app, so it is not scored | +| Arrange Tools add-on (VectorCraft addition): Object › Plug-ins › Arrange Tools › Offset Objects… chains the selected objects one after another in a Direction (Row (Left to Right) or Column (Top to Bottom)) with a Gap (negative overlaps), in an Order (Stacking Order or Position) with Reverse Order; the first stays in place and the others move only along the row or column; Preview; one undo step | done | `addon.arrange.offset`, `crates/engine/src/cmd/addons/arrange.rs`, `crates/ui-egui/src/addons/arrange.rs` and their tests; a VectorCraft addition, so it is not scored | | Document Tools add-on (VectorCraft addition): Object › Plug-ins › Document Tools › Save a Timestamped Copy writes `_YYYY-MM-DD_HH-MM.` next to the document (a folder picked for one never saved), which keeps its path, title and modified state; off on the web | done | #4926; `addon.document.saveTimestampedCopy`, `crates/engine/src/cmd/addons/document.rs`, `crates/ui-egui/src/addons/document.rs` and their tests; not a feature of the reference app, so it is not scored | | Document Tools add-on (VectorCraft addition): Export All Open Documents as PDF / as SVG (#4920) | done | asks for a folder, writes a copy of every open document named after it (taken names numbered, nothing replaced), documents and active tab unchanged; failures named in the status bar | | Document Tools add-on (VectorCraft addition): Object › Plug-ins › Document Tools › Batch Trace Folder asks for a folder of images, then a destination folder, traces each image with a preset (optionally expanded) and saves it there as `.vectorcraft`, `.svg`, `.pdf`, `.ai` or `.eps` under its own name (taken names numbered, nothing replaced), closing each image again; the status bar counts the images traced and those that couldn't be; off on the web | done | #4921; `addon.document.batchTraceFolder`, `crates/engine/src/cmd/addons/document/batch_trace.rs`, `crates/ui-egui/src/addons/document.rs` and their tests; not a feature of the reference app |