Files
vectorcraft/crates/tools/src/catalog.rs
T
dotCooCoo e6ec393062 Shapes: the Circle tool draws a circle through two or three points
The Circle tool, in the Ellipse tool's flyout, draws a circle with
shape.circleThroughPoints. A drag from one point to another, or a click
on each, draws the circle with the two points as the ends of a diameter.
A click on a first point, then a press on a second point dragged to a
third, draws the circle through the three. Shift keeps the second point
at 45° steps from the first. For a circle on two points, Alt rounds the
diameter to the nearest ruler tick at the current zoom in the General
unit. Each point snaps to Smart Guides. Until the release the tool shows
the circle as a dashed outline (solid once it is more than 50,000 screen
points around), a cross at its center, a line from the center to each
point and, with Measurement Labels on, the diameter by the pointer.
Three different points on one line, or a circle past the canvas, show
"Circle too large" by the pointer instead, and the release draws
nothing. Escape, a dropped press, and an edit, Undo or Redo made outside
the tool drop the first point. A second press within 3 screen points of
the first point, or one that snaps to it, places nothing when let go
there, and draws the circle on the diameter it drags out when dragged.
Each circle is one undo step. The tool's icon is new and drawn for
VectorCraft.

shape.circleThroughPoints also takes two points, or two selected anchor
points, as the ends of a diameter. Its two errors about the number of
points now say "two or three", in every catalog that translates them.

Part of #7178.
2026-11-17 13:29:12 -08:00

206 lines
9.7 KiB
Rust

