From 352b4c3f675e1784fc278ed503775ba5add057de Mon Sep 17 00:00:00 2001 From: "Ayberk A." <105879357+AyberkA0@users.noreply.github.com> Date: Mon, 23 Nov 2026 12:08:33 +0300 Subject: [PATCH 1/2] feat(engine): Match Size and Space Evenly in Align (#566) Five Align commands: align.match_width, align.match_height and align.match_size make each selected object (a raw drawing as one) the largest one's width and/or height, or the stage's with to_stage, scaled about its own top-left corner; align.space_h and align.space_v make the gaps between three or more objects equal, the outer two unmoved. The Align panel has buttons for them (five original icons on Lucide's grid), the stage's Align menu lists them, and Edit Multiple Frames leaves them off as it does Distribute. Co-Authored-By: Claude Opus 5.5 --- ATTRIBUTION.md | 2 +- assets/icons/anicraft-match-height.svg | 7 +++ assets/icons/anicraft-match-size.svg | 6 +++ assets/icons/anicraft-match-width.svg | 7 +++ assets/icons/anicraft-space-h.svg | 7 +++ assets/icons/anicraft-space-v.svg | 7 +++ crates/engine/src/cmds_modify.rs | 62 ++++++++++++++++++++++++++ crates/engine/src/tests.rs | 46 +++++++++++++++++++ docs/guide/drawing.md | 5 ++- docs/guide/reference/commands.md | 12 ++++- docs/parity.md | 4 +- docs/roadmap.md | 2 +- src/icons.rs | 22 ++++++++- src/onion.rs | 2 +- src/panels.rs | 10 +++++ src/stage.rs | 2 +- 16 files changed, 194 insertions(+), 9 deletions(-) create mode 100644 assets/icons/anicraft-match-height.svg create mode 100644 assets/icons/anicraft-match-size.svg create mode 100644 assets/icons/anicraft-match-width.svg create mode 100644 assets/icons/anicraft-space-h.svg create mode 100644 assets/icons/anicraft-space-v.svg diff --git a/ATTRIBUTION.md b/ATTRIBUTION.md index 6388fc40..026c2bc0 100644 --- a/ATTRIBUTION.md +++ b/ATTRIBUTION.md @@ -19,7 +19,7 @@ shaders or SDK code). | Hack Regular (via `epaint_default_fonts`) | UI monospace font | Source Foundry Authors; Bitstream (Vera) | | MIT + Bitstream Vera licence, [`licenses/fonts/LICENSE-Hack.txt`](licenses/fonts/LICENSE-Hack.txt) | | Noto Emoji (via `epaint_default_fonts`) | Symbol fallback | Google | | SIL OFL 1.1, [`licenses/fonts/OFL-1.1-NotoEmoji.txt`](licenses/fonts/OFL-1.1-NotoEmoji.txt) | | emoji-icon-font (via `epaint_default_fonts`) | Symbol fallback | John Slegers | | MIT, [`licenses/fonts/LICENSE-emoji-icon-font.txt`](licenses/fonts/LICENSE-emoji-icon-font.txt) | -| `assets/icons/anicraft-*.svg` (36 files: align, distribute, layer, the parenting view, mask and masked layer, width tool, gradient transform tool, camera, brush, paint brush, eraser, eyedropper, muted sound, magnet, bone, bind, asset warp, edit multiple frames, insert frame, keyframe and blank keyframe, clip to the stage, and seven panel icons: properties, swatches, library, explorer, history, output, actions) | Align panel, layer-type, the timeline's Parenting View toggle, Width tool, Gradient Transform tool, Camera, Brush, Paint Brush, Eraser, Eyedropper, Bone, Bind and Asset Warp tool icons, the timeline's mute toggle, Snap to Objects, Edit Multiple Frames, the timeline's Insert Frame / Keyframe / Blank Keyframe buttons, Clip Content Outside the Stage, panel icons in docks collapsed to icons (ADR 0087) | AniCraft contributors | Original work, drawn on Lucide's 24-unit grid and stroke style (the muted sound keeps the speaker of Lucide's `volume-2`, ISC, crossed out) | MIT OR Apache-2.0 | +| `assets/icons/anicraft-*.svg` (41 files: align, distribute, match size, space evenly, layer, the parenting view, mask and masked layer, width tool, gradient transform tool, camera, brush, paint brush, eraser, eyedropper, muted sound, magnet, bone, bind, asset warp, edit multiple frames, insert frame, keyframe and blank keyframe, clip to the stage, and seven panel icons: properties, swatches, library, explorer, history, output, actions) | Align panel, layer-type, the timeline's Parenting View toggle, Width tool, Gradient Transform tool, Camera, Brush, Paint Brush, Eraser, Eyedropper, Bone, Bind and Asset Warp tool icons, the timeline's mute toggle, Snap to Objects, Edit Multiple Frames, the timeline's Insert Frame / Keyframe / Blank Keyframe buttons, Clip Content Outside the Stage, panel icons in docks collapsed to icons (ADR 0087) | AniCraft contributors | Original work, drawn on Lucide's 24-unit grid and stroke style (the muted sound keeps the speaker of Lucide's `volume-2`, ISC, crossed out) | MIT OR Apache-2.0 | | `crates/svg/fixtures/clips-masks-text.svg` | SVG import test drawing (clip paths, a mask, text) | AniCraft contributors | Original work | MIT OR Apache-2.0 | | `crates/svg/fixtures/soft-masks-text-paths.svg` | SVG import test drawing (an alpha and a luminance mask, text on a path) | AniCraft contributors | Original work | MIT OR Apache-2.0 | | `assets/icons/*.svg` except `anicraft-*` (37 files: tools, transport, layer toggles, folders, guide, image, text, sound, chevrons, plus, trash, copy, ellipsis) | UI icons, stroked by `src/icons.rs` | Lucide Icons and Contributors (some derived from Feather by Cole Bemis) | (`icons/.svg`), copied unchanged from the PhotoCraft sibling project's set (`volume-2.svg` from Lucide 0.512.0; `plus.svg`, `trash.svg`, `copy.svg` and `ellipsis.svg` from Lucide's `main` branch, 2026-11) | ISC (Lucide) and MIT (Feather), [`licenses/icons/LICENSE-lucide.txt`](licenses/icons/LICENSE-lucide.txt) | diff --git a/assets/icons/anicraft-match-height.svg b/assets/icons/anicraft-match-height.svg new file mode 100644 index 00000000..8dc6d788 --- /dev/null +++ b/assets/icons/anicraft-match-height.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/assets/icons/anicraft-match-size.svg b/assets/icons/anicraft-match-size.svg new file mode 100644 index 00000000..65597964 --- /dev/null +++ b/assets/icons/anicraft-match-size.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/assets/icons/anicraft-match-width.svg b/assets/icons/anicraft-match-width.svg new file mode 100644 index 00000000..faaf0f52 --- /dev/null +++ b/assets/icons/anicraft-match-width.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/assets/icons/anicraft-space-h.svg b/assets/icons/anicraft-space-h.svg new file mode 100644 index 00000000..4f88b915 --- /dev/null +++ b/assets/icons/anicraft-space-h.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/assets/icons/anicraft-space-v.svg b/assets/icons/anicraft-space-v.svg new file mode 100644 index 00000000..05b2aeed --- /dev/null +++ b/assets/icons/anicraft-space-v.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/crates/engine/src/cmds_modify.rs b/crates/engine/src/cmds_modify.rs index 9bf98816..fbb24b06 100644 --- a/crates/engine/src/cmds_modify.rs +++ b/crates/engine/src/cmds_modify.rs @@ -55,6 +55,11 @@ pub fn specs() -> Vec { c("align.bottom", "Bottom", "Modify/Align", Some("Ctrl+Alt+6"), "{to_stage?}", true, |s, p| align(s, p, Edge::Bottom)), c("align.distribute_h", "Distribute Horizontal Centers", "Modify/Align", None, "{}", true, |s, _| distribute(s, true)), c("align.distribute_v", "Distribute Vertical Centers", "Modify/Align", None, "{}", true, |s, _| distribute(s, false)), + c("align.match_width", "Match Width", "Modify/Align", None, "{to_stage?} makes each selected object as wide as the widest (to_stage: as the stage), keeping its left edge where it is", true, |s, p| match_size(s, p, true, false)), + c("align.match_height", "Match Height", "Modify/Align", None, "{to_stage?} makes each selected object as tall as the tallest (to_stage: as the stage), keeping its top edge where it is", true, |s, p| match_size(s, p, false, true)), + c("align.match_size", "Match Width and Height", "Modify/Align", None, "{to_stage?} makes each selected object as wide as the widest and as tall as the tallest (to_stage: the stage's size), keeping its top-left corner where it is", true, |s, p| match_size(s, p, true, true)), + c("align.space_h", "Space Evenly Horizontally", "Modify/Align", None, "{} moves the selected objects (three or more) so the gaps between them across are equal; the leftmost and rightmost stay where they are", true, |s, _| space(s, true)), + c("align.space_v", "Space Evenly Vertically", "Modify/Align", None, "{} moves the selected objects (three or more) so the gaps between them down are equal; the topmost and bottommost stay where they are", true, |s, _| space(s, false)), ] } @@ -642,6 +647,63 @@ fn align(s: &mut Session, p: &Value, edge: Edge) -> Result { Ok(json!({"moved": n, "to_stage": to_stage})) } +/// Match Size (#566): each selected object (a raw drawing as one, as align takes them) scaled +/// about its top-left corner to the largest one's width and/or height, or the stage's. +/// Objects with no extent along a matched side (a straight line along the other) keep it. +fn match_size(s: &mut Session, p: &Value, width: bool, height: bool) -> Result { + let units = selected_units(s); + if units.is_empty() { + return Err(EngineError::State("nothing is selected".into())); + } + let to_stage = opt_bool(p, "to_stage")?.unwrap_or(false); + let (w, h) = if to_stage { + (s.doc.stage.width as f32, s.doc.stage.height as f32) + } else { + units.iter().fold((0.0f32, 0.0f32), |(w, h), (_, b)| (w.max(b.width()), h.max(b.height()))) + }; + const MIN: f32 = 1e-3; + let mut by: std::collections::HashMap = std::collections::HashMap::new(); + for (items, b) in units { + let sx = if width && b.width() > MIN { w / b.width() } else { 1.0 }; + let sy = if height && b.height() > MIN { h / b.height() } else { 1.0 }; + let m = Affine::translate(b.min.x, b.min.y).mul(&Affine::scale(sx, sy)).mul(&Affine::translate(-b.min.x, -b.min.y)); + by.extend(items.into_iter().map(|i| (i, m))); + } + s.each_layer(true, |s| { + let layer = s.layer; + Ok(json!({"transformed": apply_each(s, |id| by.get(&(layer, id)).copied().unwrap_or(Affine::IDENTITY))?})) + }) +} + +/// Space Evenly (#566): the objects between the first and the last (by their left or top +/// edges) move so every gap between neighbours is the same; the outer two stay put. +fn space(s: &mut Session, horizontal: bool) -> Result { + let mut units = selected_units(s); + if units.len() < 3 { + return Err(EngineError::State("select at least three elements to space evenly".into())); + } + // Where an object starts along the axis, and how long it is. + let lo = |b: &Rect| if horizontal { (b.min.x, b.width()) } else { (b.min.y, b.height()) }; + units.sort_by(|a, b| lo(&a.1).0.total_cmp(&lo(&b.1).0)); + let (Some(first), Some(last)) = (units.first(), units.last()) else { return Ok(json!({"moved": 0})) }; + let (start, _) = lo(&first.1); + let (last_at, last_len) = lo(&last.1); + let end = last_at + last_len; + let total: f32 = units.iter().map(|u| lo(&u.1).1).sum(); + let gap = (end - start - total) / (units.len() - 1) as f32; + let mut at = start; + let mut moves: Vec<(Item, Vec2)> = Vec::new(); + for (items, b) in &units { + let (l, n) = lo(b); + let d = at - l; + let d = if horizontal { Vec2::new(d, 0.0) } else { Vec2::new(0.0, d) }; + moves.extend(items.iter().map(|id| (*id, d))); + at += n + gap; + } + let n = translate_each(s, &moves)?; + Ok(json!({"moved": n})) +} + fn distribute(s: &mut Session, horizontal: bool) -> Result { let mut units = selected_units(s); if units.len() < 3 { diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 342e6942..ed2a8d92 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -299,6 +299,52 @@ fn align_and_distribute() { assert!((s.selection_bounds().max.x - s.doc.stage.width as f32).abs() < 1e-3); } +/// #566: Match Size makes every selected object the largest one's size (or the stage's), +/// each keeping its top-left corner; Space Evenly makes the gaps between neighbours equal, +/// leaving the outer two where they are. +#[test] +fn match_size_and_space_evenly() { + let mut s = Session::default(); + for (x, y, w, h) in [(10, 50, 20, 40), (200, 10, 60, 10), (90, 120, 30, 30)] { + run(&mut s, "draw.rect", json!({"x": x, "y": y, "w": w, "h": h, "stroke": null})); + } + run(&mut s, "edit.select_all", json!({})); + let boxes = |s: &Session| s.selection.ids().map(|id| s.element_bounds(id)).collect::>(); + let before = boxes(&s); + run(&mut s, "align.match_width", json!({})); + let after = boxes(&s); + let widest = before.iter().map(|b| b.width()).fold(0.0, f32::max); + for (a, b) in after.iter().zip(&before) { + assert!((a.width() - widest).abs() < 1e-3 && (a.height() - b.height()).abs() < 1e-3, "as wide as the widest, as tall as before: {a:?}"); + assert!((a.min - b.min).length() < 1e-3, "the left and top edges stay"); + } + run(&mut s, "align.match_size", json!({"to_stage": true})); + let (w, h) = (s.doc.stage.width as f32, s.doc.stage.height as f32); + assert!(boxes(&s).iter().all(|b| (b.width() - w).abs() < 1e-2 && (b.height() - h).abs() < 1e-2), "the stage's size"); + run(&mut s, "edit.undo", json!({})); + run(&mut s, "edit.undo", json!({})); + + // Space evenly: equal gaps between neighbours across, the outer two unmoved. + run(&mut s, "align.space_h", json!({})); + let mut b = boxes(&s); + b.sort_by(|p, q| p.min.x.total_cmp(&q.min.x)); + let gaps: Vec = b.windows(2).map(|w| w[1].min.x - w[0].max.x).collect(); + assert!((gaps[0] - gaps[1]).abs() < 1e-3, "{gaps:?}"); + let mut was = before.clone(); + was.sort_by(|p, q| p.min.x.total_cmp(&q.min.x)); + assert!((b[0].min.x - was[0].min.x).abs() < 1e-3 && (b[2].max.x - was[2].max.x).abs() < 1e-3, "the outer two stay"); + run(&mut s, "align.space_v", json!({})); + let mut b = boxes(&s); + b.sort_by(|p, q| p.min.y.total_cmp(&q.min.y)); + let gaps: Vec = b.windows(2).map(|w| w[1].min.y - w[0].max.y).collect(); + assert!((gaps[0] - gaps[1]).abs() < 1e-3, "{gaps:?}"); + // Two objects have no gap between others to share. + run(&mut s, "edit.deselect", json!({})); + let ids: Vec = s.visible_elements().iter().take(2).map(|e| e.id.0).collect(); + run(&mut s, "element.select", json!({"ids": ids})); + assert!(s.execute("align.space_h", &json!({})).is_err()); +} + /// #301, #297: a raw rectangle (one fill and one stroke per side, ADR 0042) aligns, distributes, /// turns and scales as one shape, so its outline stays on its fill. #[test] diff --git a/docs/guide/drawing.md b/docs/guide/drawing.md index 80147e21..a07ffe8c 100644 --- a/docs/guide/drawing.md +++ b/docs/guide/drawing.md @@ -534,7 +534,10 @@ Use the **Align** panel in the right-hand dock, or **Modify › Align**: **Left* (**Ctrl+Alt+1**), **Horizontal Center** (**Ctrl+Alt+2**), **Right** (**Ctrl+Alt+3**), **Top** (**Ctrl+Alt+4**), **Vertical Center** (**Ctrl+Alt+5**) and **Bottom** (**Ctrl+Alt+6**). **Distribute Horizontal Centers** and **Distribute Vertical Centers** space three or more -things evenly. Tick **To stage** in the Align panel (or press **Ctrl+Alt+8**) to align to the +things evenly by their centres; **Space Evenly Horizontally** and **Space Evenly Vertically** +make the gaps between them equal instead, leaving the outer two where they are. **Match +Width**, **Match Height** and **Match Width and Height** make every selected thing the size of +the largest one (with **To stage**, the stage's size), each keeping its top-left corner. Tick **To stage** in the Align panel (or press **Ctrl+Alt+8**) to align to the stage instead of the selection. A single shape always aligns to the stage. Align works across layers. diff --git a/docs/guide/reference/commands.md b/docs/guide/reference/commands.md index 3068d543..1b5c8657 100644 --- a/docs/guide/reference/commands.md +++ b/docs/guide/reference/commands.md @@ -1,6 +1,6 @@ # Command reference -Everything you can do in AniCraft is a command: the menus, the shortcuts, the command palette (**Ctrl+K**, macOS **⌘K**), `anicraft-cli` and AI assistants over MCP all run the same 399 commands, listed here by menu. The id is what scripts and [working headless](../working-headless.md) use; the parameters are what a command takes as JSON. Commands that change the document are one undo step each. Your own shortcuts (**Help › Keyboard Shortcuts**) replace the defaults shown here; see the [shortcut reference](shortcuts.md). +Everything you can do in AniCraft is a command: the menus, the shortcuts, the command palette (**Ctrl+K**, macOS **⌘K**), `anicraft-cli` and AI assistants over MCP all run the same 404 commands, listed here by menu. The id is what scripts and [working headless](../working-headless.md) use; the parameters are what a command takes as JSON. Commands that change the document are one undo step each. Your own shortcuts (**Help › Keyboard Shortcuts**) replace the defaults shown here; see the [shortcut reference](shortcuts.md). This page is generated from the command registry, so it always matches the version of AniCraft it came with. @@ -252,6 +252,16 @@ This page is generated from the command registry, so it always matches the versi Parameters: `{}` - **Distribute Vertical Centers** `align.distribute_v` · Modify › Align · changes the document Parameters: `{}` +- **Match Width** `align.match_width` · Modify › Align · changes the document + Parameters: `{to_stage?} makes each selected object as wide as the widest (to_stage: as the stage), keeping its left edge where it is` +- **Match Height** `align.match_height` · Modify › Align · changes the document + Parameters: `{to_stage?} makes each selected object as tall as the tallest (to_stage: as the stage), keeping its top edge where it is` +- **Match Width and Height** `align.match_size` · Modify › Align · changes the document + Parameters: `{to_stage?} makes each selected object as wide as the widest and as tall as the tallest (to_stage: the stage's size), keeping its top-left corner where it is` +- **Space Evenly Horizontally** `align.space_h` · Modify › Align · changes the document + Parameters: `{} moves the selected objects (three or more) so the gaps between them across are equal; the leftmost and rightmost stay where they are` +- **Space Evenly Vertically** `align.space_v` · Modify › Align · changes the document + Parameters: `{} moves the selected objects (three or more) so the gaps between them down are equal; the topmost and bottommost stay where they are` - **Bind to Data…** `data.bind` · Modify › Data · changes the document Parameters: `{property: x|y|scale_x|scale_y|rotation|alpha|frame (x, y pixels; scales and alpha percent; rotation degrees; frame: the 0-based frame of its symbol a graphic instance shows), table (id or name), column, element? (a symbol instance's id; default the selected one), start? (the span's first frame, 0-based; default the first frame the instance is on), frames? (the span's length; default one frame per row, or with a key column the frames the instance is on), from?, to? (the keys the first and last frame show; default the table's first and last; to before from plays it backwards), interpolation?: linear|step, scale?, offset? (value = column × scale + offset)} one binding per property of an instance; before the span it shows the first frame's value, after it the last's → {element, property, table, column, start, frames, value}` - **Remove Data Bindings** `data.unbind` · Modify › Data · changes the document diff --git a/docs/parity.md b/docs/parity.md index 3c898ae4..065dc6c0 100644 --- a/docs/parity.md +++ b/docs/parity.md @@ -68,7 +68,7 @@ not this table, says what matters most. | Timeline panel | **done** | See Timeline. | | Library panel | **done** | See Symbols and Library. | | Colour and Swatches panels | **done** | See Colour. | -| Align panel | **done** | Align, distribute, To Stage. Missing: Match Size and Space (P-017). | +| Align panel | **done** | Align, distribute, space evenly, match size, To Stage. | | Transform and Info panels | **partial** | Position, scale, rotation, skew and the transformation point are rows in Properties; there is no separate Transform panel with Duplicate and Transform, and no Info panel with the pointer's colour and position (P-050). | | History panel | **done** | With saved commands ([ADR 0097](adr/0097-command-macros.md)). | | Scene panel | **done** | A scene menu on the edit bar and Modify › Scene ([ADR 0011](adr/0011-scenes.md)). | @@ -143,7 +143,7 @@ not this table, says what matters most. | Combine Objects: Union, Intersect, Punch, Crop | **done** | [ADR 0073](adr/0073-groups-combine-objects-and-selection-modifiers.md). One layer at a time. | | Arrange (front, back, forward, backward) | **done** | | | Align, distribute | **done** | | -| Match Size, Space evenly | **missing** | P-017. | +| Match Size, Space evenly | **done** | `align.match_width`, `align.match_height`, `align.match_size`, `align.space_h`, `align.space_v` (#566). | | Transform: rotate 90°, flip, remove transform, scale and rotate by numbers | **done** | | | Envelope | **done** | [ADR 0080](adr/0080-drawing-parity-leftovers.md). Shapes and drawing objects only. | | Distort | **missing** | P-020. | diff --git a/docs/roadmap.md b/docs/roadmap.md index 427deb4a..30bcef14 100644 --- a/docs/roadmap.md +++ b/docs/roadmap.md @@ -65,7 +65,7 @@ the changelog. | Id | Goal | Parity area | Size | Needs | Lane | |---|---|---|---|---|---| -| P-017 | Selecting as in the reference app: a marquee takes instances, groups and objects it touches ([#522](https://github.com/storytold/anicraft/issues/522)); Hide Edges ([#298](https://github.com/storytold/anicraft/issues/298)); a first-use hint that a fill and its outline are separate, with double-click selecting both ([#484](https://github.com/storytold/anicraft/issues/484), [#485](https://github.com/storytold/anicraft/issues/485), [#343](https://github.com/storytold/anicraft/issues/343)); Match Size and Space in Align | Tools, drawing model | S each | | stage | +| P-017 | Selecting as in the reference app: a marquee takes instances, groups and objects it touches ([#522](https://github.com/storytold/anicraft/issues/522)); Hide Edges ([#298](https://github.com/storytold/anicraft/issues/298)); a first-use hint that a fill and its outline are separate, with double-click selecting both ([#484](https://github.com/storytold/anicraft/issues/484), [#485](https://github.com/storytold/anicraft/issues/485), [#343](https://github.com/storytold/anicraft/issues/343)) | Tools, drawing model | S each | | stage | | P-018 | Lasso, Polygon and Magic Wand tools ([#515](https://github.com/storytold/anicraft/issues/515)) | Tools | M | | stage | | P-019 | Text is typed in its block on the stage, in its real font and alignment ([#303](https://github.com/storytold/anicraft/issues/303)) | Text | L | P-008 | text | | P-020 | Modify › Shape: Smooth, Straighten, Advanced Smooth and Optimize ([#510](https://github.com/storytold/anicraft/issues/510)); Distort; oval angles and primitive shapes | Drawing model | M | | geom | diff --git a/src/icons.rs b/src/icons.rs index 2a843ef1..998b716f 100644 --- a/src/icons.rs +++ b/src/icons.rs @@ -53,6 +53,11 @@ pub enum Icon { AlignBottom, DistributeH, DistributeV, + MatchWidth, + MatchHeight, + MatchSize, + SpaceH, + SpaceV, Mask, Masked, Folder, @@ -93,7 +98,7 @@ pub enum Icon { impl Icon { #[cfg(test)] - pub const ALL: [Icon; 75] = [ + pub const ALL: [Icon; 80] = [ Icon::PanelProperties, Icon::PanelSwatches, Icon::PanelLibrary, @@ -138,6 +143,11 @@ impl Icon { Icon::AlignBottom, Icon::DistributeH, Icon::DistributeV, + Icon::MatchWidth, + Icon::MatchHeight, + Icon::MatchSize, + Icon::SpaceH, + Icon::SpaceV, Icon::Select, Icon::Subselect, Icon::Transform, @@ -239,6 +249,11 @@ impl Icon { Icon::AlignBottom => ("anicraft-align-bottom", false), Icon::DistributeH => ("anicraft-distribute-h", false), Icon::DistributeV => ("anicraft-distribute-v", false), + Icon::MatchWidth => ("anicraft-match-width", false), + Icon::MatchHeight => ("anicraft-match-height", false), + Icon::MatchSize => ("anicraft-match-size", false), + Icon::SpaceH => ("anicraft-space-h", false), + Icon::SpaceV => ("anicraft-space-v", false), // Layer types: a stencil (mask) and the area inside it (masked). Icon::Mask => ("anicraft-mask", false), Icon::Masked => ("anicraft-masked", false), @@ -332,6 +347,11 @@ static FILES: &[(&str, &str)] = &[ ("anicraft-align-bottom", include_str!("../assets/icons/anicraft-align-bottom.svg")), ("anicraft-distribute-h", include_str!("../assets/icons/anicraft-distribute-h.svg")), ("anicraft-distribute-v", include_str!("../assets/icons/anicraft-distribute-v.svg")), + ("anicraft-match-width", include_str!("../assets/icons/anicraft-match-width.svg")), + ("anicraft-match-height", include_str!("../assets/icons/anicraft-match-height.svg")), + ("anicraft-match-size", include_str!("../assets/icons/anicraft-match-size.svg")), + ("anicraft-space-h", include_str!("../assets/icons/anicraft-space-h.svg")), + ("anicraft-space-v", include_str!("../assets/icons/anicraft-space-v.svg")), ("anicraft-mask", include_str!("../assets/icons/anicraft-mask.svg")), ("anicraft-width", include_str!("../assets/icons/anicraft-width.svg")), ("anicraft-gradient-transform", include_str!("../assets/icons/anicraft-gradient-transform.svg")), diff --git a/src/onion.rs b/src/onion.rs index 02a5904b..f301c490 100644 --- a/src/onion.rs +++ b/src/onion.rs @@ -483,7 +483,7 @@ pub fn enabled(app: &App, id: &str) -> Option { let sel = !app.onion_ui.sel.is_empty(); match id { "edit.delete" | "edit.cut" | "edit.copy" => Some(sel), - "edit.duplicate" | "modify.convert_to_symbol" | "modify.break_apart" | "arrange.bring_to_front" | "arrange.send_to_back" | "align.distribute_h" | "align.distribute_v" => Some(false), + "edit.duplicate" | "modify.convert_to_symbol" | "modify.break_apart" | "arrange.bring_to_front" | "arrange.send_to_back" | "align.distribute_h" | "align.distribute_v" | "align.space_h" | "align.space_v" | "align.match_width" | "align.match_height" | "align.match_size" => Some(false), _ => None, } } diff --git a/src/panels.rs b/src/panels.rs index 712ff95d..6fcd6d23 100644 --- a/src/panels.rs +++ b/src/panels.rs @@ -696,6 +696,16 @@ pub(crate) fn align_panel(app: &mut App, ui: &mut egui::Ui) { ui.spacing_mut().item_spacing.x = 2.0; button(app, ui, Icon::DistributeH, "align.distribute_h"); button(app, ui, Icon::DistributeV, "align.distribute_v"); + ui.add_space(10.0); + button(app, ui, Icon::SpaceH, "align.space_h"); + button(app, ui, Icon::SpaceV, "align.space_v"); + }); + // Match Size (#566): to the largest selected object, or with To stage to the stage. + ui.horizontal_wrapped(|ui| { + ui.spacing_mut().item_spacing.x = 2.0; + button(app, ui, Icon::MatchWidth, "align.match_width"); + button(app, ui, Icon::MatchHeight, "align.match_height"); + button(app, ui, Icon::MatchSize, "align.match_size"); ui.add_space(12.0); crate::theme::checkbox(ui, &mut app.align_to_stage, text(Type::Body, tr!("To stage"))).on_hover_text(tr!("Align to the stage instead of the selection's bounds (a single shape always aligns to the stage)")); }); diff --git a/src/stage.rs b/src/stage.rs index 704c8ca8..d1835772 100644 --- a/src/stage.rs +++ b/src/stage.rs @@ -954,7 +954,7 @@ pub fn show(app: &mut App, ui: &mut egui::Ui) { } }); ui.menu_button(tr!("Align"), |ui| { - for id in ["align.left", "align.hcenter", "align.right", "align.top", "align.vcenter", "align.bottom", "align.distribute_h", "align.distribute_v"] { + for id in ["align.left", "align.hcenter", "align.right", "align.top", "align.vcenter", "align.bottom", "align.distribute_h", "align.distribute_v", "align.space_h", "align.space_v", "align.match_width", "align.match_height", "align.match_size"] { crate::menus::cmd_item(app, ui, id); } }); From 9ca07dc5659bd5d55a04f68f8580f59f6218aaf7 Mon Sep 17 00:00:00 2001 From: "Ayberk A." <105879357+AyberkA0@users.noreply.github.com> Date: Mon, 23 Nov 2026 12:54:35 +0300 Subject: [PATCH 2/2] fix(engine): Space Evenly keeps order and the outer objects; clearer Match docs Review: an object much longer than the rest could make the gap so negative that Space Evenly passed one object over the next; that is now refused, moving nothing. The gap and the running position are in f64, so rounding over many objects can't move the last one. The Match commands' descriptions and the guide say what each does per side, that the width and height may come from two objects, and that a straight line keeps its zero side. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/cmds_modify.rs | 28 +++++++++++++++++----------- crates/engine/src/tests.rs | 9 +++++++++ docs/guide/drawing.md | 9 ++++++--- docs/guide/reference/commands.md | 10 +++++----- 4 files changed, 37 insertions(+), 19 deletions(-) diff --git a/crates/engine/src/cmds_modify.rs b/crates/engine/src/cmds_modify.rs index fbb24b06..acfb3b56 100644 --- a/crates/engine/src/cmds_modify.rs +++ b/crates/engine/src/cmds_modify.rs @@ -55,11 +55,11 @@ pub fn specs() -> Vec { c("align.bottom", "Bottom", "Modify/Align", Some("Ctrl+Alt+6"), "{to_stage?}", true, |s, p| align(s, p, Edge::Bottom)), c("align.distribute_h", "Distribute Horizontal Centers", "Modify/Align", None, "{}", true, |s, _| distribute(s, true)), c("align.distribute_v", "Distribute Vertical Centers", "Modify/Align", None, "{}", true, |s, _| distribute(s, false)), - c("align.match_width", "Match Width", "Modify/Align", None, "{to_stage?} makes each selected object as wide as the widest (to_stage: as the stage), keeping its left edge where it is", true, |s, p| match_size(s, p, true, false)), - c("align.match_height", "Match Height", "Modify/Align", None, "{to_stage?} makes each selected object as tall as the tallest (to_stage: as the stage), keeping its top edge where it is", true, |s, p| match_size(s, p, false, true)), - c("align.match_size", "Match Width and Height", "Modify/Align", None, "{to_stage?} makes each selected object as wide as the widest and as tall as the tallest (to_stage: the stage's size), keeping its top-left corner where it is", true, |s, p| match_size(s, p, true, true)), - c("align.space_h", "Space Evenly Horizontally", "Modify/Align", None, "{} moves the selected objects (three or more) so the gaps between them across are equal; the leftmost and rightmost stay where they are", true, |s, _| space(s, true)), - c("align.space_v", "Space Evenly Vertically", "Modify/Align", None, "{} moves the selected objects (three or more) so the gaps between them down are equal; the topmost and bottommost stay where they are", true, |s, _| space(s, false)), + c("align.match_width", "Match Width", "Modify/Align", None, "{to_stage?} sets each selected object's width to the widest one's (to_stage: the stage's width), keeping its height and its left edge; an object with no width (a vertical line) keeps none", true, |s, p| match_size(s, p, true, false)), + c("align.match_height", "Match Height", "Modify/Align", None, "{to_stage?} sets each selected object's height to the tallest one's (to_stage: the stage's height), keeping its width and its top edge; an object with no height (a horizontal line) keeps none", true, |s, p| match_size(s, p, false, true)), + c("align.match_size", "Match Width and Height", "Modify/Align", None, "{to_stage?} sets each selected object's width to the widest one's and its height to the tallest one's, which may be two different objects (to_stage: the stage's width and height), keeping its top-left corner; a side an object has no extent along stays as it is", true, |s, p| match_size(s, p, true, true)), + c("align.space_h", "Space Evenly Horizontally", "Modify/Align", None, "{} moves the selected objects (three or more) so the gaps between them across are equal; the first and last (by their left edges) stay where they are. Refused when the objects overlap too much to keep their order", true, |s, _| space(s, true)), + c("align.space_v", "Space Evenly Vertically", "Modify/Align", None, "{} moves the selected objects (three or more) so the gaps between them down are equal; the first and last (by their top edges) stay where they are. Refused when the objects overlap too much to keep their order", true, |s, _| space(s, false)), ] } @@ -688,17 +688,23 @@ fn space(s: &mut Session, horizontal: bool) -> Result { let (Some(first), Some(last)) = (units.first(), units.last()) else { return Ok(json!({"moved": 0})) }; let (start, _) = lo(&first.1); let (last_at, last_len) = lo(&last.1); - let end = last_at + last_len; - let total: f32 = units.iter().map(|u| lo(&u.1).1).sum(); - let gap = (end - start - total) / (units.len() - 1) as f32; - let mut at = start; + // In f64, so rounding doesn't add up over many objects and move the last one. + let end = f64::from(last_at) + f64::from(last_len); + let total: f64 = units.iter().map(|u| f64::from(lo(&u.1).1)).sum(); + let gap = (end - f64::from(start) - total) / (units.len() - 1) as f64; + // A gap so negative that an object would pass the next one (one long object over short + // ones) has no even spacing that keeps their order: refuse rather than shuffle them. + if units.iter().take(units.len() - 1).any(|u| f64::from(lo(&u.1).1) + gap < 0.0) { + return Err(EngineError::State("these objects overlap too much to space evenly in their order".into())); + } + let mut at = f64::from(start); let mut moves: Vec<(Item, Vec2)> = Vec::new(); for (items, b) in &units { let (l, n) = lo(b); - let d = at - l; + let d = (at - f64::from(l)) as f32; let d = if horizontal { Vec2::new(d, 0.0) } else { Vec2::new(0.0, d) }; moves.extend(items.iter().map(|id| (*id, d))); - at += n + gap; + at += f64::from(n) + gap; } let n = translate_each(s, &moves)?; Ok(json!({"moved": n})) diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index ed2a8d92..d886a135 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -343,6 +343,15 @@ fn match_size_and_space_evenly() { let ids: Vec = s.visible_elements().iter().take(2).map(|e| e.id.0).collect(); run(&mut s, "element.select", json!({"ids": ids})); assert!(s.execute("align.space_h", &json!({})).is_err()); + // One long object over two short ones: no even spacing keeps their order, so nothing moves. + let mut s = Session::default(); + for (x, w) in [(0, 200), (20, 20), (80, 20)] { + run(&mut s, "draw.rect", json!({"x": x, "y": 0, "w": w, "h": 10, "stroke": null, "object": true})); + } + run(&mut s, "edit.select_all", json!({})); + let before = boxes(&s); + assert!(s.execute("align.space_h", &json!({})).is_err()); + assert_eq!(boxes(&s), before); } /// #301, #297: a raw rectangle (one fill and one stroke per side, ADR 0042) aligns, distributes, diff --git a/docs/guide/drawing.md b/docs/guide/drawing.md index a07ffe8c..e62a5435 100644 --- a/docs/guide/drawing.md +++ b/docs/guide/drawing.md @@ -535,9 +535,12 @@ Use the **Align** panel in the right-hand dock, or **Modify › Align**: **Left* (**Ctrl+Alt+4**), **Vertical Center** (**Ctrl+Alt+5**) and **Bottom** (**Ctrl+Alt+6**). **Distribute Horizontal Centers** and **Distribute Vertical Centers** space three or more things evenly by their centres; **Space Evenly Horizontally** and **Space Evenly Vertically** -make the gaps between them equal instead, leaving the outer two where they are. **Match -Width**, **Match Height** and **Match Width and Height** make every selected thing the size of -the largest one (with **To stage**, the stage's size), each keeping its top-left corner. Tick **To stage** in the Align panel (or press **Ctrl+Alt+8**) to align to the +make the gaps between them equal instead, leaving the outer two where they are (things that +overlap too much to keep their order are left as they are). **Match Width** gives every +selected thing the width of the widest one and **Match Height** the height of the tallest, +each keeping its other side; **Match Width and Height** does both, so the width and the height +can come from two different things. With **To stage** they use the stage's width and height. +Each thing keeps its top-left corner, and a straight line keeps its zero width or height. Tick **To stage** in the Align panel (or press **Ctrl+Alt+8**) to align to the stage instead of the selection. A single shape always aligns to the stage. Align works across layers. diff --git a/docs/guide/reference/commands.md b/docs/guide/reference/commands.md index 1b5c8657..c708a6c3 100644 --- a/docs/guide/reference/commands.md +++ b/docs/guide/reference/commands.md @@ -253,15 +253,15 @@ This page is generated from the command registry, so it always matches the versi - **Distribute Vertical Centers** `align.distribute_v` · Modify › Align · changes the document Parameters: `{}` - **Match Width** `align.match_width` · Modify › Align · changes the document - Parameters: `{to_stage?} makes each selected object as wide as the widest (to_stage: as the stage), keeping its left edge where it is` + Parameters: `{to_stage?} sets each selected object's width to the widest one's (to_stage: the stage's width), keeping its height and its left edge; an object with no width (a vertical line) keeps none` - **Match Height** `align.match_height` · Modify › Align · changes the document - Parameters: `{to_stage?} makes each selected object as tall as the tallest (to_stage: as the stage), keeping its top edge where it is` + Parameters: `{to_stage?} sets each selected object's height to the tallest one's (to_stage: the stage's height), keeping its width and its top edge; an object with no height (a horizontal line) keeps none` - **Match Width and Height** `align.match_size` · Modify › Align · changes the document - Parameters: `{to_stage?} makes each selected object as wide as the widest and as tall as the tallest (to_stage: the stage's size), keeping its top-left corner where it is` + Parameters: `{to_stage?} sets each selected object's width to the widest one's and its height to the tallest one's, which may be two different objects (to_stage: the stage's width and height), keeping its top-left corner; a side an object has no extent along stays as it is` - **Space Evenly Horizontally** `align.space_h` · Modify › Align · changes the document - Parameters: `{} moves the selected objects (three or more) so the gaps between them across are equal; the leftmost and rightmost stay where they are` + Parameters: `{} moves the selected objects (three or more) so the gaps between them across are equal; the first and last (by their left edges) stay where they are. Refused when the objects overlap too much to keep their order` - **Space Evenly Vertically** `align.space_v` · Modify › Align · changes the document - Parameters: `{} moves the selected objects (three or more) so the gaps between them down are equal; the topmost and bottommost stay where they are` + Parameters: `{} moves the selected objects (three or more) so the gaps between them down are equal; the first and last (by their top edges) stay where they are. Refused when the objects overlap too much to keep their order` - **Bind to Data…** `data.bind` · Modify › Data · changes the document Parameters: `{property: x|y|scale_x|scale_y|rotation|alpha|frame (x, y pixels; scales and alpha percent; rotation degrees; frame: the 0-based frame of its symbol a graphic instance shows), table (id or name), column, element? (a symbol instance's id; default the selected one), start? (the span's first frame, 0-based; default the first frame the instance is on), frames? (the span's length; default one frame per row, or with a key column the frames the instance is on), from?, to? (the keys the first and last frame show; default the table's first and last; to before from plays it backwards), interpolation?: linear|step, scale?, offset? (value = column × scale + offset)} one binding per property of an instance; before the span it shows the first frame's value, after it the last's → {element, property, table, column, start, frames, value}` - **Remove Data Bindings** `data.unbind` · Modify › Data · changes the document