Add Artboard Guides: the duplicate check stops at the first match without allocating

ui.menuDialog's params text and the progress line say the dialog needs an
artboard.
This commit is contained in:
dotCooCoo committed 2026-12-01 02:35:02 -08:00
1 parent 04198e416e
commit 0b5e647aa1
4 files changed
+16 -13

No files matched your search

@@ -7,7 +7,7 @@ mod tests;
use serde_json::{Value, json};
use vectorcraft_doc::{Document, Node, NodeId, NodeKind};
use vectorcraft_geom::{Anchor, PathData, Point, Rect, shapes};
use vectorcraft_geom::{PathData, Point, Rect, shapes};
use super::super::super::panelcmds::{artboard_at, listed_artboards};
use super::super::super::{CommandSpec, bad, cmd, has_doc, switch_or};
@@ -57,11 +57,14 @@ fn holds_guide(d: &Document, layer: Option<NodeId>, rect: Rect) -> bool {
let r = rect.abs();
let corners = [Point::new(r.x0, r.y0), Point::new(r.x1, r.y0), Point::new(r.x1, r.y1), Point::new(r.x0, r.y1)];
layer.and_then(|id| d.node(id)).is_some_and(|n| {
let mut found = false;
n.walk(&mut |c| {
found |= matches!(&c.kind, NodeKind::Path { path: p, guide: true, .. } if traces(p, &corners));
});
found
n.try_walk(&mut |c| {
if matches!(&c.kind, NodeKind::Path { path: p, guide: true, .. } if traces(p, &corners)) {
std::ops::ControlFlow::Break(())
} else {
std::ops::ControlFlow::Continue(())
}
})
.is_break()
})
}
@@ -71,9 +74,9 @@ fn traces(path: &PathData, corners: &[Point; 4]) -> bool {
if !sp.closed || sp.anchors.len() != 4 {
return false;
}
let anchors: Vec<&Anchor> = sp.anchors.iter().collect();
let [first, second, ..] = anchors[..] else { return false };
if anchors.iter().any(|a| a.h_in != a.p || a.h_out != a.p) {
let mut anchors = sp.anchors.iter();
let (Some(first), Some(second)) = (anchors.next(), anchors.next()) else { return false };
if sp.anchors.iter().any(|a| a.h_in != a.p || a.h_out != a.p) {
return false;
}
let (Some(start), Some(next)) = (corners.iter().position(|&c| c == first.p), corners.iter().position(|&c| c == second.p)) else {
@@ -81,7 +84,7 @@ fn traces(path: &PathData, corners: &[Point; 4]) -> bool {
};
// 1 runs the way `corners` does, 3 the other way.
let step = (next + 4 - start) % 4;
(step == 1 || step == 3) && anchors.iter().enumerate().all(|(k, a)| a.p == corners[(start + k * step) % 4])
(step == 1 || step == 3) && sp.anchors.iter().enumerate().all(|(k, a)| a.p == corners[(start + k * step) % 4])
}
fn artboard_guides(s: &mut Session, p: &Value) -> Result<Value> {
+1 -1
View File
@@ -1531,7 +1531,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
"ui.menuDialog",
"Menu Dialog",
"",
"{command: object.move|object.rotate|object.scale|object.reflect|object.shear|object.transformEach|path.average|path.averageJoin|object.path.offsetPath|object.path.simplify|object.path.smooth|object.path.splitIntoGrid|object.vectorHalftone|object.stepAndRepeat|artboard.rearrange|artboard.rename|object.envelope.makeWithWarp|object.envelope.resetWithWarp|object.envelope.makeWithMesh|object.envelope.resetWithMesh|object.envelope.options|addon.arrange.grid|addon.arrange.offset|addon.arrange.replace|addon.arrange.size|addon.arrange.match|addon.packaging.setFoldAngle|addon.pathtools.cornerSet|addon.pathtools.divideDashes|addon.pathtools.bridge|addon.pathtools.tangentCircle|addon.type.textTweaker|addon.color.swatchLegend|addon.arrange.randomizeOpacity|addon.arrange.sort|addon.arrange.artboardGuides|addon.color.applyNearestSwatch|addon.select.byArtboards|addon.select.editPointsOnly|type.smartPunctuation|variable.define|variable.rename|variable.bind|dataset.new|dataset.set|dataset.rename|dataset.select} open the dialog that command's menu item opens (its `key` in ui.inspect is the command id, except `transformEach` for object.transformEach, `envelopeWarp` for object.envelope.makeWithWarp and object.envelope.resetWithWarp, `envelopeMesh` for object.envelope.makeWithMesh and object.envelope.resetWithMesh, `variables` for variable.define and variable.rename and variable.bind and dataset.new and dataset.set and dataset.rename and dataset.select, `envelopeOptions` for object.envelope.options, `smoothSlider` for object.path.smooth, and `simplifySlider` for object.path.simplify; the dialogs of addon.color.applyNearestSwatch and addon.select.byArtboards have no `key`; smoothSlider and simplifySlider are the sliders over the canvas, with field `level`, and object.path.simplify opens its dialog `object.path.simplify` instead once OK in that dialog keeps the settings (`retain`); Set Fold Angle's `angle` is the selected fold lines' angle, and it is refused while the selection has no fold line it can change; Scale and Transform Each have `corners` and `strokes`, from the preferences, which OK updates; Transform Each opens on the values it was last confirmed with (not `copy`), and its Copy button confirms with `copy: true`; the envelope dialogs start from the selected envelope, Make opens as Reset (`reset: true`) while one is selected; variable.rename opens only while the document has a variable, and dataset.set and dataset.rename only while it has a data set, and otherwise the status bar says why; ui.dialog.set, ui.dialog.confirm and ui.dialog.cancel take the dialog's `id` from ui.inspect, or `top`, not its `key`)",
"{command: object.move|object.rotate|object.scale|object.reflect|object.shear|object.transformEach|path.average|path.averageJoin|object.path.offsetPath|object.path.simplify|object.path.smooth|object.path.splitIntoGrid|object.vectorHalftone|object.stepAndRepeat|artboard.rearrange|artboard.rename|object.envelope.makeWithWarp|object.envelope.resetWithWarp|object.envelope.makeWithMesh|object.envelope.resetWithMesh|object.envelope.options|addon.arrange.grid|addon.arrange.offset|addon.arrange.replace|addon.arrange.size|addon.arrange.match|addon.packaging.setFoldAngle|addon.pathtools.cornerSet|addon.pathtools.divideDashes|addon.pathtools.bridge|addon.pathtools.tangentCircle|addon.type.textTweaker|addon.color.swatchLegend|addon.arrange.randomizeOpacity|addon.arrange.sort|addon.arrange.artboardGuides|addon.color.applyNearestSwatch|addon.select.byArtboards|addon.select.editPointsOnly|type.smartPunctuation|variable.define|variable.rename|variable.bind|dataset.new|dataset.set|dataset.rename|dataset.select} open the dialog that command's menu item opens (its `key` in ui.inspect is the command id, except `transformEach` for object.transformEach, `envelopeWarp` for object.envelope.makeWithWarp and object.envelope.resetWithWarp, `envelopeMesh` for object.envelope.makeWithMesh and object.envelope.resetWithMesh, `variables` for variable.define and variable.rename and variable.bind and dataset.new and dataset.set and dataset.rename and dataset.select, `envelopeOptions` for object.envelope.options, `smoothSlider` for object.path.smooth, and `simplifySlider` for object.path.simplify; the dialogs of addon.color.applyNearestSwatch and addon.select.byArtboards have no `key`; smoothSlider and simplifySlider are the sliders over the canvas, with field `level`, and object.path.simplify opens its dialog `object.path.simplify` instead once OK in that dialog keeps the settings (`retain`); addon.arrange.artboardGuides fails when the document has no artboards; Set Fold Angle's `angle` is the selected fold lines' angle, and it is refused while the selection has no fold line it can change; Scale and Transform Each have `corners` and `strokes`, from the preferences, which OK updates; Transform Each opens on the values it was last confirmed with (not `copy`), and its Copy button confirms with `copy: true`; the envelope dialogs start from the selected envelope, Make opens as Reset (`reset: true`) while one is selected; variable.rename opens only while the document has a variable, and dataset.set and dataset.rename only while it has a data set, and otherwise the status bar says why; ui.dialog.set, ui.dialog.confirm and ui.dialog.cancel take the dialog's `id` from ui.inspect, or `top`, not its `key`)",
),
(
"ui.widthPointEdit",
+1 -1
View File
@@ -1532,7 +1532,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
"ui.menuDialog",
"Menu Dialog",
"",
"{command: object.move|object.rotate|object.scale|object.reflect|object.shear|object.transformEach|path.average|path.averageJoin|object.path.offsetPath|object.path.simplify|object.path.smooth|object.path.splitIntoGrid|object.vectorHalftone|object.stepAndRepeat|artboard.rearrange|artboard.rename|object.envelope.makeWithWarp|object.envelope.resetWithWarp|object.envelope.makeWithMesh|object.envelope.resetWithMesh|object.envelope.options|addon.arrange.grid|addon.arrange.offset|addon.arrange.replace|addon.arrange.size|addon.arrange.match|addon.packaging.setFoldAngle|addon.pathtools.cornerSet|addon.pathtools.divideDashes|addon.pathtools.bridge|addon.pathtools.tangentCircle|addon.type.textTweaker|addon.color.swatchLegend|addon.arrange.randomizeOpacity|addon.arrange.sort|addon.arrange.artboardGuides|addon.color.applyNearestSwatch|addon.select.byArtboards|addon.select.editPointsOnly|type.smartPunctuation|variable.define|variable.rename|variable.bind|dataset.new|dataset.set|dataset.rename|dataset.select} open the dialog that command's menu item opens (its `key` in ui.inspect is the command id, except `transformEach` for object.transformEach, `envelopeWarp` for object.envelope.makeWithWarp and object.envelope.resetWithWarp, `envelopeMesh` for object.envelope.makeWithMesh and object.envelope.resetWithMesh, `variables` for variable.define and variable.rename and variable.bind and dataset.new and dataset.set and dataset.rename and dataset.select, `envelopeOptions` for object.envelope.options, `smoothSlider` for object.path.smooth, and `simplifySlider` for object.path.simplify; the dialogs of addon.color.applyNearestSwatch and addon.select.byArtboards have no `key`; smoothSlider and simplifySlider are the sliders over the canvas, with field `level`, and object.path.simplify opens its dialog `object.path.simplify` instead once OK in that dialog keeps the settings (`retain`); Set Fold Angle's `angle` is the selected fold lines' angle, and it is refused while the selection has no fold line it can change; Scale and Transform Each have `corners` and `strokes`, from the preferences, which OK updates; Transform Each opens on the values it was last confirmed with (not `copy`), and its Copy button confirms with `copy: true`; the envelope dialogs start from the selected envelope, Make opens as Reset (`reset: true`) while one is selected; variable.rename opens only while the document has a variable, and dataset.set and dataset.rename only while it has a data set, and otherwise the status bar says why; ui.dialog.set, ui.dialog.confirm and ui.dialog.cancel take the dialog's `id` from ui.inspect, or `top`, not its `key`)",
"{command: object.move|object.rotate|object.scale|object.reflect|object.shear|object.transformEach|path.average|path.averageJoin|object.path.offsetPath|object.path.simplify|object.path.smooth|object.path.splitIntoGrid|object.vectorHalftone|object.stepAndRepeat|artboard.rearrange|artboard.rename|object.envelope.makeWithWarp|object.envelope.resetWithWarp|object.envelope.makeWithMesh|object.envelope.resetWithMesh|object.envelope.options|addon.arrange.grid|addon.arrange.offset|addon.arrange.replace|addon.arrange.size|addon.arrange.match|addon.packaging.setFoldAngle|addon.pathtools.cornerSet|addon.pathtools.divideDashes|addon.pathtools.bridge|addon.pathtools.tangentCircle|addon.type.textTweaker|addon.color.swatchLegend|addon.arrange.randomizeOpacity|addon.arrange.sort|addon.arrange.artboardGuides|addon.color.applyNearestSwatch|addon.select.byArtboards|addon.select.editPointsOnly|type.smartPunctuation|variable.define|variable.rename|variable.bind|dataset.new|dataset.set|dataset.rename|dataset.select} open the dialog that command's menu item opens (its `key` in ui.inspect is the command id, except `transformEach` for object.transformEach, `envelopeWarp` for object.envelope.makeWithWarp and object.envelope.resetWithWarp, `envelopeMesh` for object.envelope.makeWithMesh and object.envelope.resetWithMesh, `variables` for variable.define and variable.rename and variable.bind and dataset.new and dataset.set and dataset.rename and dataset.select, `envelopeOptions` for object.envelope.options, `smoothSlider` for object.path.smooth, and `simplifySlider` for object.path.simplify; the dialogs of addon.color.applyNearestSwatch and addon.select.byArtboards have no `key`; smoothSlider and simplifySlider are the sliders over the canvas, with field `level`, and object.path.simplify opens its dialog `object.path.simplify` instead once OK in that dialog keeps the settings (`retain`); addon.arrange.artboardGuides fails when the document has no artboards; Set Fold Angle's `angle` is the selected fold lines' angle, and it is refused while the selection has no fold line it can change; Scale and Transform Each have `corners` and `strokes`, from the preferences, which OK updates; Transform Each opens on the values it was last confirmed with (not `copy`), and its Copy button confirms with `copy: true`; the envelope dialogs start from the selected envelope, Make opens as Reset (`reset: true`) while one is selected; variable.rename opens only while the document has a variable, and dataset.set and dataset.rename only while it has a data set, and otherwise the status bar says why; ui.dialog.set, ui.dialog.confirm and ui.dialog.cancel take the dialog's `id` from ui.inspect, or `top`, not its `key`)",
),
(
"ui.widthPointEdit",
+1 -1
View File
@@ -3158,7 +3158,7 @@ A VectorCraft addition, not a feature of the reference app, so no area score mov
## Arrange Tools add-on: Add Artboard Guides (2026-11-29)
A VectorCraft addition, so no area score moves. Object › Plug-ins › Arrange Tools › Add Artboard Guides… adds a rectangular guide around the active artboard, or around every artboard, at the Offset typed: more than 0 puts it outside the artboard (a bleed line), less than 0 inside it (a safe-area line). The guides go on a top-level layer named Artboard Guides, made above the others the first time and reused after that with its lock and visibility as they are; a guide already anywhere in that layer with the same rectangle is not added again. The dialog acts on the artboard the view shows. One undo step; no step when nothing is added. An inset that leaves an artboard no width or no height is refused. `addon.arrange.artboardGuides` also takes a list of artboards. Tests: `cmd::addons::arrange::artboard_guides::tests` in `vectorcraft-engine` (outside and inside offsets, the active artboard and the one the journal records, every artboard and listed ones, the layer reused with its lock and visibility, no repeat and no step, a guide grouped inside the layer, Release Guides, bad params and too large an inset refused, off without artboards), `real_artboard_guide_edits_reach_the_preview_and_ok_adds_one_undo_step`, `add_artboard_guides_puts_one_around_every_artboard_and_refuses_too_large_an_inset` and `add_artboard_guides_uses_the_artboard_the_view_shows` in `vectorcraft-ui-egui`, and `command_sweep`. Commands: `docs/mcp.md` › Arrange Tools add-on.
A VectorCraft addition, so no area score moves. Object › Plug-ins › Arrange Tools › Add Artboard Guides… adds a rectangular guide around the active artboard, or around every artboard, at the Offset typed: more than 0 puts it outside the artboard (a bleed line), less than 0 inside it (a safe-area line). The guides go on a top-level layer named Artboard Guides, made above the others the first time and reused after that with its lock and visibility as they are; a guide already anywhere in that layer with the same rectangle, from whichever corner and in whichever direction its path runs, is not added again. The dialog acts on the artboard the view shows. One undo step; no step when nothing is added. The dialog does not open, and `ui.menuDialog` returns an error, when the document has no artboards. An inset that leaves an artboard no width or no height is refused. `addon.arrange.artboardGuides` also takes a list of artboards. Tests: `cmd::addons::arrange::artboard_guides::tests` in `vectorcraft-engine` (outside and inside offsets, the active artboard and the one the journal records, every artboard and listed ones, the layer reused with its lock and visibility, no repeat and no step, a guide grouped inside the layer, a guide drawn from another corner or the other way round, Release Guides, bad params and too large an inset refused, off without artboards), `real_artboard_guide_edits_reach_the_preview_and_ok_adds_one_undo_step`, `add_artboard_guides_puts_one_around_every_artboard_and_refuses_too_large_an_inset`, `add_artboard_guides_does_not_open_without_artboards` and `add_artboard_guides_uses_the_artboard_the_view_shows` in `vectorcraft-ui-egui`, and `command_sweep`. Commands: `docs/mcp.md` › Arrange Tools add-on.
## Arrange Tools add-on: Offset Objects (2026-11-29)