From 9693ce96aac2a7ec6caed6fdb4d89e82b14ee621 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 29 Nov 2026 13:33:21 -0800 Subject: [PATCH] Arrange Tools: Group by Row puts each row of the selection in its own group Object > Plug-ins > Arrange Tools > Group by Row... (addon.arrange.groupRows) groups the selected top-level objects by the rows their visual bounds share: an object joins a row when its bounds overlap the row from top to bottom, and Group By Columns does the same from left to right. Extents that only touch stay apart, and an object that overlaps two rows joins them into one. Only objects in the same layer or group and on the same artboard share a row; an object alone in its row stays as it is. Each new group takes its frontmost member's place in the stacking order, and the groups and the objects left alone stay selected. One undo step, none when no row holds two objects; an unknown direction is refused. At most 20000 objects, sorted once along the axis. Group Overlapping Objects and Group by Row share the step that builds the groups. The dialog has Group By (Rows or Columns) 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 | 77 ++++++++- crates/engine/src/cmd/addons/arrange/tests.rs | 154 ++++++++++++++++++ crates/engine/src/cmd/plugin_call/reviewed.rs | 1 + crates/engine/tests/command_sweep.rs | 2 + crates/ui-egui/src/addons/arrange.rs | 19 ++- crates/ui-egui/src/addons/arrange/tests.rs | 58 +++++++ docs/mcp.md | 5 +- docs/target-app-parity.md | 4 + docs/ui-parity.md | 1 + 10 files changed, 317 insertions(+), 5 deletions(-) diff --git a/ROADMAP.md b/ROADMAP.md index c743448b07..4a869f1d36 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -164,6 +164,7 @@ Ranked; detail in [docs/roadmap.md](docs/roadmap.md) and [docs/gaps.md](docs/gap - 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-29: Group by Row joins the Arrange Tools add-on (Object › Plug-ins › Arrange Tools): the selected objects whose visual bounds overlap from top to bottom go into one group for each row (or, by column, from left to right), within their own layer or group and artboard, at the stacking place of their frontmost member; an object alone in its row stays as it is. One undo step, with a previewed dialog (`addon.arrange.groupRows`). 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 a25f341d1c..4274932141 100644 --- a/crates/engine/src/cmd/addons/arrange.rs +++ b/crates/engine/src/cmd/addons/arrange.rs @@ -4,7 +4,8 @@ //! 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 -//! objects whose visual bounds overlap, Randomize Opacity gives each selected object a random +//! objects whose visual bounds overlap, Group by Row groups them by the rows (or columns) their +//! visual bounds share, Randomize Opacity gives each selected object a random //! opacity, and Sort Objects sorts the selected objects by one attribute and gives them another in //! that order. Its submenu (Object › Plug-ins › Arrange Tools), its dialogs and Zoom to Selection //! (a view command) are the UI's. @@ -98,6 +99,15 @@ pub fn specs() -> Vec { has_multi, group_overlapping ), + cmd!( + "addon.arrange.groupRows", + "Group by Row", + ["Object", "Plug-ins", "Arrange Tools"], + None, + "{direction?: \"row\" (objects whose vertical extents overlap) | \"column\" (objects whose horizontal extents overlap) (\"row\")} group the selected objects (the top-level ones, at most 20000) into one group for each row (column), as one undo step. An object joins a row when its visual bounds (strokes and effects as drawn; a clipping group by its mask) overlap the row's extent across it; extents that only touch stay apart, and an object that overlaps two rows joins them into one. Only objects in the same layer or group and on the same artboard (the one holding the object's center, else the one it overlaps most) share a row, an object alone in its row stays as it is, and each new group goes where its frontmost member was in the stacking order; the new groups (top to bottom, or left to right) and the objects left alone stay selected. A run with no row of two or more objects makes no step → {groups: [id…], grouped (how many objects went into groups)}", + has_multi, + group_rows + ), cmd!( "addon.arrange.randomizeOpacity", "Randomize Opacity", @@ -407,11 +417,74 @@ fn group_overlapping(s: &mut Session, _: &Value) -> Result { roots.iter().filter_map(|id| Some((*id, (d.parent_of(*id), effects::preview::bounds_of(d, &[*id], true)?)))).collect(); let keyed: Vec<(Option, Rect)> = items.iter().map(|(_, k)| *k).collect(); let sets: Vec> = overlapping(&keyed).into_iter().map(|set| set.iter().filter_map(|i| Some(items.get(*i)?.0)).collect()).collect(); + group_each(s, "Group Overlapping Objects", &roots, sets) +} + +/// The rows of `items` (each a key and an extent `(start, end)` along the axis across the rows): the sets of +/// two or more (each in the order given) among items of the same key whose extents overlap, chains included. +/// Extents that only touch stay apart. Sorted by start, then by end, each item joins its key's open row when it +/// starts before that row ends, so the rows come out in order along the axis, and an extent with no length at +/// another's start stays apart from it whatever their order. +fn rows_of(items: &[(K, (f64, f64))]) -> Vec> { + let mut order: Vec = (0..items.len()).collect(); + order.sort_by(|a, b| items[*a].1.0.total_cmp(&items[*b].1.0).then(items[*a].1.1.total_cmp(&items[*b].1.1))); + let mut rows: Vec> = vec![]; + // Each key's open row: its index in `rows` and where it ends. + let mut open: HashMap = HashMap::new(); + for i in order { + let (key, (start, end)) = items[i]; + match open.get_mut(&key) { + Some((row, until)) if start < *until => { + if let Some(r) = rows.get_mut(*row) { + r.push(i); + } + *until = until.max(end); + } + _ => { + open.insert(key, (rows.len(), end)); + rows.push(vec![i]); + } + } + } + rows.retain(|r| r.len() > 1); + for r in &mut rows { + r.sort_unstable(); + } + rows +} + +fn group_rows(s: &mut Session, p: &Value) -> Result { + const C: &str = "addon.arrange.groupRows"; + let rows = choice(p, C, "direction", &["row", "column"])?.unwrap_or("row") == "row"; + let roots = selected_roots(s)?; + if roots.len() > MAX_OBJECTS { + return Err(bad(C, "too many objects selected (at most 20000)")); + } + let d = &s.doc()?.doc; + // Each object's row key (its parent and its artboard) and its extent across the rows. + type Keyed = ((Option, Option), (f64, f64)); + let items: Vec<(NodeId, Keyed)> = roots + .iter() + .filter_map(|id| { + let b = effects::preview::bounds_of(d, &[*id], true)?; + let extent = if rows { (b.y0, b.y1) } else { (b.x0, b.x1) }; + Some((*id, ((d.parent_of(*id), d.artboard_for_bounds(b)), extent))) + }) + .collect(); + let keyed: Vec<_> = items.iter().map(|(_, k)| *k).collect(); + let sets: Vec> = rows_of(&keyed).into_iter().map(|set| set.iter().filter_map(|i| Some(items.get(*i)?.0)).collect()).collect(); + group_each(s, if rows { "Group by Row" } else { "Group by Column" }, &roots, sets) +} + +/// Put each of `sets` (two or more of the selected top-level objects `roots`, each in stacking order) into a +/// new group of its own at its frontmost member's place, as undo step `label`, and select the new groups and +/// the objects of `roots` left alone. No step when `sets` is empty. +fn group_each(s: &mut Session, label: &str, roots: &[NodeId], sets: Vec>) -> Result { if sets.is_empty() { return Ok(json!({ "groups": [], "grouped": 0 })); } let grouped: std::collections::HashSet = sets.iter().flatten().copied().collect(); - let groups = s.edit("Group Overlapping Objects", |d, sel| { + let groups = s.edit(label, |d, sel| { // Every group at once: the members behind each front one go, then each front one is // replaced by its group (one pass over the tree each, however many groups). let (mut places, mut behind, mut groups) = (vec![], vec![], vec![]); diff --git a/crates/engine/src/cmd/addons/arrange/tests.rs b/crates/engine/src/cmd/addons/arrange/tests.rs index 498a927898..94e43a78d2 100644 --- a/crates/engine/src/cmd/addons/arrange/tests.rs +++ b/crates/engine/src/cmd/addons/arrange/tests.rs @@ -390,6 +390,7 @@ fn off_without_a_selection() { "addon.arrange.replace", "addon.arrange.size", "addon.arrange.groupOverlapping", + "addon.arrange.groupRows", "addon.arrange.randomizeOpacity", "addon.arrange.sort", ] { @@ -473,6 +474,159 @@ fn group_overlapping_is_off_with_one_object_and_scales_to_many() { assert!(sets.iter().all(|s| s.len() == 2 && s[1] == s[0] + 1)); } +fn layer_children(s: &Session) -> Vec { + s.doc().unwrap().doc.layers[0].children().unwrap().iter().map(|n| n.id).collect() +} + +#[test] +fn group_rows_groups_each_row_and_leaves_loners() { + let mut s = session(); + // Row one: a and b (y 0 to 12). c only touches it (from y 12), alone in its row. Row two: d and e. + let a = rect(&mut s, 0.0, 0.0, 10.0, 10.0); + let d = rect(&mut s, 0.0, 40.0, 10.0, 10.0); + let b = rect(&mut s, 20.0, 2.0, 10.0, 10.0); + let c = rect(&mut s, 40.0, 12.0, 10.0, 10.0); + let e = rect(&mut s, 20.0, 45.0, 10.0, 10.0); + select(&mut s, &[a, b, c, d, e]); + let n = steps(&s); + let r = s.execute("addon.arrange.groupRows", &json!({})).unwrap(); + assert_eq!(steps(&s), n + 1, "one undo step"); + assert_eq!(r["grouped"], json!(4)); + let groups = ids_of(&r["groups"]); + assert_eq!(groups.len(), 2); + assert_eq!(children(&s, groups[0]), [a, b], "the top row first, its members in stacking order"); + assert_eq!(children(&s, groups[1]), [d, e]); + // Each group where its frontmost member was: a d b c e → group(ab) at b, c, group(de) at e. + assert_eq!(layer_children(&s), [groups[0], c, groups[1]]); + let sel = &s.doc().unwrap().selection.objects; + assert!(sel.contains(&groups[0]) && sel.contains(&groups[1]) && sel.contains(&c) && sel.len() == 3, "{sel:?}"); + assert_eq!(s.doc().unwrap().history.undo.last().map(|step| step.label.as_str()), Some("Group by Row")); + s.execute("edit.undo", &json!({})).unwrap(); + assert_eq!(layer_children(&s), [a, d, b, c, e]); +} + +#[test] +fn group_rows_makes_columns_and_joins_rows_an_object_spans() { + let mut s = session(); + // Columns: a and b share x 0 to 15, c stands apart. + let a = rect(&mut s, 0.0, 0.0, 10.0, 10.0); + let b = rect(&mut s, 5.0, 50.0, 10.0, 10.0); + let c = rect(&mut s, 30.0, 0.0, 10.0, 10.0); + select(&mut s, &[a, b, c]); + let r = s.execute("addon.arrange.groupRows", &json!({"direction": "column"})).unwrap(); + let groups = ids_of(&r["groups"]); + assert_eq!(groups.len(), 1); + assert_eq!(children(&s, groups[0]), [a, b]); + assert_eq!(s.doc().unwrap().history.undo.last().map(|step| step.label.as_str()), Some("Group by Column")); + // By row, p and q lie in two rows until r, reaching from one to the other, joins them. + let mut s = session(); + let p = rect(&mut s, 0.0, 0.0, 10.0, 10.0); + let q = rect(&mut s, 50.0, 20.0, 10.0, 10.0); + select(&mut s, &[p, q]); + let n = steps(&s); + let r = s.execute("addon.arrange.groupRows", &json!({"direction": "row"})).unwrap(); + assert_eq!((r["grouped"].clone(), steps(&s)), (json!(0), n), "two rows of one: no groups, no step"); + let bridge = rect(&mut s, 100.0, 5.0, 10.0, 20.0); + select(&mut s, &[p, q, bridge]); + let r = s.execute("addon.arrange.groupRows", &json!({"direction": "row"})).unwrap(); + let groups = ids_of(&r["groups"]); + assert_eq!(groups.len(), 1); + assert_eq!(children(&s, groups[0]), [p, q, bridge]); +} + +#[test] +fn group_rows_keeps_layers_and_artboards_apart_and_measures_visual_bounds() { + let mut s = session(); + s.execute("artboard.new", &json!({"x": 500, "y": 0, "width": 200, "height": 300})).unwrap(); + let a = rect(&mut s, 0.0, 0.0, 20.0, 20.0); + // Touching a's bottom edge: a row of its own until strokes reach over the edge. + let below = rect(&mut s, 50.0, 20.0, 20.0, 20.0); + let far = rect(&mut s, 550.0, 0.0, 20.0, 20.0); + s.execute("layer.new", &json!({})).unwrap(); + let other = rect(&mut s, 100.0, 0.0, 20.0, 20.0); + select(&mut s, &[a, below, far, other]); + let n = steps(&s); + let r = s.execute("addon.arrange.groupRows", &json!({})).unwrap(); + assert_eq!((r["grouped"].clone(), steps(&s)), (json!(0), n), "another artboard, another layer, a touching edge: no groups"); + select(&mut s, &[a, below]); + s.execute("paint.setStroke", &json!({"color": "#000000"})).unwrap(); + s.execute("stroke.set", &json!({"weight": 4})).unwrap(); + select(&mut s, &[a, below, far, other]); + let r = s.execute("addon.arrange.groupRows", &json!({})).unwrap(); + let groups = ids_of(&r["groups"]); + assert_eq!(groups.len(), 1); + assert_eq!(children(&s, groups[0]), [a, below], "the strokes overlap"); + let doc = &s.doc().unwrap().doc; + assert_ne!(doc.parent_of(far), Some(groups[0]), "left on its own artboard"); + assert_ne!(doc.layer_of(other), doc.layer_of(a), "left in its own layer"); +} + +#[test] +fn group_rows_measures_clipping_groups_by_their_mask() { + let mut s = session(); + let a = rect(&mut s, 0.0, 0.0, 20.0, 20.0); + // A 200 tall object clipped to a 30 tall mask at y 100. + let clipped = rect(&mut s, 50.0, 0.0, 10.0, 200.0); + let mask = rect(&mut s, 40.0, 100.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 b = rect(&mut s, 100.0, 110.0, 10.0, 10.0); + select(&mut s, &[a, group, b]); + let r = s.execute("addon.arrange.groupRows", &json!({})).unwrap(); + let groups = ids_of(&r["groups"]); + assert_eq!(groups.len(), 1); + assert_eq!(children(&s, groups[0]), [group, b], "the mask's row, not the clipped art's"); +} + +#[test] +fn group_rows_is_off_with_one_object_skips_locked_ones_and_refuses_bad_params() { + let mut s = session(); + let a = rect(&mut s, 0.0, 0.0, 20.0, 20.0); + select(&mut s, &[a]); + assert!(!enabled(&s, "addon.arrange.groupRows")); + let b = rect(&mut s, 30.0, 0.0, 20.0, 20.0); + let c = rect(&mut s, 60.0, 0.0, 20.0, 20.0); + select(&mut s, &[a, b, c]); + assert!(enabled(&s, "addon.arrange.groupRows")); + refuses(&mut s, "addon.arrange.groupRows", &[json!({"direction": "diagonal"}), json!({"direction": 3}), json!({"direction": true})]); + select(&mut s, &[b]); + s.execute("object.lock", &json!({})).unwrap(); + s.execute("select.all", &json!({})).unwrap(); + let r = s.execute("addon.arrange.groupRows", &json!({})).unwrap(); + let groups = ids_of(&r["groups"]); + assert_eq!(groups.len(), 1); + assert_eq!(children(&s, groups[0]), [a, c], "the locked object stays out"); + assert_eq!(s.doc().unwrap().doc.parent_of(b), Some(s.doc().unwrap().doc.layers[0].id)); +} + +#[test] +fn group_rows_sorts_many_objects_into_rows() { + // 20000 objects in pairs up the page, the front one of each pair starting higher: each pair overlaps, + // neighboring pairs only touch. + let items: Vec<(u8, (f64, f64))> = (0..20_000) + .map(|i| { + let top = (10_000 - i / 2) as f64 * 10.0; + (0, (if i % 2 == 0 { top + 1.0 } else { top }, top + 10.0)) + }) + .collect(); + let rows = super::rows_of(&items); + assert_eq!(rows.len(), 10_000); + assert!(rows.iter().all(|r| r.len() == 2 && r[1] == r[0] + 1), "pairs, in the order given"); + assert_eq!(rows.first(), Some(&vec![19_998, 19_999]), "the top row first"); +} + +#[test] +fn group_rows_keeps_a_flat_object_on_a_row_edge_apart_in_either_order() { + // An extent with no height at the top edge of another only touches it, whichever is in front. + let flat_behind: Vec<(u8, (f64, f64))> = vec![(0, (0.0, 0.0)), (0, (0.0, 10.0))]; + let flat_in_front: Vec<(u8, (f64, f64))> = vec![(0, (0.0, 10.0)), (0, (0.0, 0.0))]; + assert!(super::rows_of(&flat_behind).is_empty()); + assert!(super::rows_of(&flat_in_front).is_empty(), "{:?}", super::rows_of(&flat_in_front)); + // Inside the row, it joins. + assert_eq!(super::rows_of(&[(0u8, (0.0, 10.0)), (0, (5.0, 5.0))]), vec![vec![0, 1]]); +} + fn opacity(s: &Session, id: NodeId) -> f32 { s.doc().unwrap().doc.node(id).unwrap().opacity } diff --git a/crates/engine/src/cmd/plugin_call/reviewed.rs b/crates/engine/src/cmd/plugin_call/reviewed.rs index 75074c6c3c..a0bd0d94b2 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.groupRows", "addon.arrange.offset", "addon.arrange.randomizeOpacity", "addon.arrange.replace", diff --git a/crates/engine/tests/command_sweep.rs b/crates/engine/tests/command_sweep.rs index c98cd9278e..bc72152b5c 100644 --- a/crates/engine/tests/command_sweep.rs +++ b/crates/engine/tests/command_sweep.rs @@ -1003,6 +1003,8 @@ fn structured_junk() { ("addon.arrange.size", json!({"width": 1e6, "height": 0.001, "reference": 8, "scaleStrokes": true})), ("addon.arrange.size", json!({"width": 0.001, "proportional": true, "reference": u64::MAX})), ("addon.arrange.groupOverlapping", json!({"ids": "x", "junk": f64::MAX})), + ("addon.arrange.groupRows", json!({"direction": "column"})), + ("addon.arrange.groupRows", json!({"direction": "diagonal", "junk": f64::MAX})), ("addon.arrange.randomizeOpacity", json!({"min": 0, "max": 100, "seed": u64::MAX})), ("addon.arrange.randomizeOpacity", json!({"min": f64::MAX, "max": -1e308, "seed": -1, "ids": [u64::MAX]})), ("addon.arrange.randomizeOpacity", json!({"min": 100, "max": 0, "seed": 1e308, "ids": []})), diff --git a/crates/ui-egui/src/addons/arrange.rs b/crates/ui-egui/src/addons/arrange.rs index ccd32bd7aa..44eb168b3b 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, Offset Objects, 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, Group by Row, 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. @@ -25,14 +25,16 @@ 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 ROWS: &str = "addon.arrange.groupRows"; const OPACITY: &str = "addon.arrange.randomizeOpacity"; const SORT: &str = "addon.arrange.sort"; /// Each dialog's command and heading. -const DIALOGS: [(&str, &str); 6] = [ +const DIALOGS: [(&str, &str); 7] = [ (GRID, "Arrange in Grid"), (OFFSET, "Offset Objects"), (REPLACE, "Replace with Top Object"), (SIZE, "Set Size of Each"), + (ROWS, "Group by Row"), (OPACITY, "Randomize Opacity"), (SORT, "Sort Objects"), ]; @@ -64,6 +66,7 @@ pub fn menu() -> Vec { c("Replace with Top Object…", REPLACE), c("Set Size of Each…", SIZE), cp("Group Overlapping Objects", "addon.arrange.groupOverlapping", json!({})), + c("Group by Row…", ROWS), c("Randomize Opacity…", OPACITY), c("Sort Objects…", SORT), Sep, @@ -75,6 +78,7 @@ 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 ROWS_SPEC: Spec = Spec { command: ROWS, params: group_rows_params, found: None }; static OPACITY_SPEC: Spec = Spec { command: OPACITY, params: opacity_params, found: None }; static SORT_SPEC: Spec = Spec { command: SORT, params: sort_params, found: None }; @@ -149,6 +153,11 @@ fn size_rows(lengths: LengthUnits) -> Vec { ] } +fn group_rows_rows() -> Vec { + let directions = [("row", "Rows"), ("column", "Columns")]; + vec![choice("direction", "Group By:", &directions, "row")] +} + fn opacity_rows() -> Vec { vec![percent("min", "Minimum:", 30.0), percent("max", "Maximum:", 100.0), seed()] } @@ -192,6 +201,10 @@ fn size_params(fields: &DialogFields) -> Value { Value::Object(params) } +fn group_rows_params(fields: &DialogFields) -> Value { + Value::Object(form::json_of(&group_rows_rows(), fields)) +} + fn opacity_params(fields: &DialogFields) -> Value { Value::Object(form::json_of(&opacity_rows(), fields)) } @@ -217,6 +230,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 })), + ROWS => (group_rows_rows(), json!({ "direction": "row" })), // 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 })), // The random order's seed (not shown): new whenever the document has changed, so each run @@ -245,6 +259,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))), + ROWS => super::dialogs::open(app, &ROWS_SPEC, fields, |fields| dialog(ROWS, group_rows_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)); dialog(OPACITY, opacity_rows()).ok_enabled(min <= max).values(Bind::bound(fields)) diff --git a/crates/ui-egui/src/addons/arrange/tests.rs b/crates/ui-egui/src/addons/arrange/tests.rs index 016391d661..41686a4bd1 100644 --- a/crates/ui-egui/src/addons/arrange/tests.rs +++ b/crates/ui-egui/src/addons/arrange/tests.rs @@ -169,6 +169,64 @@ fn stacking(panel: &Harness) -> Vec { panel.app().session.doc().unwrap().doc.layers[0].children().unwrap().iter().map(|n| n.id).collect() } +/// [`app`] with a third rectangle, c, in b's row and a's column; all three selected. +fn rows_app() -> (VectorcraftApp, NodeId, NodeId, NodeId) { + let (mut app, a, b) = app(); + let c = NodeId(app.run("shape.rectangle", json!({"x": 10, "y": 100, "width": 20, "height": 20})).unwrap()["id"].as_u64().unwrap()); + app.run("select.all", json!({})).unwrap(); + (app, a, b, c) +} + +fn parent(panel: &Harness, id: NodeId) -> Option { + panel.app().session.doc().unwrap().doc.parent_of(id) +} + +#[test] +fn real_group_by_row_keyboard_choice_reaches_the_preview_and_ok_groups_as_one_step() { + let (app, a, b, c) = rows_app(); + let n = steps(&app); + let mut panel = Harness::new(app, crate::tests::picks::dialogs); + click(&mut panel.app(), "Group by Row…"); + panel.frame(); + let layer = panel.app().session.doc().unwrap().doc.layers[0].id; + // Rows: b and c share one, a is alone in its own. + assert_eq!(parent(&panel, b), parent(&panel, c), "the preview groups b's row"); + assert_ne!(parent(&panel, b), Some(layer)); + assert_eq!(parent(&panel, a), Some(layer)); + panel.click_role("Group By", Role::COMBO_BOX); + panel.key(egui::Key::ArrowDown, egui::Modifiers::NONE); + panel.key(egui::Key::Enter, egui::Modifiers::NONE); + panel.frame(); + let id = host::dialog_id(&panel.app()); + assert_eq!(host::read(&panel.app(), id, |f| f.text("direction").map(str::to_owned)), Some("column".to_owned())); + // Columns: a and c share one, b is alone in its own. + assert_eq!(parent(&panel, a), parent(&panel, c), "the preview follows the keyboard choice"); + assert_ne!(parent(&panel, a), Some(layer)); + assert_eq!(parent(&panel, b), Some(layer)); + panel.click("OK"); + panel.frame(); + let group = parent(&panel, a).unwrap(); + assert_eq!(stacking(&panel), vec![b, group], "the group takes c's place, in front of b"); + assert_eq!(parent(&panel, c), Some(group)); + assert_eq!(steps(&panel.app()), n + 1, "one undo step"); + assert!(!panel.app().any_dialog_open()); +} + +#[test] +fn real_group_by_row_cancel_leaves_the_objects_ungrouped() { + let (app, a, b, c) = rows_app(); + let n = steps(&app); + let mut panel = Harness::new(app, crate::tests::picks::dialogs); + click(&mut panel.app(), "Group by Row…"); + panel.frame(); + assert_eq!(stacking(&panel).len(), 2, "the preview groups b and c"); + panel.click("Cancel"); + panel.frame(); + assert_eq!(stacking(&panel), vec![a, b, c]); + assert_eq!(steps(&panel.app()), n); + assert!(!panel.app().any_dialog_open()); +} + #[test] fn real_replace_edits_reach_the_preview_and_confirmed_copies() { let (app, a, b) = app(); diff --git a/docs/mcp.md b/docs/mcp.md index d984e7b92d..1582662613 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -17582,6 +17582,7 @@ as `object.setBounds` measures them (Use Preview Bounds), except Arrange in Grid | `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). | | `addon.arrange.groupOverlapping` | none | Groups the selected objects (at most 20000) wherever their visual bounds overlap or touch, chains included: when A overlaps B and B overlaps C, all three go in one group. Only objects in the same layer or group are grouped together; objects that overlap nothing stay as they are. Each new group goes where its frontmost member was in the stacking order, and the groups and the objects left alone stay selected; with nothing overlapping it makes no step. Needs two objects or more. → `{groups: [id…], grouped}` (how many objects went into groups) | +| `addon.arrange.groupRows` | `direction`: `row` (vertical extents), `column` (horizontal extents) (`row`) | Groups the selected objects (at most 20000) into one group for each row (column): an object joins a row when its visual bounds, a clipping group's by its mask, overlap the row's extent from top to bottom (left to right). Extents that only touch stay apart, and an object that overlaps two rows joins them into one. Only objects in the same layer or group and on the same artboard (the one holding the object's center, else the one it overlaps most) share a row; an object alone in its row stays as it is. Each new group goes where its frontmost member was in the stacking order, and the groups (top to bottom, or left to right) and the objects left alone stay selected; with no row of two objects or more it makes no step. Needs two objects or more. → `{groups: [id…], grouped}` (how many objects went into groups) | | `addon.arrange.randomizeOpacity` | `min`, `max` % 0…100 (30, 100; `min` not more than `max`); `seed` whole number (0); `ids` (the selection) | Gives each selected object its own opacity (the object opacity the Transparency panel sets), picked at random and evenly from `min` to `max`; the same seed, objects and range give the same opacities. Groups take one opacity of their own; the objects inside keep theirs. A run that changes no opacity, such as `min` and `max` both at the opacity every object has, records no undo step. → `{count}` | | `addon.arrange.sort` | `by`, `apply`: `width`, `height`, `area` (width × height), `x` (left edge), `y` (top edge), `opacity` (%), `stacking` (stacking order from the back) (`area`, `stacking`); `order`: `ascending` (small to large), `descending` (large to small), `random` (`ascending`); `distribute` (false); `seed` whole number (0, for `random`); `scaleStrokes`; `ids` (the selection) | Sorts the selected objects (at most 20000) by `by` and gives them the values of `apply` in that order: the first gets the smallest value. Without `distribute` the objects trade the values they have; with it the values step evenly from the smallest to the largest. A width, height or area changes about each object's centre (an area in proportion), a place moves the top-left corner. Stacking order always trades places, and only among objects in the same layer or group. Needs two objects or more. → `{count}` | @@ -17591,11 +17592,13 @@ and fails with nothing selected. Arrange in Grid…, Replace with Top Object…, (`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. +and Reverse Order. Group by Row… opens one too (`ui.menuDialog {command: "addon.arrange.groupRows"}`), with Group By +(Rows or Columns). ```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.groupRows","params":{"direction":"row"}}} {"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 ee49042298..ef8382bb36 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -3162,6 +3162,10 @@ A VectorCraft addition, not a feature of the reference app, so no area score mov 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. +## Arrange Tools add-on: Group by Row (2026-11-29) + +A VectorCraft addition, so no area score moves. Object › Plug-ins › Arrange Tools › Group by Row… puts the top-level selected objects (at most 20000) into one group for each row: an object joins a row when its visual bounds, a clipping group's by its mask, overlap the row from top to bottom. Group By Columns does the same from left to right. Extents that only touch stay apart, an object that overlaps two rows joins them, and only objects in the same layer or group and on the same artboard share a row; an object alone in its row stays as it is. Each new group takes its frontmost member's place in the stacking order, and the groups and the objects left alone stay selected. One undo step; no step when no row holds two objects. Tests: `group_rows_*` in `cmd::addons::arrange::tests` in `vectorcraft-engine` (rows and loners, columns, an object spanning two rows, layers and artboards kept apart, strokes and clipping groups, locked objects left out, bad params, 20000 objects), `real_group_by_row_*` 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 ac20453f86..795af5c60c 100644 --- a/docs/ui-parity.md +++ b/docs/ui-parity.md @@ -568,6 +568,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 › 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 | +| Arrange Tools add-on (VectorCraft addition): Object › Plug-ins › Arrange Tools › Group by Row… groups the selected objects whose visual bounds overlap from top to bottom into one group for each row, or with Group By Columns from left to right (within one layer or group and one artboard), each group at its frontmost member's stacking place; Preview; one undo step | done | `addon.arrange.groupRows`, `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 |