From e2334a21652950b6804ce078eb47785aaf9506a9 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 22 Nov 2026 06:39:29 -0800 Subject: [PATCH] Smart Pen: the tool is in the Pen tool's flyout MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Smart Pen Tool joins the Pen group in both shipped toolbars, after the Quick Pen, and stays in Object › Plug-ins › Smart Pen. The All Tools drawer lists it once, under Draw, and Edit › Keyboard Shortcuts › Tools lists it once. It has no default shortcut, and the Pen keeps P. A toolbar the user already edited keeps its saved layout; Reset Toolbar adds the tool. A group torn off the Tools panel's toolbar now shows the tools of the current layout's group that starts with the same tool, after toolbar edits, Reset Toolbar, a switch between Basic and Advanced, loading the preferences and switching workspaces, as groups torn off a toolbar made with New Toolbar already did. A strip with no such group keeps its tools. Part of #8326 --- crates/mcp/src/tests.rs | 12 +++ crates/tools/src/addons.rs | 34 ++++-- crates/tools/src/catalog.rs | 2 + crates/ui-egui/src/control/tests.rs | 4 +- crates/ui-egui/src/edit_toolbar.rs | 34 ++++++ crates/ui-egui/src/edit_toolbar/tests.rs | 131 ++++++++++++++++++++++- crates/ui-egui/src/menus/run.rs | 6 +- crates/ui-egui/src/state.rs | 1 + crates/ui-egui/src/toolbar.rs | 6 +- crates/ui-egui/src/toolbar/tests.rs | 7 +- crates/ui-egui/src/workspaces.rs | 1 + docs/control-protocol.md | 4 +- docs/mcp.md | 4 +- docs/target-app-parity.md | 8 +- docs/ui-parity.md | 4 +- 15 files changed, 232 insertions(+), 26 deletions(-) diff --git a/crates/mcp/src/tests.rs b/crates/mcp/src/tests.rs index c8756cefc7..9b27b976de 100644 --- a/crates/mcp/src/tests.rs +++ b/crates/mcp/src/tests.rs @@ -1599,6 +1599,18 @@ fn headless_backend_methods() { assert_eq!(with_enclosing[0][1]["label"], "Enclosing Lasso Tool"); assert!(with_enclosing[0][1]["shortcut"].is_null()); assert_eq!(h.call("ui.tool.select", json!({"tool": enclosing})).unwrap()["tool"], enclosing); + // The Smart Pen Tool is listed once, at the end of the Pen tool's group. + let smart_pen = vectorcraft_tools::addons::smart_pen::ID; + let with_smart_pen: Vec<_> = + groups.iter().map(|group| group.as_array().unwrap()).filter(|group| group.iter().any(|entry| entry["id"] == smart_pen)).collect(); + assert_eq!(with_smart_pen.len(), 1, "{smart_pen} is in one group"); + let ids: Vec<_> = with_smart_pen[0].iter().map(|entry| entry["id"].clone()).collect(); + assert_eq!(ids.first(), Some(&json!("pen"))); + assert_eq!(ids[ids.len().saturating_sub(2)..], [json!("quickPen"), json!(smart_pen)]); + let entry = with_smart_pen[0].iter().find(|entry| entry["id"] == smart_pen).unwrap(); + assert_eq!(entry["label"], "Smart Pen Tool"); + assert!(entry["shortcut"].is_null()); + assert_eq!(h.call("ui.tool.select", json!({"tool": smart_pen})).unwrap()["tool"], smart_pen); let polygonal = groups.iter().flat_map(|group| group.as_array().unwrap()).find(|entry| entry["id"] == "polygonalLasso"); assert_eq!(polygonal.map(|entry| entry["label"].clone()), Some(json!("Polygonal Lasso Tool"))); assert!(h.call("ui.resize", json!({})).is_err()); diff --git a/crates/tools/src/addons.rs b/crates/tools/src/addons.rs index c0223aedb9..1a240419be 100644 --- a/crates/tools/src/addons.rs +++ b/crates/tools/src/addons.rs @@ -1,9 +1,9 @@ //! The tools of VectorCraft's built-in add-ons. They aren't in the toolbars as they ship: the All //! Tools drawer lists them (under their add-on's heading) so they can be added, and each add-on's -//! submenu selects them. Tool gestures emit engine commands. Two tools are the exceptions: the Trim -//! at Crossings Tool is in the Scissors tool's group and the Enclosing Lasso Tool is in the Lasso -//! tool's group ([`crate::TOOL_GROUPS`]), where the toolbars and the All Tools drawer show them, as -//! well as in their add-ons' submenus. +//! submenu selects them. Tool gestures emit engine commands. Three tools are the exceptions: the +//! Trim at Crossings Tool is in the Scissors tool's group, the Enclosing Lasso Tool is in the Lasso +//! tool's group and the Smart Pen Tool is in the Pen tool's group ([`crate::TOOL_GROUPS`]), where +//! the toolbars and the All Tools drawer show them, as well as in their add-ons' submenus. pub mod anchor_eraser; pub mod box3d; @@ -35,9 +35,6 @@ pub const PATH_TOOLS: &[ToolInfo] = &[ ToolInfo { id: tangent_circle::ID, label: "Tangent Circle Tool", shortcut: None, icon: "circle" }, ]; -/// Smart Pen's tool, a flyout group of its own. -pub const SMART_PEN: &[ToolInfo] = &[ToolInfo { id: smart_pen::ID, label: "Smart Pen Tool", shortcut: None, icon: "spline-pointer" }]; - pub const CONTOUR: &[ToolInfo] = &[ToolInfo { id: contour::ID, label: "Contour Tool", shortcut: None, icon: "tool-contour" }]; pub const BOX_3D: &[ToolInfo] = &[ToolInfo { id: box3d::ID, label: "3D Box Tool", shortcut: None, icon: "box" }]; @@ -47,10 +44,10 @@ pub const POLYGONAL_LASSO: &[ToolInfo] = &[ToolInfo { id: polygonal_lasso::ID, l /// The add-ons' tool groups, after the toolbar's own ([`crate::TOOL_GROUPS`]), each with the /// heading the All Tools drawer lists it under (its add-on's name). const HEADED: &[(&[ToolInfo], &str)] = - &[(PATH_TOOLS, "Path Precision Tools"), (SMART_PEN, "Smart Pen"), (CONTOUR, "Contour"), (BOX_3D, "3D Box"), (POLYGONAL_LASSO, "Polygonal Lasso")]; + &[(PATH_TOOLS, "Path Precision Tools"), (CONTOUR, "Contour"), (BOX_3D, "3D Box"), (POLYGONAL_LASSO, "Polygonal Lasso")]; /// The add-ons' tool groups, after the toolbar's own ([`crate::TOOL_GROUPS`]). -pub const GROUPS: &[&[ToolInfo]] = &[PATH_TOOLS, SMART_PEN, CONTOUR, BOX_3D, POLYGONAL_LASSO]; +pub const GROUPS: &[&[ToolInfo]] = &[PATH_TOOLS, CONTOUR, BOX_3D, POLYGONAL_LASSO]; /// The heading the All Tools drawer lists tool `id` under: its add-on's name. pub fn heading(id: &str) -> Option<&'static str> { @@ -92,7 +89,6 @@ mod tests { assert!(!crate::TOOL_GROUPS.iter().any(|g| g.iter().any(|x| x.id == t.id)), "{} is not in the toolbar's groups", t.id); } assert!(PATH_TOOLS.iter().all(|t| heading(t.id) == Some("Path Precision Tools"))); - assert_eq!(heading(smart_pen::ID), Some("Smart Pen")); assert_eq!(heading(contour::ID), Some("Contour")); assert_eq!(heading(box3d::ID), Some("3D Box")); assert_eq!(heading(polygonal_lasso::ID), Some("Polygonal Lasso")); @@ -134,4 +130,22 @@ mod tests { assert!(heading(id).is_none(), "not listed again under the add-on"); assert_eq!(crate::catalog::all_tools().filter(|t| t.id == id).count(), 1); } + + /// The Smart Pen Tool is in the Pen tool's group, after the Pen family's own tools, with no + /// default shortcut, listed once, and still made by its add-on. + #[test] + fn smart_pen_is_in_the_pen_group_once() { + let id = smart_pen::ID; + let groups: Vec<_> = crate::TOOL_GROUPS.iter().filter(|g| g.iter().any(|t| t.id == id)).collect(); + assert_eq!(groups.len(), 1); + let ids: Vec<_> = groups[0].iter().map(|t| t.id).collect(); + assert_eq!(ids.first(), Some(&"pen"), "the Pen stays the group's default"); + assert_eq!(ids[ids.len().saturating_sub(2)..], [crate::quickpen::ID, id], "right after the Quick Pen, last"); + let info = crate::tool_info(id).expect("catalogued"); + assert_eq!((info.label, info.shortcut), ("Smart Pen Tool", None)); + assert_eq!(crate::tool_info("pen").and_then(|t| t.shortcut), Some("P"), "the Pen keeps its shortcut"); + assert_eq!(create(id).map(|tool| tool.id()), Some(id)); + assert!(heading(id).is_none(), "not listed again under the add-on"); + assert_eq!(crate::catalog::all_tools().filter(|t| t.id == id).count(), 1); + } } diff --git a/crates/tools/src/catalog.rs b/crates/tools/src/catalog.rs index 2dc0774aa2..c839287732 100644 --- a/crates/tools/src/catalog.rs +++ b/crates/tools/src/catalog.rs @@ -35,6 +35,8 @@ pub const TOOL_GROUPS: &[&[ToolInfo]] = &[ t("deleteAnchor", "Delete Anchor Point Tool", Some("-"), "tool-pen-delete"), t("anchorPoint", "Anchor Point Tool", Some("Shift+C"), "tool-anchor"), t(crate::quickpen::ID, "Quick Pen Tool", Some("Alt+P"), "tool-quick-pen"), + // Smart Pen's tool, kept out of `addons::GROUPS` so that `all_tools` lists it once. + t(crate::addons::smart_pen::ID, "Smart Pen Tool", None, "spline-pointer"), ], &[t("curvature", "Curvature Tool", Some("Shift+~"), "tool-curvature")], &[ diff --git a/crates/ui-egui/src/control/tests.rs b/crates/ui-egui/src/control/tests.rs index 96c4880d39..f627c63a1a 100644 --- a/crates/ui-egui/src/control/tests.rs +++ b/crates/ui-egui/src/control/tests.rs @@ -613,7 +613,9 @@ fn control_lists_and_selects_optional_addon_tools() { let listed = input_request(&mut app, "ui.tool.list", json!({})); assert_eq!(listed["ok"], true); let groups = listed["result"].as_array().unwrap(); - for tool in vectorcraft_tools::addons::GROUPS.iter().flat_map(|group| group.iter()) { + // The add-on tools that ship in a toolbar group as well. + let in_toolbar_groups = [vectorcraft_tools::addons::smart_pen::ID].map(|id| vectorcraft_tools::tool_info(id).expect("catalogued")); + for tool in vectorcraft_tools::addons::GROUPS.iter().flat_map(|group| group.iter()).chain(in_toolbar_groups) { let matching: Vec<_> = groups.iter().flat_map(|group| group.as_array().unwrap()).filter(|entry| entry["id"] == tool.id).collect(); assert_eq!(matching.len(), 1, "{}", tool.id); assert_eq!(matching[0]["label"], tool.label); diff --git a/crates/ui-egui/src/edit_toolbar.rs b/crates/ui-egui/src/edit_toolbar.rs index 5c1fa8f6ed..f0aa5b3621 100644 --- a/crates/ui-egui/src/edit_toolbar.rs +++ b/crates/ui-egui/src/edit_toolbar.rs @@ -153,9 +153,42 @@ fn edit(app: &mut VectorcraftApp, f: impl FnOnce(&mut Vec) -> R f(&mut cats)?; prune(&mut cats); *slot = (cats != shipped(advanced)).then_some(cats); + keep_strips(&mut app.ui); Ok(slots_json(app)) } +/// Give each group torn off the Tools panel's toolbar the tools of the current layout's group +/// with the same first tool, as [`crate::custom_toolbars::keep_strips`] does for a toolbar made +/// with New Toolbar. A strip with no such group keeps its tools. +pub(crate) fn keep_strips(ui: &mut crate::state::UiState) { + if ui.floating_flyouts.is_empty() { + return; + } + let groups = layout_groups(ui); + for f in &mut ui.floating_flyouts { + if let Some(group) = f.tools.first().and_then(|k| group_of(&groups, k)) { + f.tools = group; + } + } +} + +/// The tools of the current layout's group of several tools that starts with `key`, if there is +/// one ([`keep_strips`]). +pub(crate) fn layout_group(ui: &crate::state::UiState, key: &str) -> Option> { + group_of(&layout_groups(ui), key) +} + +/// The groups of the Tools panel's current layout, as Edit Toolbar left it. +fn layout_groups(ui: &crate::state::UiState) -> Vec> { + let edited = if ui.toolbar_advanced { &ui.toolbar_edits.advanced } else { &ui.toolbar_edits.basic }; + let cats = edited.clone().unwrap_or_else(|| shipped(ui.toolbar_advanced)); + cats.iter().flat_map(|c| c.slots.iter()).map(|s| s.iter().filter_map(|id| tool_info(id).map(|t| t.id)).collect()).collect() +} + +fn group_of(groups: &[Vec<&'static str>], key: &str) -> Option> { + groups.iter().find(|s| s.len() > 1 && s.first() == Some(&key)).map(|s| s.iter().map(|id| id.to_string()).collect()) +} + /// Change the toolbar made with New Toolbar called `name` with `f`, and the groups torn off it with /// it ([`crate::custom_toolbars::keep_strips`]). Returns its slots. fn edit_custom(app: &mut VectorcraftApp, name: &str, f: impl FnOnce(&mut Vec) -> Result<(), String>) -> Result { @@ -311,6 +344,7 @@ pub(crate) fn command(app: &mut VectorcraftApp, id: &str, p: &Value) -> Option return None, diff --git a/crates/ui-egui/src/edit_toolbar/tests.rs b/crates/ui-egui/src/edit_toolbar/tests.rs index 0973a752b2..bfde6f06d5 100644 --- a/crates/ui-egui/src/edit_toolbar/tests.rs +++ b/crates/ui-egui/src/edit_toolbar/tests.rs @@ -233,6 +233,128 @@ fn a_saved_toolbar_without_enclosing_lasso_keeps_its_layout() { assert!(slot.is_some_and(|s| s.contains(&id)), "Reset Toolbar adds it"); } +/// The Smart Pen Tool is in the Pen tool's flyout in both toolbars, after the Pen family's own +/// tools, once in the All Tools drawer (under Draw) and in Keyboard Shortcuts' list, with no +/// shortcut; its button's tip names it; Reset Toolbar keeps it there. +#[test] +fn smart_pen_is_in_the_pen_flyout() { + let mut app = app(); + let id = vectorcraft_tools::addons::smart_pen::ID; + for advanced in [false, true] { + if advanced { + app.run("window.toolbarAdvanced", json!({})).unwrap(); + } + let s = slots(&app); + let slot = slot_of(&app, "pen").map(|i| s[i].clone()).expect("a Pen slot"); + assert_eq!(slot.first(), Some(&"pen"), "advanced: {advanced}"); + assert_eq!(slot[slot.len().saturating_sub(2)..], ["quickPen", id], "advanced: {advanced}"); + assert_eq!(s.iter().filter(|ids| ids.contains(&id)).count(), 1, "advanced: {advanced}"); + } + assert_eq!(heading(id), "Draw"); + assert_eq!(sections().iter().flat_map(|(_, tools)| tools.iter()).filter(|t| t.id == id).count(), 1, "listed once in the drawer"); + let rows = app.run("shortcuts.list", json!({"query": id})).unwrap(); + let rows: Vec<_> = rows.as_array().unwrap().iter().filter(|r| r["id"] == format!("tool:{id}")).collect(); + assert_eq!(rows.len(), 1, "listed once in Keyboard Shortcuts"); + assert_eq!((&rows[0]["group"], &rows[0]["shortcut"]), (&json!("Tools"), &Value::Null)); + let info = vectorcraft_tools::tool_info(id).expect("catalogued"); + assert_eq!((info.label, info.shortcut), ("Smart Pen Tool", None)); + assert_eq!(crate::toolbar::tip(info), "Smart Pen Tool"); + app.run("tool.select", json!({"tool": id})).unwrap(); + assert_eq!(app.session.tool_id(), id); + let shown = slot_of(&app, id).map(|i| crate::toolbar::shown_tool(&app, &slots(&app)[i])); + assert_eq!(shown, Some(id), "the slot's button shows the tool once chosen"); + app.run("toolbar.removeTool", json!({"tool": id})).unwrap(); + assert!(slot_of(&app, id).is_none(), "it can be taken out"); + app.run("toolbar.addTool", json!({"tool": id})).unwrap(); + assert!(slot_of(&app, id).is_some(), "the drawer adds it back"); + app.run("toolbar.removeTool", json!({"tool": id})).unwrap(); + app.run("toolbar.reset", json!({})).unwrap(); + let after_reset = slot_of(&app, "pen").map(|i| slots(&app)[i].contains(&id)); + assert_eq!(after_reset, Some(true), "Reset Toolbar puts it back"); +} + +/// A toolbar edited and saved before the Smart Pen Tool joined the Pen group keeps its saved +/// layout, in both toolbars: the tool stays in the drawer until Reset Toolbar or a drag adds it, +/// and a toolbar that already had it in a slot of its own keeps it there, once. +#[test] +fn a_saved_toolbar_without_smart_pen_keeps_its_layout() { + let id = vectorcraft_tools::addons::smart_pen::ID; + let category = |slots: &[&[&str]]| ToolbarCategory { + name: Some("Draw".into()), + slots: slots.iter().map(|s| s.iter().map(|t| t.to_string()).collect()).collect(), + }; + for advanced in [false, true] { + let edits = |saved: Vec| { + if advanced { ToolbarEdits { basic: None, advanced: Some(saved) } } else { ToolbarEdits { basic: Some(saved), advanced: None } } + }; + let mut app = app(); + if advanced { + app.run("window.toolbarAdvanced", json!({})).unwrap(); + } + app.ui.toolbar_edits = edits(vec![category(&[&["pen", "addAnchor"]])]); + app.ui = std::mem::take(&mut app.ui).sanitized(); + assert_eq!(slots(&app), [["pen", "addAnchor"]], "advanced: {advanced}"); + assert!(slot_of(&app, id).is_none(), "advanced: {advanced}"); + app.run("toolbar.reset", json!({})).unwrap(); + let slot = slot_of(&app, "pen").map(|i| slots(&app)[i].clone()); + assert!(slot.is_some_and(|s| s.contains(&id)), "Reset Toolbar adds it; advanced: {advanced}"); + app.ui.toolbar_edits = edits(vec![category(&[&["pen", "addAnchor"], &[id]])]); + app.ui = std::mem::take(&mut app.ui).sanitized(); + assert_eq!(slots(&app), [vec!["pen", "addAnchor"], vec![id]], "advanced: {advanced}"); + } +} + +/// A Pen group torn off the toolbar before the Smart Pen Tool joined it gets the tool when Reset +/// Toolbar runs, and a torn-off group follows edits to its group in the toolbar. +#[test] +fn a_torn_off_group_follows_the_toolbar() { + let id = vectorcraft_tools::addons::smart_pen::ID; + let old: Vec = ["pen", "addAnchor", "deleteAnchor", "anchorPoint", "quickPen"].map(String::from).into(); + let strip = |tools: &[String]| vec![crate::state::FloatingFlyout { tools: tools.to_vec(), pos: [0.0, 0.0] }]; + let has_it = |app: &VectorcraftApp| { + let tools = &app.ui.floating_flyouts[0].tools; + tools.starts_with(&old) && tools.last().is_some_and(|t| t == id) + }; + for advanced in [false, true] { + let mut app = app(); + if advanced { + app.run("window.toolbarAdvanced", json!({})).unwrap(); + } + // Read with the preferences. + app.ui.floating_flyouts = strip(&old); + app.ui = std::mem::take(&mut app.ui).sanitized(); + assert!(has_it(&app), "advanced: {advanced}: {:?}", app.ui.floating_flyouts); + // Applied with a workspace. + let w = crate::workspaces::Workspace { floating_flyouts: strip(&old), toolbar_advanced: advanced, ..Default::default() }; + crate::workspaces::apply(&mut app.ui, &w); + assert!(has_it(&app), "advanced: {advanced}: {:?}", app.ui.floating_flyouts); + // With a toolbar edited without the tool, until Reset Toolbar. + let saved = ToolbarCategory { name: Some("Draw".into()), slots: vec![old.clone()] }; + app.ui.toolbar_edits = if advanced { + ToolbarEdits { basic: None, advanced: Some(vec![saved]) } + } else { + ToolbarEdits { basic: Some(vec![saved]), advanced: None } + }; + app.ui = std::mem::take(&mut app.ui).sanitized(); + assert_eq!(app.ui.floating_flyouts[0].tools, old, "advanced: {advanced}"); + app.run("toolbar.reset", json!({})).unwrap(); + assert!(has_it(&app), "advanced: {advanced}: {:?}", app.ui.floating_flyouts); + app.run("toolbar.removeTool", json!({"tool": "addAnchor"})).unwrap(); + let strip = &app.ui.floating_flyouts[0].tools; + assert!(!strip.iter().any(|t| t == "addAnchor") && strip.iter().any(|t| t == id), "advanced: {advanced}: {strip:?}"); + } + // A strip shows the group of the layout shown, after an edit in the other layout too. + let mut app = app(); + app.run("window.floatTools", json!({"tool": "lasso", "floating": true})).unwrap(); + let basic = app.ui.floating_flyouts[0].tools.clone(); + app.run("window.toolbarAdvanced", json!({})).unwrap(); + let advanced = slot_of(&app, "lasso").map(|i| slots(&app)[i].iter().map(|t| t.to_string()).collect::>()); + assert_eq!(Some(&app.ui.floating_flyouts[0].tools), advanced.as_ref()); + app.run("toolbar.removeTool", json!({"tool": "addAnchor"})).unwrap(); + app.run("window.toolbarAdvanced", json!({})).unwrap(); + assert_eq!(app.ui.floating_flyouts[0].tools, basic); +} + #[test] fn the_commands_add_move_remove_and_reset_tools() { let mut app = app(); @@ -846,8 +968,9 @@ fn a_saved_toolbar_without_trim_at_crossings_keeps_its_layout() { } /// The add-ons' tools are in neither toolbar as they ship (the Trim at Crossings Tool, in the -/// Scissors tool's group, and the Enclosing Lasso Tool, in the Lasso tool's group, aside): the -/// drawer lists them under their add-on's heading, and they can be added from there. +/// Scissors tool's group, the Enclosing Lasso Tool, in the Lasso tool's group, and the Smart Pen +/// Tool, in the Pen tool's group, aside): the drawer lists them under their add-on's heading, and +/// they can be added from there. #[test] fn addon_tools_are_in_the_drawer_not_the_toolbars() { let mut app = app(); @@ -866,7 +989,6 @@ fn addon_tools_are_in_the_drawer_not_the_toolbars() { "slideAnchor", "sharedEdge", "tangentCircle", - "smartPen", contour, box3d, polygonal @@ -882,11 +1004,10 @@ fn addon_tools_are_in_the_drawer_not_the_toolbars() { sections().iter().find(|(_, tools)| tools.iter().any(|t| t.id == id)).map(|(h, tools)| (*h, tools.iter().map(|t| t.id).collect::>())) }; assert_eq!(listed("extendPath"), Some(("Path Precision Tools", addon[..8].to_vec()))); - assert_eq!(listed("smartPen"), Some(("Smart Pen", vec!["smartPen"]))); assert_eq!(listed(contour), Some(("Contour", vec![contour]))); assert_eq!(listed(box3d), Some(("3D Box", vec![box3d]))); assert_eq!(listed(polygonal), Some(("Polygonal Lasso", vec![polygonal]))); - for tool in ["extendPath", "smartPen", contour, box3d, polygonal] { + for tool in ["extendPath", contour, box3d, polygonal] { app.run("toolbar.addTool", json!({"tool": tool})).unwrap(); assert!(slot_of(&app, tool).is_some(), "{tool}"); } diff --git a/crates/ui-egui/src/menus/run.rs b/crates/ui-egui/src/menus/run.rs index aa9451d3f9..20ce2933fd 100644 --- a/crates/ui-egui/src/menus/run.rs +++ b/crates/ui-egui/src/menus/run.rs @@ -612,7 +612,11 @@ fn run_ui_part5(app: &mut VectorcraftApp, id: &str, p: &Value) -> Option flag(&mut app.ui.toolbar_advanced), + "window.toolbarAdvanced" => { + let on = flag(&mut app.ui.toolbar_advanced); + crate::edit_toolbar::keep_strips(&mut app.ui); + on + } "window.toolsBesideCanvas" => opt_bool(p, "on").map(|on| { let on = on.unwrap_or(!app.ui.tools_beside_canvas); app.ui.tools_beside_canvas = on; diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rs index f8bce4e088..f3c0ed772c 100644 --- a/crates/ui-egui/src/state.rs +++ b/crates/ui-egui/src/state.rs @@ -1261,6 +1261,7 @@ impl UiState { sanitize_toolbar_pos(&mut self.toolbar_pos); sanitize_toolbar_pos(&mut self.control_bar_float_pos); crate::edit_toolbar::sanitize(&mut self.toolbar_edits); + crate::edit_toolbar::keep_strips(&mut self); // `read_preferences` converted the file's older layouts already; this covers a state read // any other way. What it reports lost was dropped there. let _ = crate::layout_migration::migrate_ui(&mut self); diff --git a/crates/ui-egui/src/toolbar.rs b/crates/ui-egui/src/toolbar.rs index a4846cd35b..a3499f5040 100644 --- a/crates/ui-egui/src/toolbar.rs +++ b/crates/ui-egui/src/toolbar.rs @@ -49,7 +49,7 @@ pub const BASIC: &[(&str, &[&[&str]])] = &[ &["pencil", "smooth", "pathEraser", "join"], &["eraser", "scissors", "knife", "trimAtCrossings", "mirrorCut", "lineCut", "rectCut"], &["paintbrush", "blobBrush"], - &["pen", "addAnchor", "deleteAnchor", "anchorPoint", "quickPen"], + &["pen", "addAnchor", "deleteAnchor", "anchorPoint", "quickPen", "smartPen"], &["curvature"], ], ), @@ -1100,6 +1100,10 @@ fn flyout(app: &mut VectorcraftApp, ctx: &egui::Context) { let released_on_bar = input.bar.as_ref().is_some_and(|b| ctx.input(|i| i.pointer.primary_released()) && at.is_some_and(|p| b.rect.contains(p))); let dragged_off = input.bar.as_ref().is_some_and(egui::Response::dragged) && press_travel(ctx).is_some_and(|d| d.length() > TEAR); if released_on_bar || dragged_off { + // A flyout opened before the layout changed shows the tools it was opened with; the strip + // gets the group's tools now. + let current = tools.first().filter(|_| toolbar.is_none()).and_then(|key| crate::edit_toolbar::layout_group(&app.ui, key)); + let tools = current.unwrap_or(tools); // The strip is far narrower than the flyout: it floats with its bar under the pointer. let at = at.unwrap_or(resp.response.rect.right_center()); // (Past the frame's 1 pt border.) diff --git a/crates/ui-egui/src/toolbar/tests.rs b/crates/ui-egui/src/toolbar/tests.rs index 4c8c25392d..1f52fece74 100644 --- a/crates/ui-egui/src/toolbar/tests.rs +++ b/crates/ui-egui/src/toolbar/tests.rs @@ -883,7 +883,12 @@ fn loaded_floating_flyouts_keep_known_tools_one_strip_per_group() { ..Default::default() }; let ui = ui.sanitized(); - assert_eq!(ui.floating_flyouts.iter().map(|f| f.tools.join(",")).collect::>(), ["pen,addAnchor"]); + // The one strip left shows the current layout's Pen group. + let pen = BASIC.iter().flat_map(|(_, slots)| slots.iter()).find(|s| s.first() == Some(&"pen")).map(|s| s.join(",")); + assert_eq!(ui.floating_flyouts.iter().map(|f| f.tools.join(",")).collect::>(), pen.into_iter().collect::>()); + // A strip whose group isn't in the layout keeps its known tools. + let ui = crate::state::UiState { floating_flyouts: vec![f(&["curvature", "nope", "addAnchor"])], ..Default::default() }.sanitized(); + assert_eq!(ui.floating_flyouts.iter().map(|f| f.tools.join(",")).collect::>(), ["curvature,addAnchor"]); } #[test] diff --git a/crates/ui-egui/src/workspaces.rs b/crates/ui-egui/src/workspaces.rs index c409b6b71a..c7efa332dc 100644 --- a/crates/ui-egui/src/workspaces.rs +++ b/crates/ui-egui/src/workspaces.rs @@ -278,6 +278,7 @@ pub fn apply(ui: &mut UiState, w: &Workspace) { } ui.flyout = None; ui.workspace = w.name.clone(); + crate::edit_toolbar::keep_strips(ui); } /// Keep the layout of the current workspace as it is now, so switching back brings it back. diff --git a/docs/control-protocol.md b/docs/control-protocol.md index dafab93a58..427ee3dcae 100644 --- a/docs/control-protocol.md +++ b/docs/control-protocol.md @@ -450,7 +450,9 @@ Floating tool groups: dragging or clicking the tear-off bar down a tool group's that opened it over the bar) floats the group as a strip of tool buttons, moved by the same bar and put back in the toolbar by the × at its top; `window.floatTools {tool, floating?}` does the same for the group of the current layout holding `tool` (omitted toggles; a tool alone in its slot is an error). While a group floats, the presses -that open its flyout raise the strip instead. The strips (`ui.floating_flyouts` in `ui.inspect`: the group's tools +that open its flyout raise the strip instead. A strip shows the tools of the current layout's group that starts +with the same tool, also after `toolbar.addTool`, `toolbar.removeTool`, `toolbar.reset`, `window.toolbarAdvanced`, loading the +preferences or switching workspaces; a strip with no such group keeps its tools. The strips (`ui.floating_flyouts` in `ui.inspect`: the group's tools and the strip's top-left corner) are saved with the preferences and in user workspaces; the built-in workspaces float none. diff --git a/docs/mcp.md b/docs/mcp.md index 3c577e0356..b031f71214 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -14975,8 +14975,8 @@ than 50000 anchors as it is. Smart Pen is a built-in add-on: one tool that draws paths and edits their points, handles and segments without switching tools. Its commands are `addon.pen.*`; in the desktop app it lives in Object › Plug-ins › Smart Pen, in its -panel (`window.panel {panel: "smartPen"}`) and in the Smart Pen Tool (`smartPen`), which the toolbars don't show until -it is added from the All Tools drawer (or chosen with `tool.select`); it has no shortcut. Each gesture and each command is +panel (`window.panel {panel: "smartPen"}`) and in the Smart Pen Tool (`smartPen`), which both shipped toolbars show in +the Pen tool's group, after the Quick Pen (`ui.tool.list` lists it there); it has no shortcut. Each gesture and each command is one undo step; an edit that changes nothing makes no step. The standard Pen tool is unchanged. The tool (`smartPen`), option `next`: `"straight"` (default) or `"curved"`, the segment a click adds: diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 3da663c191..8cb71c0365 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -2886,7 +2886,8 @@ ends), `addons::shared_edge` in `vectorcraft-tools`, `cmd::addons::pathtools::sh ## Smart Pen add-on (2026-10-30) A VectorCraft addition, not a feature of the reference app, so no area score moves. Object › Plug-ins › Smart Pen selects the -Smart Pen Tool (kept out of the shipped toolbars, listed in the All Tools drawer, no shortcut) and opens its panel. The +Smart Pen Tool (in the Pen tool's group in both shipped toolbars, after the Quick Pen, and under Draw in the All Tools +drawer; a toolbar edited before keeps its saved layout until Reset Toolbar; no shortcut) and opens its panel. The tool draws with a straight or curved next segment (a curve after a straight segment leaves it tangent), smooth drags with Alt, Shift and Space, Tab to switch a segment, a rubber band, closing, joining and continuing open ends; and edits without switching tools: point select, move, Alt-click remove keeping shape, Shift+Alt-click plain delete, double-click @@ -2895,7 +2896,10 @@ insert. The panel sets the next segment and runs Remove Points Keep Shape, Make Close or Join. Kernels: `vectorcraft_pathops::addons::pen` and the shared `addons::segment_reshape`. Tests: `addons::pen` and `addons::segment_reshape` in `vectorcraft-pathops`, `addons::smart_pen` in `vectorcraft-tools`, `cmd::addons::pen::tests` in `vectorcraft-engine` (each command one undo step, bad params refused, the tool's gestures -through the session) and `addons::pen::tests` in `vectorcraft-ui-egui` (the submenu, the panel). Commands: `docs/mcp.md` +through the session), `addons::pen::tests` in `vectorcraft-ui-egui` (the submenu, the panel), and for the toolbars +`smart_pen_is_in_the_pen_flyout` and `a_saved_toolbar_without_smart_pen_keeps_its_layout` in `edit_toolbar::tests` +in `vectorcraft-ui-egui`, `smart_pen_is_in_the_pen_group_once` in `addons::tests` in `vectorcraft-tools` and +`headless_backend_methods` in `vectorcraft-mcp`. Commands: `docs/mcp.md` › Smart Pen add-on. ## Color Effects add-on (2026-10-30) diff --git a/docs/ui-parity.md b/docs/ui-parity.md index e9fd857a9d..00e75dba5d 100644 --- a/docs/ui-parity.md +++ b/docs/ui-parity.md @@ -549,7 +549,7 @@ next unit in the order a right-click on a ruler lists them, from Feet back to Po | 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 | | Document Tools add-on (VectorCraft addition): Object › Plug-ins › Document Tools › New Symbols from Layers makes a symbol of each layer's art named after the layer (the highlighted layers when two or more are, else all); Convert Layers to Symbols also replaces each layer's art with an instance in place; empty layers skipped, one undo step | done | #4927; `addon.document.symbolsFromLayers`, `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 | -| Smart Pen add-on (VectorCraft addition): Object › Plug-ins › Smart Pen selects the Smart Pen Tool, which the All Tools drawer lists under its own heading but neither toolbar shows as shipped (no shortcut), and opens the Smart Pen panel (next segment straight or curved; Remove Points Keep Shape, Make Smooth, Make Corner, Retract Handles, Close or Join). The tool draws (click: straight or curved segment, a curve after a straight one tangent; drag: smooth anchor, Alt breaks the handle, Shift 45°, Space moves it; Tab switches a segment; rubber band; close, join, continue) and edits without switching tools (click selects a point, drag moves it, Alt-click removes it keeping the shape, Shift+Alt-click deletes it, double-click toggles smooth/corner; handle drags with Shift and Alt; segment drags reshape, Alt-click adds a point) | done | `addon.pen.*`, `crates/tools/src/addons/smart_pen.rs`, `crates/ui-egui/src/addons/pen.rs` and their tests; not a feature of the reference app, so it is not scored | +| Smart Pen add-on (VectorCraft addition): Object › Plug-ins › Smart Pen selects the Smart Pen Tool (also in the Pen tool's group in both shipped toolbars, after the Quick Pen; the All Tools drawer lists it under Draw; a toolbar edited before keeps its saved layout until Reset Toolbar; no shortcut), and opens the Smart Pen panel (next segment straight or curved; Remove Points Keep Shape, Make Smooth, Make Corner, Retract Handles, Close or Join). The tool draws (click: straight or curved segment, a curve after a straight one tangent; drag: smooth anchor, Alt breaks the handle, Shift 45°, Space moves it; Tab switches a segment; rubber band; close, join, continue) and edits without switching tools (click selects a point, drag moves it, Alt-click removes it keeping the shape, Shift+Alt-click deletes it, double-click toggles smooth/corner; handle drags with Shift and Alt; segment drags reshape, Alt-click adds a point) | done | `addon.pen.*`, `crates/tools/src/addons/smart_pen.rs`, `crates/ui-egui/src/addons/pen.rs` and their tests; not a feature of the reference app, so it is not scored | | Path Precision Tools add-on (VectorCraft addition): Object › Plug-ins › Path Precision Tools selects its nine tools (Anchor Eraser Brush, Extend Path, Measure & Inspect, Parametric Shape, Corner Tool, Slide Anchor Along Path, Shared Edge Merge Tool, Tangent Circle Tool, Trim at Crossings Tool), which the All Tools drawer lists under their own heading but neither toolbar shows as shipped (except Trim at Crossings, which both shipped toolbars and the drawer show in the Scissors tool's group), opens the Anchor Inspector panel (the selected anchor's X/Y and handle lengths and angles as fields; Make Smooth, Make Corner, Equalize Handles, Remove Points Keep Shape, Add Points, the three ways to close) and the Parametric Shape panel (kind, count, W/H, rotation, the kind's own values and corner radius of the selected parametric shape, or of the tool's next one), and runs Add Points at / Split at Crossings and Convert to Parametric Shape; the Parametric Shape Tool draws ten re-editable kinds from the centre (↑/↓ and ←/→ change their numbers while dragging) and edits a selected one with handles; the Corner Tool cuts editable corners on any path (hover shows the anchor, a click uses its radius and kind, a drag sizes the corner, Shift whole values; a corner's marker selects it and loads its values, drags to resize, to 0 or double-clicked removes it; never past what fits; Alt-marquee cuts every anchor inside) with a Corners section in the Anchor Inspector (radius, kind, selected count, Apply to Selected Anchors); Slide Anchor Along Path drags an anchor along its curve with the segments beside it refitted, Shift snapping where the tangent is a multiple of 45°; the Shared Edge Merge Tool shows, over two paths touching at two coincident anchors, the two stretches and the edge merging them, a click merges them (half way; Shift the upper path, Alt the lower), and near anchors meet or an anchor one path lacks is added to match (Shift+Alt asks for this inside a stretch), with a Shared Edges section in the Anchor Inspector (brush diameter, coincidence 0 to 3 pt, Keep Shared Points Together, which takes coincident anchors along with the add-on's own anchor moves); a double-click on the brush, Extend Path or Tangent Circle tool opens its options | done | `addon.pathtools.*`, `crates/tools/src/addons/`, `crates/ui-egui/src/addons/pathtools.rs`, `crates/ui-egui/src/addons/pathtools/` and their tests; not a feature of the reference app, so it is not scored | | Path Precision Tools add-on (VectorCraft addition): Object › Plug-ins › Path Precision Tools › Divide into Dashes… (Dash and Gap in any unit, Fit to Corners and Ends, Remove Gaps; Preview) cuts the selected paths, or only their direct-selected segments, into open pieces along the curve, keeping their appearance, one undo step | done | #4950; `addon.pathtools.divideDashes`, `crates/pathops/src/addons/pathtools/dashes.rs`, `crates/ui-egui/src/addons/pathtools/dashes.rs` and their tests; not a feature of the reference app, so it is not scored | | Path Precision Tools add-on (VectorCraft addition): Object › Plug-ins › Path Precision Tools › Set Corners… (also a button in the Anchor Inspector's Corners section: Radius in any unit, Corner kind, Anchors: All, Odd-Numbered or Even-Numbered, counted from each path's first anchor; Angle: from … to …°, only the corners whose sides meet at an angle in that range; Preview) cuts corners on the chosen anchors of every selected path, one undo step | done | #5546, #5545; `addon.pathtools.cornerSet` (`every`, `minAngle`, `maxAngle`), `crates/ui-egui/src/addons/pathtools/set_corners.rs` and their tests; not a feature of the reference app, so it is not scored | @@ -562,7 +562,7 @@ next unit in the order a right-click on a ruler lists them, from Feet back to Po | Path Precision Tools add-on (VectorCraft addition): Effect › Path Effects lists its live effects (Dashes to Geometry, Add Anchors, Extend Path, Close Path, Smooth Anchors, Retract Handles, Reverse Direction, Simplify Anchors, Split at Anchors), each with the effect dialog's live Preview except Reverse Direction, which has no options, and listed in the Appearance panel like any effect | done | `addon.path.*`, `crates/effects/src/addons/path.rs`, `crates/ui-egui/src/addons/pathtools.rs` and their tests; not a feature of the reference app, so it is not scored | | Path Precision Tools add-on (VectorCraft addition): Object › Plug-ins › Path Precision Tools selects its four tools (Anchor Eraser Brush, Extend Path, Measure & Inspect, Parametric Shape), which the All Tools drawer lists under their own heading but neither toolbar shows as shipped, opens the Anchor Inspector panel (the selected anchor's X/Y and handle lengths and angles as fields; Make Smooth, Make Corner, Equalize Handles, Remove Points Keep Shape, Add Points, the three ways to close) and the Parametric Shape panel (kind, count, W/H, rotation, the kind's own values and corner radius of the selected parametric shape, or of the tool's next one), and runs Add Points at / Split at Crossings and Convert to Parametric Shape; the Parametric Shape Tool draws ten re-editable kinds from the centre (↑/↓ and ←/→ change their numbers while dragging) and edits a selected one with handles; a double-click on the brush or Extend Path tool opens its options | done | `addon.pathtools.*`, `crates/tools/src/addons/`, `crates/ui-egui/src/addons/pathtools.rs`, `crates/ui-egui/src/addons/pathtools/shape.rs` and their tests; not a feature of the reference app, so it is not scored | | Path Precision Tools add-on (VectorCraft addition): Object › Plug-ins › Path Precision Tools selects its six tools (Anchor Eraser Brush, Extend Path, Measure & Inspect, Parametric Shape, Corner Tool, Slide Anchor Along Path), which the All Tools drawer lists under their own heading but neither toolbar shows as shipped, opens the Anchor Inspector panel (the selected anchor's X/Y and handle lengths and angles as fields; Make Smooth, Make Corner, Equalize Handles, Remove Points Keep Shape, Add Points, the three ways to close) and the Parametric Shape panel (kind, count, W/H, rotation, the kind's own values and corner radius of the selected parametric shape, or of the tool's next one), and runs Add Points at / Split at Crossings and Convert to Parametric Shape; the Parametric Shape Tool draws ten re-editable kinds from the centre (↑/↓ and ←/→ change their numbers while dragging) and edits a selected one with handles; the Corner Tool cuts editable corners on any path (hover shows the anchor, a click uses its radius and kind, a drag sizes the corner, Shift whole values; a corner's marker selects it and loads its values, drags to resize, to 0 or double-clicked removes it; never past what fits; Alt-marquee cuts every anchor inside) with a Corners section in the Anchor Inspector (radius, kind, selected count, Apply to Selected Anchors); Slide Anchor Along Path drags an anchor along its curve with the segments beside it refitted, Shift snapping where the tangent is a multiple of 45°; a double-click on the brush or Extend Path tool opens its options | done | `addon.pathtools.*`, `crates/tools/src/addons/`, `crates/ui-egui/src/addons/pathtools.rs`, `crates/ui-egui/src/addons/pathtools/` and their tests; not a feature of the reference app, so it is not scored | -| Smart Pen add-on (VectorCraft addition): Object › Plug-ins › Smart Pen selects the Smart Pen Tool, which the All Tools drawer lists under its own heading but neither toolbar shows as shipped (no shortcut), and opens the Smart Pen panel (next segment straight or curved; Remove Points Keep Shape, Make Smooth, Make Corner, Retract Handles, Close or Join). The tool draws (click: straight or curved segment, a curve after a straight one tangent; drag: smooth anchor, Alt breaks the handle, Shift 45°, Space moves it; Tab switches a segment; rubber band; close, join, continue) and edits without switching tools (click selects a point, drag moves it, Alt-click removes it keeping the shape, Shift+Alt-click deletes it, double-click toggles smooth/corner; handle drags with Shift and Alt; segment drags reshape, Alt-click adds a point); an Alt-drag away from paths selects the points inside a marquee | done | `addon.pen.*`, `crates/tools/src/addons/smart_pen.rs`, `crates/ui-egui/src/addons/pen.rs` and their tests; not a feature of the reference app, so it is not scored | +| Smart Pen add-on (VectorCraft addition): Object › Plug-ins › Smart Pen selects the Smart Pen Tool (also in the Pen tool's group in both shipped toolbars, after the Quick Pen; the All Tools drawer lists it under Draw; a toolbar edited before keeps its saved layout until Reset Toolbar; no shortcut), and opens the Smart Pen panel (next segment straight or curved; Remove Points Keep Shape, Make Smooth, Make Corner, Retract Handles, Close or Join). The tool draws (click: straight or curved segment, a curve after a straight one tangent; drag: smooth anchor, Alt breaks the handle, Shift 45°, Space moves it; Tab switches a segment; rubber band; close, join, continue) and edits without switching tools (click selects a point, drag moves it, Alt-click removes it keeping the shape, Shift+Alt-click deletes it, double-click toggles smooth/corner; handle drags with Shift and Alt; segment drags reshape, Alt-click adds a point); an Alt-drag away from paths selects the points inside a marquee | done | `addon.pen.*`, `crates/tools/src/addons/smart_pen.rs`, `crates/ui-egui/src/addons/pen.rs` and their tests; not a feature of the reference app, so it is not scored | | Path Precision Tools add-on (VectorCraft addition): Object › Plug-ins › Path Precision Tools selects its three tools (Anchor Eraser Brush, Extend Path, Measure & Inspect), which the All Tools drawer lists under their own heading but neither toolbar shows as shipped, opens the Anchor Inspector panel (the selected anchor's X/Y and handle lengths and angles as fields; Make Smooth, Make Corner, Equalize Handles, Remove Points Keep Shape, Add Points, the three ways to close) and runs Add Points at / Split at Crossings; a double-click on the brush or Extend Path tool opens its options | done | `addon.pathtools.*`, `crates/tools/src/addons/`, `crates/ui-egui/src/addons/pathtools.rs` and their tests; not a feature of the reference app, so it is not scored | | Artwork Cleanup add-on (VectorCraft addition): Object › Plug-ins › Artwork Cleanup opens its panel, which checks the selection or the document for 16 kinds of issue, lists them with counts, and shows or fixes the picked rows or all of them, each fix one undo step; Simplify Anchors (Keep Shape), Rejoin Path Pieces and Deep Ungroup open their options first | done | `addon.cleanup.*`, `crates/ui-egui/src/addons/cleanup.rs` and its tests; not a feature of the reference app, so it is not scored | | Artwork Cleanup add-on text tools (VectorCraft addition): the panel's Text row, which the panel can hide, and Object › Plug-ins › Artwork Cleanup set the alignment of point type keeping its place, break type into lines (Shift-click: paragraphs), words or glyphs, split type at the cursor, reset a text transform (Alt-click: and its horizontal scale), combine point type, remove line or paragraph breaks and replace missing fonts, each one undo step | done | `addon.cleanup.*` text commands, `crates/ui-egui/src/addons/cleanup.rs` and its tests; a VectorCraft addition, so it is not scored |