//! The tool catalogue: ids, labels, shortcuts and toolbar groups (Illustrator's Advanced toolbar order).
use serde::Serialize;
#[derive(Clone, Copy, Debug, Serialize)]
pub struct ToolInfo {
pub id: &'static str,
pub label: &'static str,
/// Single-key shortcut (Shift+key shown as "Shift+X").
pub shortcut: Option<&'static str>,
/// Icon name in the UI icon set.
pub icon: &'static str,
}
const fn t(id: &'static str, label: &'static str, shortcut: Option<&'static str>, icon: &'static str) -> ToolInfo {
ToolInfo { id, label, shortcut, icon }
}
/// Toolbar groups in order; the first tool of each group is the default visible one.
pub const TOOL_GROUPS: &[&[ToolInfo]] = &[
&[t("selection", "Selection Tool", Some("V"), "tool-selection")],
&[
t("directSelection", "Direct Selection Tool", Some("A"), "tool-direct"),
t("groupSelection", "Group Selection Tool", None, "tool-group-select"),
],
&[t("magicWand", "Magic Wand Tool", Some("Y"), "tool-magic-wand")],
&[
t("lasso", "Lasso Tool", Some("Q"), "tool-lasso"),
// Enclosing Lasso's tool, kept out of `addons::GROUPS` so that `all_tools` lists it once.
t(crate::addons::enclosing_lasso::ID, "Enclosing Lasso Tool", None, "tool-lasso"),
],
&[
t("pen", "Pen Tool", Some("P"), "tool-pen"),
t("addAnchor", "Add Anchor Point Tool", Some("+"), "tool-pen-add"),
t("deleteAnchor", "Delete Anchor Point Tool", Some("-"), "tool-pen-delete"),
t("anchorPoint", "Anchor Point Tool", Some("Shift+C"), "tool-anchor"),
],
&[t("curvature", "Curvature Tool", Some("Shift+~"), "tool-curvature")],
&[
t("type", "Type Tool", Some("T"), "tool-type"),
t("areaType", "Area Type Tool", None, "tool-type-area"),
t("typeOnPath", "Type on a Path Tool", None, "tool-type-path"),
t("verticalType", "Vertical Type Tool", None, "tool-type-vertical"),
t("verticalAreaType", "Vertical Area Type Tool", None, "tool-type-vertical-area"),
t("verticalTypeOnPath", "Vertical Type on a Path Tool", None, "tool-type-vertical-path"),
t("touchType", "Touch Type Tool", Some("Shift+T"), "tool-touch-type"),
],
&[
t("lineSegment", "Line Segment Tool", Some("\\"), "tool-line"),
t("arc", "Arc Tool", None, "tool-arc"),
t("spiral", "Spiral Tool", None, "tool-spiral"),
t("rectangularGrid", "Rectangular Grid Tool", None, "tool-rect-grid"),
t("polarGrid", "Polar Grid Tool", None, "tool-polar-grid"),
],
&[
t("rectangle", "Rectangle Tool", Some("M"), "tool-rect"),
t("roundedRectangle", "Rounded Rectangle Tool", None, "tool-rounded-rect"),
t("ellipse", "Ellipse Tool", Some("L"), "tool-ellipse"),
t(crate::circle::ID, "Circle Tool", None, "tool-circle"),
t("polygon", "Polygon Tool", None, "tool-polygon"),
t("star", "Star Tool", None, "tool-star"),
t("flare", "Flare Tool", None, "tool-flare"),
],
&[t("paintbrush", "Paintbrush Tool", Some("B"), "tool-brush"), t("blobBrush", "Blob Brush Tool", Some("Shift+B"), "tool-blob-brush")],
&[
t("shaper", "Shaper Tool", Some("Shift+N"), "tool-shaper"),
t("pencil", "Pencil Tool", Some("N"), "tool-pencil"),
t("smooth", "Smooth Tool", None, "tool-smooth"),
t("pathEraser", "Path Eraser Tool", None, "tool-path-eraser"),
t("join", "Join Tool", None, "tool-join"),
],
&[
t("eraser", "Eraser Tool", Some("Shift+E"), "tool-eraser"),
t("scissors", "Scissors Tool", Some("C"), "tool-scissors"),
t("knife", "Knife", None, "tool-knife"),
// Path Precision Tools' Trim at Crossings Tool, kept out of `addons::PATH_TOOLS` so that
// `all_tools` lists it once.
t(crate::addons::trim::ID, "Trim at Crossings Tool", None, "dc-pf-trim"),
t("mirrorCut", "Mirror & Cut Tool", None, "tool-mirror-cut"),
t("lineCut", "Line Cut Tool", None, "tool-line-cut"),
t("rectCut", "Rectangle Cut Tool", None, "tool-rect-cut"),
],
&[t("rotate", "Rotate Tool", Some("R"), "tool-rotate"), t("reflect", "Reflect Tool", Some("O"), "tool-reflect")],
&[
t("scale", "Scale Tool", Some("S"), "tool-scale"),
t("shear", "Shear Tool", None, "tool-shear"),
t("reshape", "Reshape Tool", None, "tool-reshape"),
],
&[
t("width", "Width Tool", Some("Shift+W"), "tool-width"),
t("warp", "Warp Tool", Some("Shift+R"), "tool-warp"),
t("twirl", "Twirl Tool", None, "tool-twirl"),
t("pucker", "Pucker Tool", None, "tool-pucker"),
t("bloat", "Bloat Tool", None, "tool-bloat"),
t("scallop", "Scallop Tool", None, "tool-scallop"),
t("crystallize", "Crystallize Tool", None, "tool-crystallize"),
t("wrinkle", "Wrinkle Tool", None, "tool-wrinkle"),
],
&[t("freeTransform", "Free Transform Tool", Some("E"), "tool-free-transform"), t("puppetWarp", "Puppet Warp Tool", None, "tool-puppet")],
&[
t("shapeBuilder", "Shape Builder Tool", Some("Shift+M"), "tool-shape-builder"),
t("livePaintBucket", "Live Paint Bucket", Some("K"), "tool-bucket"),
t("livePaintSelection", "Live Paint Selection Tool", Some("Shift+L"), "tool-live-select"),
],
&[
t("perspectiveGrid", "Perspective Grid Tool", Some("Shift+P"), "tool-perspective"),
t("perspectiveSelection", "Perspective Selection Tool", Some("Shift+V"), "tool-perspective-select"),
],
&[t("mesh", "Mesh Tool", Some("U"), "tool-mesh")],
&[t("gradient", "Gradient Tool", Some("G"), "tool-gradient")],
&[t("eyedropper", "Eyedropper Tool", Some("I"), "tool-eyedropper"), t("measure", "Measure Tool", None, "tool-measure")],
&[t("blend", "Blend Tool", Some("W"), "tool-blend"), t("objectsOnPath", "Objects on Path Tool", None, "tool-objects-on-path")],
&[t("dimension", "Dimension Tool", None, "tool-dimension")],
&[
t("symbolSprayer", "Symbol Sprayer Tool", Some("Shift+S"), "tool-symbol"),
t("symbolShifter", "Symbol Shifter Tool", None, "tool-symbol"),
t("symbolScruncher", "Symbol Scruncher Tool", None, "tool-symbol"),
t("symbolSizer", "Symbol Sizer Tool", None, "tool-symbol"),
t("symbolSpinner", "Symbol Spinner Tool", None, "tool-symbol"),
t("symbolStainer", "Symbol Stainer Tool", None, "tool-symbol"),
t("symbolScreener", "Symbol Screener Tool", None, "tool-symbol"),
t("symbolStyler", "Symbol Styler Tool", None, "tool-symbol"),
],
&[
t("columnGraph", "Column Graph Tool", Some("J"), "tool-graph"),
t("stackedColumnGraph", "Stacked Column Graph Tool", None, "tool-graph"),
t("barGraph", "Bar Graph Tool", None, "tool-graph"),
t("stackedBarGraph", "Stacked Bar Graph Tool", None, "tool-graph"),
t("lineGraph", "Line Graph Tool", None, "tool-graph"),
t("areaGraph", "Area Graph Tool", None, "tool-graph"),
t("scatterGraph", "Scatter Graph Tool", None, "tool-graph"),
t("pieGraph", "Pie Graph Tool", None, "tool-graph"),
t("radarGraph", "Radar Graph Tool", None, "tool-graph"),
],
&[
t("artboard", "Artboard Tool", Some("Shift+O"), "tool-artboard"),
t("slice", "Slice Tool", Some("Shift+K"), "tool-slice"),
t("sliceSelection", "Slice Selection Tool", None, "tool-slice"),
],
&[
t("hand", "Hand Tool", Some("H"), "tool-hand"),
t("rotateView", "Rotate View Tool", Some("Shift+H"), "tool-rotate-view"),
t("printTiling", "Print Tiling Tool", None, "tool-print-tiling"),
],
&[t("zoom", "Zoom Tool", Some("Z"), "tool-zoom")],
];
/// Every tool: the toolbar's, then the add-ons' ([`crate::addons::GROUPS`]).
pub fn all_tools() -> impl Iterator<Item = &'static ToolInfo> {
TOOL_GROUPS.iter().chain(crate::addons::GROUPS).flat_map(|g| g.iter())
}
pub fn tool_info(id: &str) -> Option<&'static ToolInfo> {
all_tools().find(|t| t.id == id)
}
/// Tool for a single-key shortcut such as "V" or "Shift+M".
pub fn tool_for_shortcut(s: &str) -> Option<&'static ToolInfo> {
all_tools().find(|t| t.shortcut == Some(s))
}
/// Index of the group containing `id`.
pub fn group_of(id: &str) -> Option<usize> {
TOOL_GROUPS.iter().position(|g| g.iter().any(|t| t.id == id))
}
/// Selection, Direct Selection and Group Selection: the tools Cmd held lends the others for a drag.
pub fn is_selection_tool(id: &str) -> bool {
matches!(id, "selection" | "directSelection" | "groupSelection")
}
/// The tools that show a selected path's anchors and handles as Direct Selection does, and drag
/// them: a Cmd drag with one of them is a Direct Selection drag until a selection tool is chosen.
pub fn edits_anchors(id: &str) -> bool {
matches!(id, "directSelection" | "pen" | "addAnchor" | "deleteAnchor" | "anchorPoint" | "curvature" | crate::addons::smart_pen::ID)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn unique_ids_and_shortcuts() {
let mut ids: Vec<&str> = all_tools().map(|t| t.id).collect();
let n = ids.len();
ids.sort();
ids.dedup();
assert_eq!(ids.len(), n, "duplicate tool ids");
let mut sc: Vec<&str> = all_tools().filter_map(|t| t.shortcut).collect();
let n = sc.len();
sc.sort();
sc.dedup();
assert_eq!(sc.len(), n, "duplicate shortcuts");
assert!(n > 40);
}
#[test]
fn lookups() {
assert_eq!(tool_for_shortcut("V").unwrap().id, "selection");
assert_eq!(tool_for_shortcut("Shift+M").unwrap().id, "shapeBuilder");
assert_eq!(group_of("star"), group_of("rectangle"));
assert!(is_selection_tool("groupSelection") && !is_selection_tool("pen"));
assert!(edits_anchors("pen") && !edits_anchors("rectangle"));
}
}