diff --git a/ROADMAP.md b/ROADMAP.md index 79ec54818f..90a6100167 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -148,6 +148,7 @@ Ranked; detail in [docs/roadmap.md](docs/roadmap.md) and [docs/gaps.md](docs/gap - 2026-11-17: Circle tool (after the Ellipse tool in its group): two clicks or a drag draw the circle on that diameter, and a click followed by a drag from a second point to a third draws the circle through the three; Shift keeps the diameter at 45° steps, Alt rounds a two-point circle's diameter to the rulers' ticks at the current zoom, points snap to Smart Guides, and the tool shows the circle, its center, its radii and its diameter until the release, or "Circle too large" for points on one line or a circle past the canvas. `shape.circleThroughPoints` also takes two points or two selected anchor points as the ends of a diameter. One undo step per circle. A VectorCraft addition: headline numbers unchanged. - 2026-11-17: Circle Tool Options (double-click the Circle tool): Show Center, Show Radii and Show Diameter switch what the tool shows while a circle is drawn, Color sets the color of the center cross and radius lines, Anchors at Standard Positions off puts the circle's anchors at the points it was drawn through (`shape.circleThroughPoints {anchors: "points"}`), and Third Point by Dragging off draws a three-point circle with three clicks and a two-point circle with a double-click on the second point. A VectorCraft addition: headline numbers unchanged. - 2026-11-19: Quick Pen tool, in the Pen tool's group (Alt+P, Option+P on macOS): clicks or drags add straight lines, continuous arcs or sharp-corner arcs; Alt tapped on its own switches the action, C flips the last arc, `[` and `]` size it, a click on the first point closes the path and a click on an open end continues it (`path.quickPen`, part of #2660). Headline numbers unchanged. +- 2026-11-19: Quick Pen toolbar on the canvas while the tool is active: Straight Line, Continuous Arc and Sharp Corner Arc, Flip Arc, and More Options with Hide Toolbar, Pin Toolbar Position and Reset Toolbar Position; it follows the drawing beside the path's last point and its handle drags it (`tool.quickPen.flipArc`, `window.quickPenToolbar`, Window › Quick Pen Toolbar; part of #2660). Headline numbers unchanged. - 2026-10-31: Pattern libraries: Window › Swatch Libraries › Patterns and the Swatches panel's library menu open Geometric Patterns, a built-in library of eleven pattern swatches (dots, stripes, checks, a grid and shapes); clicking one adds its pattern and swatch to the document, once, and applies it to the active fill or stroke (`swatch.library.add`). - 2026-11-11: Pattern libraries: Patterns › Grit Textures, a second built-in pattern library, holds eight seamless black textures (Fine Grain, Coarse Grit, Sand, Speckle, Stipple, Scratches, Sparse Flecks and Dense Flecks) on tiles of 18 to 36 pt, each drawn the same way every time; marks that reach past a tile edge continue on the next tile, so the tiles join without a seam (`swatch.library.add`). Scores and estimates unchanged. - 2026-11-11: Pattern libraries: Patterns › Optical Effects, a third built-in pattern library, of VectorCraft's own designs, holds eight black wave, moiré and op-art tiles (Sine Bands, Ripple Lines, Interference Rings, Offset Rings, Warped Checks, Pinched Stripes, Chevron Pulse and Radiating Lenses) of 32 to 48 pt, each drawn the same way every time; each tile is one period of its design, and art that reaches past a tile edge continues on the next tile, so the tiles join without a seam (`swatch.library.add`). Scores and estimates unchanged. diff --git a/crates/engine/src/tests/quickpen.rs b/crates/engine/src/tests/quickpen.rs index 033f51e0c5..f14be809b4 100644 --- a/crates/engine/src/tests/quickpen.rs +++ b/crates/engine/src/tests/quickpen.rs @@ -127,6 +127,25 @@ fn c_flips_and_brackets_size_the_last_sharp_arc() { assert!(!s.tool_claims_key(ToolKey::Letter('c'), view())); } +/// The drawing end (where the Quick Pen toolbar sits beside) is the path's last point with the +/// direction it arrives in: none before the first click, no direction for one point, and none +/// once Escape ends the path. +#[test] +fn the_drawing_end_is_the_last_point_and_its_direction() { + let mut s = session(); + quick_pen(&mut s); + assert_eq!(s.tool_drawing_end(view()), None); + click(&mut s, 100.0, 100.0); + assert_eq!(s.tool_drawing_end(view()), Some((pt(100.0, 100.0), None))); + click(&mut s, 100.0, 200.0); + let (p, dir) = s.tool_drawing_end(view()).unwrap(); + assert_eq!(p, pt(100.0, 200.0)); + let dir = dir.unwrap(); + assert!(dir.x.abs() < 1e-9 && dir.y > 0.99, "arrives heading down: {dir:?}"); + key(&mut s, ToolKey::Escape); + assert_eq!(s.tool_drawing_end(view()), None); +} + /// Alt tapped during a drag draws the piece with the next action: a continuous arc becomes a /// sharp-corner arc with a corner where it starts, and the path goes on drawing after it. #[test] diff --git a/crates/engine/src/tooling.rs b/crates/engine/src/tooling.rs index b6c90ee7a3..7b1caffb7c 100644 --- a/crates/engine/src/tooling.rs +++ b/crates/engine/src/tooling.rs @@ -1262,6 +1262,12 @@ impl Session { self.with_tool_cx(view, |t, cx| t.ends_on_escape(cx)) } + /// The point a path the active tool is drawing goes on from, and the direction the path + /// arrives there in (see `Tool::drawing_end`). + pub fn tool_drawing_end(&mut self, view: ViewInfo) -> Option<(Point, Option)> { + self.with_tool_cx(view, |t, cx| t.drawing_end(cx)) + } + pub fn overlays(&mut self, view: ViewInfo) -> Vec { // The Blend tool's first pick is not marked after an edit that dropped it. self.tell_tool_history_moved(); diff --git a/crates/mcp/src/ui_catalog.rs b/crates/mcp/src/ui_catalog.rs index f45c1387e2..64c57a6798 100644 --- a/crates/mcp/src/ui_catalog.rs +++ b/crates/mcp/src/ui_catalog.rs @@ -699,6 +699,25 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "", "{} show every Contextual Task Bar action and chip that Bar Actions turned off, as the bar's More Options › Reset Bar Actions does; returns the ids shown again", ), + ( + "window.quickPenToolbar", + "Quick Pen Toolbar", + "", + "{} show or hide the toolbar the Quick Pen tool shows on the canvas (toggles; returns whether it shows), as Window › Quick Pen Toolbar and the toolbar's More Options › Hide Toolbar do; selecting the Quick Pen tool shows it again", + ), + ( + "window.quickPenToolbar.pin", + "Pin Toolbar Position", + "", + "{pinned?: bool} keep the Quick Pen toolbar where it is in the canvas window instead of following the drawing (true), let it follow the drawing again from where it is (false) or toggle (omitted), as the toolbar's More Options menu does; returns the new state", + ), + ("window.quickPenToolbar.reset", "Reset Toolbar Position", "", "{} unpin the Quick Pen toolbar and put it back beside the drawing"), + ( + "tool.quickPen.flipArc", + "Flip Arc", + "", + "{} flip the last sharp-corner arc of the path the Quick Pen tool is drawing to the other side of its chord, as C and the toolbar's Flip Arc button do, as one undo step; first finishes any pending tool edit (which can change the document), then returns false, changing nothing more, when the Quick Pen tool is not active, no path is being drawn or the last piece is not a sharp-corner arc", + ), ( "window.dock", "Panels", diff --git a/crates/tools/src/lib.rs b/crates/tools/src/lib.rs index 9057b33cc3..688f295478 100644 --- a/crates/tools/src/lib.rs +++ b/crates/tools/src/lib.rs @@ -226,6 +226,12 @@ pub trait Tool: Send { fn ends_on_escape(&self, _cx: &ToolContext) -> bool { false } + /// The point a path the tool is drawing goes on from, and the direction the path arrives there + /// in (none for a path of one point), while the tool draws one: the Quick Pen toolbar sits + /// beside it. + fn drawing_end(&self, _cx: &ToolContext) -> Option<(Point, Option)> { + None + } /// Does the tool want typed text (Type tool editing)? Single-key shortcuts are suppressed. fn wants_text(&self) -> bool { false diff --git a/crates/tools/src/quickpen.rs b/crates/tools/src/quickpen.rs index 6c546aad0f..6368ba160b 100644 --- a/crates/tools/src/quickpen.rs +++ b/crates/tools/src/quickpen.rs @@ -577,6 +577,11 @@ impl Tool for QuickPenTool { self.active(cx).is_some() } + fn drawing_end(&self, cx: &ToolContext) -> Option<(Point, Option)> { + let (_, sp) = self.active(cx)?; + Some((sp.anchors.last()?.p, arrival(sp))) + } + fn claims_key(&self, cx: &ToolContext, key: ToolKey) -> bool { match key { ToolKey::Letter('c') => self.last_sharp_arc(cx).is_some(), diff --git a/crates/ui-egui/src/app/commands.rs b/crates/ui-egui/src/app/commands.rs index fc04c051fc..042e8b37a5 100644 --- a/crates/ui-egui/src/app/commands.rs +++ b/crates/ui-egui/src/app/commands.rs @@ -479,6 +479,10 @@ impl VectorcraftApp { if crate::touch::is_drawing_tool(now) { self.ui.touch_drawing_tool = Some(now.to_string()); } + // Selecting the Quick Pen tool shows its toolbar, even after Hide Toolbar. + if now == vectorcraft_tools::quickpen::ID { + self.ui.quick_pen_bar = true; + } Ok(()) } diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs index fe8b03b9f1..8b366665d4 100644 --- a/crates/ui-egui/src/canvas.rs +++ b/crates/ui-egui/src/canvas.rs @@ -28,6 +28,7 @@ mod input; mod outline; mod overlays; mod panes; +mod quick_pen_bar; mod raster; mod selection_marks; mod task_bar; @@ -68,6 +69,7 @@ use overlays::{ }; pub use panes::{Layout as TileLayout, Panes}; pub(crate) use panes::{consolidate, note_drop, noted_cursor, pane, release_on_noted, tile, tiled_area}; +pub(crate) use quick_pen_bar::quick_pen_bar_rect; pub(crate) use raster::{KeptFrame, color_image, color_image_owned, render_job}; use raster::{changed_pixels, frame_ppp, pixel_region, upload}; pub use selection_marks::SelectionMarks; @@ -463,6 +465,8 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { task_bar(app, ui, &xf); } if app.ui.screen_mode < 3 { + // The Quick Pen toolbar gives way to a drag as the task bar does. + quick_pen_bar::quick_pen_bar(app, ui, &xf); contour_bar::contour_bar(app, ui, &xf); // After the task bar, which the row of character alternates keeps clear of. alternates_bar::alternates_bar(app, ui, &xf); diff --git a/crates/ui-egui/src/canvas/quick_pen_bar.rs b/crates/ui-egui/src/canvas/quick_pen_bar.rs new file mode 100644 index 0000000000..fdca1884de --- /dev/null +++ b/crates/ui-egui/src/canvas/quick_pen_bar.rs @@ -0,0 +1,278 @@ +//! The Quick Pen toolbar: a floating bar on the canvas while the Quick Pen tool is active. It holds +//! the tool's actions (Straight Line, Continuous Arc, Sharp Corner Arc), Flip Arc for the last +//! sharp-corner arc, and a More Options menu with Hide Toolbar, Pin Toolbar Position and Reset +//! Toolbar Position. Its handle, at its left end, drags it. +//! +//! Public behavior: selecting the tool shows the toolbar, its actions decide what a click or drag +//! draws, Flip Arc flips the sharp-corner arc just drawn, the More menu hides the toolbar and resets +//! its position, and the toolbar moves by dragging its left side +//! ([Draw with the Quick Pen tool](https://helpx.adobe.com/illustrator/web/add-and-edit-artwork/draw-and-edit-paths/draw-with-quick-pen-tool.html)). +//! The toolbar follows the drawing, beside the point the path goes on from and away from what was +//! drawn ([Behind the design: the Quick Pen tool](https://adobe.design/ideas/behind-the-design-adobe-illustrator-s-quick-pen-tool)). +//! VectorCraft's own rules: the exact place beside the point, moving to the drawn side where the +//! other side runs off the canvas, the place with no path being drawn, how a drag's offset is kept, +//! Pin Toolbar Position (which holds the toolbar at its place in the canvas window, not on the +//! artboard), and Window › Quick Pen Toolbar to show it again. + +use vectorcraft_tools::quickpen::{self, Stroke as Action}; + +use super::{Color32, CornerRadius, Pos2, Sense, Stroke, Tokens, Ui, Vec2, VectorcraftApp, Xf, json, pos2, vec2, widgets}; + +/// The space between the point the path goes on from and the toolbar's nearest corner. +const GAP: f32 = 24.0; +/// The width of the toolbar's handle. +const HANDLE: f32 = 4.0; +/// The side of the toolbar's buttons. +const BUTTON: f32 = 28.0; +/// The space between the toolbar's controls. +const SPACING: f32 = 4.0; + +fn bar_id() -> egui::Id { + egui::Id::unique("quick-pen-bar") +} + +/// Where the Quick Pen toolbar was last drawn (none while it isn't shown). +pub(crate) fn quick_pen_bar_rect(ctx: &egui::Context) -> Option { + let id = bar_id(); + ctx.memory(|m| m.areas().is_visible(&egui::LayerId::new(egui::Order::Middle, id)).then(|| m.area_rect(id)).flatten()) +} + +/// The toolbar's top-left corner, of `size`, beside `end` (the point the path goes on from, on +/// screen), on the side the path arrives there from `dir` (on screen): to its right and below it +/// for a path drawn to the right and down, so the toolbar stays off what was drawn. A path of one +/// point puts it to the right and below. Where that side runs out of `room` (the canvas) and the +/// other side fits, it goes on the other side; where neither fits, on the side with more room. +/// Kept in `room` ([`keep_in`]), it covers `end` only when neither side fits across or down. +fn beside(end: Pos2, dir: Option, size: Vec2, room: egui::Rect) -> Pos2 { + // `first` unless it runs out of room and `other` fits or runs out by less. + let pick = |first: f32, other: f32, lo: f32, hi: f32, len: f32| { + let over = |p: f32| (lo - p).max(0.0) + (p + len - hi).max(0.0); + if over(other) < over(first) { other } else { first } + }; + let (right, left) = (end.x + GAP, end.x - GAP - size.x); + let (below, above) = (end.y + GAP, end.y - GAP - size.y); + let x = if dir.is_none_or(|d| d.x >= 0.0) { (right, left) } else { (left, right) }; + let y = if dir.is_none_or(|d| d.y >= 0.0) { (below, above) } else { (above, below) }; + pos2(pick(x.0, x.1, room.left(), room.right(), size.x), pick(y.0, y.1, room.top(), room.bottom(), size.y)) +} + +/// The toolbar's place with no path being drawn: centered at the bottom of the canvas area `room`. +fn resting(room: egui::Rect, size: Vec2) -> Pos2 { + pos2(room.center().x - size.x / 2.0, room.bottom() - size.y) +} + +/// `p` moved, as little as it takes, for a toolbar of `size` to lie inside `room`. +fn keep_in(p: Pos2, size: Vec2, room: egui::Rect) -> Pos2 { + p.clamp(room.min, (room.max - size).max(room.min)) +} + +/// Where an unpinned toolbar of `size` sits: `home` moved by the drag `offset`, kept in `room`, +/// unless that would cover `end` (the point the path goes on from, on screen), where it sits at +/// `home` as if never dragged. +fn unpinned(home: Pos2, offset: Vec2, end: Option, size: Vec2, room: egui::Rect) -> Pos2 { + let moved = keep_in(home + offset, size, room); + if end.is_some_and(|e| egui::Rect::from_min_size(moved, size).contains(e)) { keep_in(home, size, room) } else { moved } +} + +/// What a click on the toolbar does. +enum Click { + Action(Action), + Run(&'static str, serde_json::Value), +} + +/// Is a drag under way (past the drag threshold) that began on the canvas `canvas` outside the +/// toolbar's last place `bar`? A stroke, a Space or middle-button pan and a drag from a path's first +/// point all are; a drag of the toolbar's handle is not. +fn canvas_drag(dragging: bool, press: Option, canvas: egui::Rect, bar: Option) -> bool { + dragging && press.is_some_and(|p| canvas.contains(p) && !bar.is_some_and(|b| b.contains(p))) +} + +/// The Quick Pen toolbar, while the Quick Pen tool is active, Window › Quick Pen Toolbar is on and +/// no press is dragging on the canvas. Selecting the tool turns Window › Quick Pen Toolbar on +/// ([`VectorcraftApp::try_select_tool`]). +pub(super) fn quick_pen_bar(app: &mut VectorcraftApp, ui: &mut Ui, xf: &Xf) { + if !app.ui.quick_pen_bar || app.session.tool_id() != quickpen::ID { + return; + } + let (dragging, press, down) = ui.input(|i| (i.pointer.is_decidedly_dragging(), i.pointer.press_origin(), i.pointer.any_down())); + // The handle's drag moves the toolbar away from where the press began. + let handle_id = bar_id().with("handle"); + if !down { + ui.ctx().data_mut(|d| d.insert_temp(handle_id, false)); + } + let on_handle = ui.ctx().data(|d| d.get_temp::(handle_id)).unwrap_or(false); + let shown = app.ui.quick_pen_bar_place.shown_at.zip(egui::AreaState::load(ui.ctx(), bar_id()).and_then(|s| s.size)); + if canvas_drag(dragging && !on_handle, press, xf.rect, shown.map(|(at, size)| egui::Rect::from_min_size(xf.rect.min + at, size))) { + return; + } + let Some(doc) = app.session.active().map(|st| st.uid) else { return }; + let view = app.view_info(); + let end = app.session.tool_drawing_end(view); + let flip = app.session.tool_claims_key(vectorcraft_tools::ToolKey::Letter('c'), view); + let current = app.session.tool_options().get("action").and_then(serde_json::Value::as_str).and_then(Action::parse).unwrap_or_default(); + let t = Tokens::get(ui.ctx()); + let id = bar_id(); + let bounds = xf.rect.shrink(8.0); + let est = vec2(HANDLE + 5.0 * BUTTON + 6.0 * SPACING + 16.0, BUTTON + 12.0); + let size = egui::AreaState::load(ui.ctx(), id).and_then(|s| s.size).unwrap_or(est); + let end = end.map(|(p, dir)| { + let at = xf.to_screen(p); + (at, dir.map(|d| xf.to_screen(p + d) - at)) + }); + let drawing = end.is_some(); + let home = match end { + Some((at, dir)) => beside(at, dir, size, bounds), + None => resting(bounds, size), + }; + let place = &mut app.ui.quick_pen_bar_place; + // Just unpinned: follow the drawing from the pinned spot. + if !place.pinned + && let Some(at) = place.pin_at.take() + { + place.offset = Some((doc, drawing, xf.rect.min + at - home)); + } + // A drag's offset holds in the document and the kind of place (beside the drawing, or resting) + // it was made in. + let offset = place.offset.filter(|(d, beside, _)| *d == doc && *beside == drawing).map_or(Vec2::ZERO, |(_, _, o)| o); + let pos = match place.pin_at { + Some(at) => keep_in(xf.rect.min + at, size, bounds), + None => unpinned(home, offset, end.map(|(at, _)| at), size, bounds), + }; + place.shown_at = Some(pos - xf.rect.min); + // Pinned before it ever showed: hold it here. + if place.pinned && place.pin_at.is_none() { + place.pin_at = place.shown_at; + } + let pinned = place.pinned; + let mut moved = Vec2::ZERO; + let mut click: Option = None; + egui::Area::new(id).order(egui::Order::Middle).fixed_pos(pos).show(ui.ctx(), |ui| { + egui::Frame::NONE + .fill(t.panel) + .stroke(Stroke::new(1.0, t.tool_active)) + .corner_radius(CornerRadius::same(5)) + .inner_margin(egui::Margin::symmetric(8, 6)) + .shadow(egui::epaint::Shadow { offset: [0, 3], blur: 10, spread: 0, color: Color32::from_black_alpha(70) }) + .show(ui, |ui| { + // In a canvas pane narrower than the toolbar, its controls wrap onto more rows. + ui.set_max_width((bounds.width() - 18.0).max(HANDLE + SPACING + BUTTON)); + ui.horizontal_wrapped(|ui| { + ui.spacing_mut().item_spacing = vec2(SPACING, SPACING); + let (g, grip) = ui.allocate_exact_size(vec2(HANDLE, BUTTON), Sense::drag()); + let active = grip.hovered() || grip.dragged(); + ui.painter().rect_filled(g.shrink2(vec2(0.5, 4.0)), CornerRadius::same(2), if active { t.text_dim } else { t.button_border }); + if grip.dragged() { + ui.ctx().data_mut(|d| d.insert_temp(handle_id, true)); + ui.ctx().set_cursor_icon(egui::CursorIcon::Grabbing); + moved = grip.drag_delta(); + } else if grip.hovered() { + ui.ctx().set_cursor_icon(egui::CursorIcon::Grab); + } + let actions = [ + (Action::Line, "dc-line", tl!("Straight Line")), + (Action::ContinuousArc, "spline", tl!("Continuous Arc")), + (Action::SharpArc, "dc-arc", tl!("Sharp Corner Arc")), + ]; + for (action, icon, tip) in actions { + if widgets::icon_button(ui, icon, tip, current == action, BUTTON).clicked() { + click = Some(Click::Action(action)); + } + } + if widgets::icon_button_enabled(ui, "flip-horizontal-2", tl!("Flip Arc"), false, flip, BUTTON).clicked() { + click = Some(Click::Run("tool.quickPen.flipArc", json!({}))); + } + let more = widgets::icon_button(ui, "ellipsis", tl!("More Options"), false, BUTTON); + egui::Popup::menu(&more).show(|ui| { + ui.set_min_width(170.0); + let items = [ + (tl!("Hide Toolbar"), "window.quickPenToolbar", false), + (tl!("Pin Toolbar Position"), "window.quickPenToolbar.pin", pinned), + (tl!("Reset Toolbar Position"), "window.quickPenToolbar.reset", false), + ]; + for (label, cmd, checked) in items { + if widgets::menu_item(ui, label, true, checked) { + click = Some(Click::Run(cmd, json!({}))); + } + } + }); + }); + }); + }); + if moved != Vec2::ZERO { + let to = keep_in(pos + moved, size, bounds); + let place = &mut app.ui.quick_pen_bar_place; + if place.pinned { + place.pin_at = Some(to - xf.rect.min); + } else { + place.offset = Some((doc, drawing, to - home)); + } + ui.ctx().request_repaint(); + } + let r = match click { + Some(Click::Action(a)) => app.run("tool.setOption", json!({"key": "action", "value": a.name()})).map(|_| ()), + Some(Click::Run(cmd, p)) => app.run(cmd, p).map(|_| ()), + None => Ok(()), + }; + if let Err(e) = r { + app.ui.status = e; + } +} + +#[cfg(test)] +mod tests { + use super::*; + + /// The toolbar sits off what was drawn: ahead of a path drawn right and down, behind-left and + /// above for one drawn left and up, and to the right and below a single point. + #[test] + fn the_toolbar_sits_beside_the_end_away_from_the_drawing() { + let (end, size) = (pos2(500.0, 300.0), vec2(180.0, 40.0)); + let room = egui::Rect::from_min_max(pos2(8.0, 8.0), pos2(808.0, 608.0)); + assert_eq!(beside(end, Some(vec2(1.0, 0.0)), size, room), pos2(524.0, 324.0)); + assert_eq!(beside(end, Some(vec2(-1.0, -1.0)), size, room), pos2(500.0 - 24.0 - 180.0, 300.0 - 24.0 - 40.0)); + assert_eq!(beside(end, Some(vec2(0.0, 1.0)), size, room), pos2(524.0, 324.0)); + assert_eq!(beside(end, Some(vec2(-1.0, 0.5)), size, room), pos2(296.0, 324.0)); + assert_eq!(beside(end, None, size, room), pos2(524.0, 324.0)); + assert_eq!(resting(room, size), pos2(318.0, 568.0)); + // Near the canvas's bottom right corner, the side that runs off it gives way to the other. + let corner = pos2(700.0, 580.0); + assert_eq!(beside(corner, Some(vec2(1.0, 1.0)), size, room), pos2(700.0 - 24.0 - 180.0, 580.0 - 24.0 - 40.0)); + // Near the top left corner, a path heading up and left still gets a toolbar off its end. + let corner = pos2(30.0, 30.0); + assert_eq!(beside(corner, Some(vec2(-1.0, -1.0)), size, room), pos2(54.0, 54.0)); + // On a canvas too narrow for either side across, the toolbar goes on the side with more + // room and stays off the end by going below it. + let narrow = egui::Rect::from_min_max(pos2(8.0, 8.0), pos2(208.0, 608.0)); + let end = pos2(60.0, 300.0); + let at = keep_in(beside(end, Some(vec2(-1.0, 1.0)), size, narrow), size, narrow); + assert_eq!(at, pos2(28.0, 324.0)); + assert!(!egui::Rect::from_min_size(at, size).contains(end)); + } + + /// Any drag that began on the canvas hides the toolbar, whether or not the tool has a press + /// (a pan does not); a drag that began on the toolbar, and no drag, do not. + #[test] + fn a_drag_that_began_on_the_canvas_hides_the_toolbar() { + let canvas = egui::Rect::from_min_max(pos2(0.0, 0.0), pos2(800.0, 600.0)); + let bar = Some(egui::Rect::from_min_size(pos2(300.0, 500.0), vec2(180.0, 40.0))); + assert!(canvas_drag(true, Some(pos2(100.0, 100.0)), canvas, bar), "a pan or stroke on the canvas"); + assert!(canvas_drag(true, Some(pos2(100.0, 100.0)), canvas, None), "no toolbar shown yet"); + assert!(!canvas_drag(false, Some(pos2(100.0, 100.0)), canvas, bar), "a click, not a drag"); + assert!(!canvas_drag(true, Some(pos2(310.0, 510.0)), canvas, bar), "the toolbar's own drag"); + assert!(!canvas_drag(true, Some(pos2(900.0, 100.0)), canvas, bar), "a drag in another panel"); + assert!(!canvas_drag(true, None, canvas, bar)); + } + + /// A drag's offset moves the toolbar from its place, unless that would put it over the point + /// the path goes on from. + #[test] + fn a_dragged_toolbar_never_covers_the_end() { + let size = vec2(180.0, 40.0); + let room = egui::Rect::from_min_max(pos2(8.0, 8.0), pos2(808.0, 608.0)); + let (end, home) = (pos2(500.0, 300.0), pos2(524.0, 324.0)); + assert_eq!(unpinned(home, vec2(30.0, 40.0), Some(end), size, room), pos2(554.0, 364.0)); + assert_eq!(unpinned(home, vec2(-60.0, -40.0), Some(end), size, room), home, "over the end"); + assert_eq!(unpinned(home, vec2(-60.0, -40.0), None, size, room), pos2(464.0, 284.0)); + assert_eq!(unpinned(home, vec2(900.0, 0.0), Some(end), size, room), pos2(628.0, 324.0), "kept on the canvas"); + } +} diff --git a/crates/ui-egui/src/control.rs b/crates/ui-egui/src/control.rs index 6d2417a0fd..218312750d 100644 --- a/crates/ui-egui/src/control.rs +++ b/crates/ui-egui/src/control.rs @@ -268,6 +268,11 @@ pub fn inspect(app: &VectorcraftApp, ctx: &egui::Context) -> Value { "pinned": app.ui.task_bar_place.pinned, "rect": crate::canvas::task_bar_rect(ctx).map(|r| json!([r.left(), r.top(), r.width(), r.height()])), }, + // The Quick Pen toolbar: pinned (not saved either) and where it shows. + "quickPenToolbar": { + "pinned": app.ui.quick_pen_bar_place.pinned, + "rect": crate::canvas::quick_pen_bar_rect(ctx).map(|r| json!([r.left(), r.top(), r.width(), r.height()])), + }, // The Free Transform tool's widget, where it shows. "freeTransformWidget": crate::free_transform::rect(ctx).map(|r| json!([r.left(), r.top(), r.width(), r.height()])), "view": app.view().map(|v| serde_json::to_value(v).unwrap_or_default()), diff --git a/crates/ui-egui/src/i18n/bg.tsv b/crates/ui-egui/src/i18n/bg.tsv index dd6b662e2a..1ffb352a36 100644 --- a/crates/ui-egui/src/i18n/bg.tsv +++ b/crates/ui-egui/src/i18n/bg.tsv @@ -2714,6 +2714,13 @@ font-technology Variable Променливи Pen Tool Инструмент „Перо“ Quick Pen Tool Инструмент „Бързо перо“ Quick Pen Бързо перо + Quick Pen Toolbar Лента на бързото перо + Continuous Arc Непрекъсната дъга + Sharp Corner Arc Дъга с остър ъгъл + Flip Arc Обръщане на дъгата + Hide Toolbar Скриване на лентата с инструменти + Pin Toolbar Position Закачане на позицията на лентата с инструменти + Reset Toolbar Position Нулиране на позицията на лентата с инструменти Pencil Молив Pencil Tool Инструмент „Молив“ per slice на отрязък diff --git a/crates/ui-egui/src/i18n/bs.tsv b/crates/ui-egui/src/i18n/bs.tsv index 442d040e8d..712106379f 100644 --- a/crates/ui-egui/src/i18n/bs.tsv +++ b/crates/ui-egui/src/i18n/bs.tsv @@ -4219,6 +4219,13 @@ theme Appearance Izgled Pen Tool Alat pero Quick Pen Tool Alat brzo pero Quick Pen Brzo pero + Quick Pen Toolbar Traka Brzog pera + Continuous Arc Neprekidni luk + Sharp Corner Arc Luk s oštrim uglom + Flip Arc Preokreni luk + Hide Toolbar Sakrij traku s alatima + Pin Toolbar Position Prikvači položaj trake s alatima + Reset Toolbar Position Vrati položaj trake s alatima na početno Picas Pice Portuguese Portugalski Preserve Appearance and Overprints Očuvaj izgled i pretiske diff --git a/crates/ui-egui/src/i18n/ca.tsv b/crates/ui-egui/src/i18n/ca.tsv index d9bda69ac1..70b7cbf8ee 100644 --- a/crates/ui-egui/src/i18n/ca.tsv +++ b/crates/ui-egui/src/i18n/ca.tsv @@ -3470,6 +3470,13 @@ digits Malayalam Malaiàlam Pen Tool Eina de ploma Quick Pen Tool Eina de ploma ràpida Quick Pen Ploma ràpida + Quick Pen Toolbar Barra d’eines de la ploma ràpida + Continuous Arc Arc continu + Sharp Corner Arc Arc de cantonada aguda + Flip Arc Inverteix l’arc + Hide Toolbar Amaga la barra d’eines + Pin Toolbar Position Fixa la posició de la barra d’eines + Reset Toolbar Position Restableix la posició de la barra d’eines Pencil Llapis Pencil Tool Eina de llapis Pentagram Pentagrama diff --git a/crates/ui-egui/src/i18n/cs.tsv b/crates/ui-egui/src/i18n/cs.tsv index c9296beb23..9ef6f066e6 100644 --- a/crates/ui-egui/src/i18n/cs.tsv +++ b/crates/ui-egui/src/i18n/cs.tsv @@ -4326,6 +4326,13 @@ theme Appearance Motiv Pen Tool Nástroj Pero Quick Pen Tool Nástroj Rychlé pero Quick Pen Rychlé pero + Quick Pen Toolbar Panel nástrojů rychlého pera + Continuous Arc Plynulý oblouk + Sharp Corner Arc Oblouk s ostrým rohem + Flip Arc Překlopit oblouk + Hide Toolbar Skrýt panel nástrojů + Pin Toolbar Position Připnout polohu panelu nástrojů + Reset Toolbar Position Obnovit polohu panelu nástrojů Picas Pica Portuguese Portugalština Preserve Appearance and Overprints Zachovat vzhled a přetisky diff --git a/crates/ui-egui/src/i18n/da.tsv b/crates/ui-egui/src/i18n/da.tsv index 49cd18a0cb..0d8b14dba4 100644 --- a/crates/ui-egui/src/i18n/da.tsv +++ b/crates/ui-egui/src/i18n/da.tsv @@ -6783,6 +6783,13 @@ theme Appearance Udseende Pen Tool Pen-værktøj Quick Pen Tool Hurtigpen-værktøj Quick Pen Hurtigpen + Quick Pen Toolbar Hurtigpennens værktøjslinje + Continuous Arc Fortløbende bue + Sharp Corner Arc Bue med skarpt hjørne + Flip Arc Vend bue + Hide Toolbar Skjul værktøjslinjen + Pin Toolbar Position Fastgør værktøjslinjens placering + Reset Toolbar Position Nulstil værktøjslinjens placering Picas Pica Portuguese Portugisisk Preserve Appearance and Overprints Bevar udseende og overprint diff --git a/crates/ui-egui/src/i18n/de.tsv b/crates/ui-egui/src/i18n/de.tsv index 4772c05d08..bd04b8cc19 100644 --- a/crates/ui-egui/src/i18n/de.tsv +++ b/crates/ui-egui/src/i18n/de.tsv @@ -2776,6 +2776,13 @@ file-filter Templates Vorlagen Pen Tool Zeichenstift-Werkzeug Quick Pen Tool Schnellzeichenstift-Werkzeug Quick Pen Schnellzeichenstift + Quick Pen Toolbar Schnellzeichenstift-Werkzeugleiste + Continuous Arc Fortlaufender Bogen + Sharp Corner Arc Bogen mit scharfer Ecke + Flip Arc Bogen spiegeln + Hide Toolbar Werkzeugleiste ausblenden + Pin Toolbar Position Position der Werkzeugleiste fixieren + Reset Toolbar Position Position der Werkzeugleiste zurücksetzen Pencil Buntstift Pencil Tool Buntstift-Werkzeug per slice pro Slice diff --git a/crates/ui-egui/src/i18n/el.tsv b/crates/ui-egui/src/i18n/el.tsv index 9b5c6b8186..220e9dede3 100644 --- a/crates/ui-egui/src/i18n/el.tsv +++ b/crates/ui-egui/src/i18n/el.tsv @@ -2180,6 +2180,13 @@ font-technology Variable Μεταβλητές Pen Tool Πένα (Pen Tool) Quick Pen Tool Εργαλείο γρήγορης πένας Quick Pen Γρήγορη πένα + Quick Pen Toolbar Γραμμή εργαλείων γρήγορης πένας + Continuous Arc Συνεχές τόξο + Sharp Corner Arc Τόξο με αιχμηρή γωνία + Flip Arc Αναστροφή τόξου + Hide Toolbar Απόκρυψη γραμμής εργαλείων + Pin Toolbar Position Σταθεροποίηση θέσης γραμμής εργαλείων + Reset Toolbar Position Επαναφορά θέσης γραμμής εργαλείων Pencil Μολύβι Pencil Tool Μολύβι (Pencil Tool) Percent: Ποσοστό: diff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsv index 23ba04351f..016f297b3b 100644 --- a/crates/ui-egui/src/i18n/es.tsv +++ b/crates/ui-egui/src/i18n/es.tsv @@ -2817,6 +2817,13 @@ font-technology Variable Variables Pen Tool Herramienta Pluma Quick Pen Tool Herramienta Pluma rápida Quick Pen Pluma rápida + Quick Pen Toolbar Barra de herramientas de Pluma rápida + Continuous Arc Arco continuo + Sharp Corner Arc Arco de esquina aguda + Flip Arc Voltear arco + Hide Toolbar Ocultar barra de herramientas + Pin Toolbar Position Fijar posición de la barra de herramientas + Reset Toolbar Position Restablecer posición de la barra de herramientas Pencil Lápiz Pencil Tool Herramienta Lápiz per slice por sector diff --git a/crates/ui-egui/src/i18n/fi.tsv b/crates/ui-egui/src/i18n/fi.tsv index c3c3cb3d6d..46b3fbf1d5 100644 --- a/crates/ui-egui/src/i18n/fi.tsv +++ b/crates/ui-egui/src/i18n/fi.tsv @@ -4243,6 +4243,13 @@ theme Appearance Ulkoasu Pen Tool Kynätyökalu Quick Pen Tool Pikakynätyökalu Quick Pen Pikakynä + Quick Pen Toolbar Pikakynän työkalurivi + Continuous Arc Jatkuva kaari + Sharp Corner Arc Terävän kulman kaari + Flip Arc Käännä kaari + Hide Toolbar Piilota työkalurivi + Pin Toolbar Position Kiinnitä työkalurivin sijainti + Reset Toolbar Position Palauta työkalurivin sijainti Picas Picat Portuguese Portugali Preserve Appearance and Overprints Säilytä ulkoasu ja päällepainatukset diff --git a/crates/ui-egui/src/i18n/fr.tsv b/crates/ui-egui/src/i18n/fr.tsv index 575c8e76a8..4ce31cfc06 100644 --- a/crates/ui-egui/src/i18n/fr.tsv +++ b/crates/ui-egui/src/i18n/fr.tsv @@ -2805,6 +2805,13 @@ font-technology Variable Variables Pen Tool Outil Plume Quick Pen Tool Outil Plume rapide Quick Pen Plume rapide + Quick Pen Toolbar Barre d’outils Plume rapide + Continuous Arc Arc continu + Sharp Corner Arc Arc à angle vif + Flip Arc Retourner l’arc + Hide Toolbar Masquer la barre d’outils + Pin Toolbar Position Épingler la position de la barre d’outils + Reset Toolbar Position Réinitialiser la position de la barre d’outils Pencil Crayon Pencil Tool Outil Crayon per slice par tranche diff --git a/crates/ui-egui/src/i18n/gu.tsv b/crates/ui-egui/src/i18n/gu.tsv index c0747ef65c..f1ad753245 100644 --- a/crates/ui-egui/src/i18n/gu.tsv +++ b/crates/ui-egui/src/i18n/gu.tsv @@ -2823,6 +2823,13 @@ Pen Tool પેન ટૂલ Quick Pen Tool ક્વિક પેન ટૂલ Quick Pen ક્વિક પેન + Quick Pen Toolbar ક્વિક પેન ટૂલબાર + Continuous Arc સતત આર્ક + Sharp Corner Arc તીક્ષ્ણ ખૂણાવાળો આર્ક + Flip Arc આર્ક ફ્લિપ કરો + Hide Toolbar ટૂલબાર છુપાવો + Pin Toolbar Position ટૂલબાર સ્થિતિ પિન કરો + Reset Toolbar Position ટૂલબાર સ્થિતિ રીસેટ કરો Pencil પેન્સિલ Pencil Tool પેન્સિલ ટૂલ Percent: ટકા: diff --git a/crates/ui-egui/src/i18n/hi.tsv b/crates/ui-egui/src/i18n/hi.tsv index aadea1276c..c8852f1ddd 100644 --- a/crates/ui-egui/src/i18n/hi.tsv +++ b/crates/ui-egui/src/i18n/hi.tsv @@ -4017,6 +4017,13 @@ arrowhead Feather पंख Pen Tool पेन टूल Quick Pen Tool क्विक पेन टूल Quick Pen क्विक पेन + Quick Pen Toolbar क्विक पेन टूलबार + Continuous Arc सतत आर्क + Sharp Corner Arc तीखे कोने वाला आर्क + Flip Arc आर्क पलटें + Hide Toolbar टूलबार छिपाएँ + Pin Toolbar Position टूलबार स्थिति पिन करें + Reset Toolbar Position टूलबार स्थिति रीसेट करें Pencil पेंसिल Pencil Tool पेंसिल टूल Pentagram पेंटाग्राम diff --git a/crates/ui-egui/src/i18n/hu.tsv b/crates/ui-egui/src/i18n/hu.tsv index f787652bfd..54ff192eed 100644 --- a/crates/ui-egui/src/i18n/hu.tsv +++ b/crates/ui-egui/src/i18n/hu.tsv @@ -3346,6 +3346,13 @@ file-filter Templates Sablonok Pen Tool Toll Quick Pen Tool Gyorstoll Quick Pen Gyorstoll + Quick Pen Toolbar Gyorstoll eszköztár + Continuous Arc Folytonos ív + Sharp Corner Arc Éles sarkú ív + Flip Arc Ív tükrözése + Hide Toolbar Eszköztár elrejtése + Pin Toolbar Position Eszköztár helyének rögzítése + Reset Toolbar Position Eszköztár helyének visszaállítása Pencil Ceruza Pencil Tool Ceruza Pentagram Pentagram diff --git a/crates/ui-egui/src/i18n/id.tsv b/crates/ui-egui/src/i18n/id.tsv index a8713b1bbc..9a0f622d21 100644 --- a/crates/ui-egui/src/i18n/id.tsv +++ b/crates/ui-egui/src/i18n/id.tsv @@ -4651,6 +4651,13 @@ theme Appearance Tampilan Pen Tool Alat pena Quick Pen Tool Alat pena cepat Quick Pen Pena cepat + Quick Pen Toolbar Bilah alat Pena cepat + Continuous Arc Busur bersambung + Sharp Corner Arc Busur sudut tajam + Flip Arc Balik busur + Hide Toolbar Sembunyikan bilah alat + Pin Toolbar Position Sematkan posisi bilah alat + Reset Toolbar Position Atur ulang posisi bilah alat Picas Pica Portuguese Portugis Preserve Appearance and Overprints Pertahankan tampilan dan overprint diff --git a/crates/ui-egui/src/i18n/it.tsv b/crates/ui-egui/src/i18n/it.tsv index 270e9f9679..190b136a06 100644 --- a/crates/ui-egui/src/i18n/it.tsv +++ b/crates/ui-egui/src/i18n/it.tsv @@ -2861,6 +2861,13 @@ file-filter Templates Modelli Pen Tool Strumento Penna Quick Pen Tool Strumento Penna rapida Quick Pen Penna rapida + Quick Pen Toolbar Barra degli strumenti Penna rapida + Continuous Arc Arco continuo + Sharp Corner Arc Arco ad angolo vivo + Flip Arc Capovolgi arco + Hide Toolbar Nascondi barra degli strumenti + Pin Toolbar Position Fissa posizione barra degli strumenti + Reset Toolbar Position Ripristina posizione barra degli strumenti Pencil Matita Pencil Tool Strumento Matita per slice per sezione diff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsv index 075d02f7de..665e74c319 100644 --- a/crates/ui-egui/src/i18n/ja.tsv +++ b/crates/ui-egui/src/i18n/ja.tsv @@ -2951,6 +2951,13 @@ antiAlias Sharp シャープ Pen Tool ペンツール Quick Pen Tool クイックペンツール Quick Pen クイックペン + Quick Pen Toolbar クイックペンツールバー + Continuous Arc 連続円弧 + Sharp Corner Arc 鋭角円弧 + Flip Arc 円弧を反転 + Hide Toolbar ツールバーを隠す + Pin Toolbar Position ツールバーの位置を固定 + Reset Toolbar Position ツールバーの位置をリセット Pencil 鉛筆 Pencil Tool 鉛筆ツール Percent: パーセント: diff --git a/crates/ui-egui/src/i18n/ka.tsv b/crates/ui-egui/src/i18n/ka.tsv index 3800505653..d3ea2160c1 100644 --- a/crates/ui-egui/src/i18n/ka.tsv +++ b/crates/ui-egui/src/i18n/ka.tsv @@ -6064,6 +6064,13 @@ theme Appearance იერსახე Pen Tool კალმის ხელსაწყო Quick Pen Tool სწრაფი კალმის ხელსაწყო Quick Pen სწრაფი კალამი + Quick Pen Toolbar სწრაფი კალმის ხელსაწყოთა ზოლი + Continuous Arc უწყვეტი რკალი + Sharp Corner Arc მახვილკუთხიანი რკალი + Flip Arc რკალის არეკვლა + Hide Toolbar ხელსაწყოთა ზოლის დამალვა + Pin Toolbar Position ხელსაწყოთა ზოლის პოზიციის ჩამაგრება + Reset Toolbar Position ხელსაწყოთა ზოლის პოზიციის ჩამოყრა Picas პიკები Portuguese პორტუგალიური Preserve Appearance and Overprints იერსახისა და ზედდაბეჭდვების შენარჩუნება diff --git a/crates/ui-egui/src/i18n/ko.tsv b/crates/ui-egui/src/i18n/ko.tsv index 3fbca77157..0c2642f758 100644 --- a/crates/ui-egui/src/i18n/ko.tsv +++ b/crates/ui-egui/src/i18n/ko.tsv @@ -2941,6 +2941,13 @@ antiAlias Sharp 날카롭게 Pen Tool 펜 도구 Quick Pen Tool 빠른 펜 도구 Quick Pen 빠른 펜 + Quick Pen Toolbar 빠른 펜 도구 모음 + Continuous Arc 연속 호 + Sharp Corner Arc 뾰족한 모서리 호 + Flip Arc 호 뒤집기 + Hide Toolbar 도구 모음 숨기기 + Pin Toolbar Position 도구 모음 위치 고정 + Reset Toolbar Position 도구 모음 위치 재설정 Pencil 연필 Pencil Tool 연필 도구 Percent: 퍼센트: diff --git a/crates/ui-egui/src/i18n/nl.tsv b/crates/ui-egui/src/i18n/nl.tsv index ee6f7510d1..c1f7e36426 100644 --- a/crates/ui-egui/src/i18n/nl.tsv +++ b/crates/ui-egui/src/i18n/nl.tsv @@ -4651,6 +4651,13 @@ theme Appearance Vormgeving Pen Tool Pen-gereedschap Quick Pen Tool Snelpen-gereedschap Quick Pen Snelpen + Quick Pen Toolbar Snelpen-werkbalk + Continuous Arc Doorlopende boog + Sharp Corner Arc Boog met scherpe hoek + Flip Arc Boog spiegelen + Hide Toolbar Werkbalk verbergen + Pin Toolbar Position Werkbalkpositie vastzetten + Reset Toolbar Position Werkbalkpositie herstellen Picas Pica's Portuguese Portugees Preserve Appearance and Overprints Vormgeving en overprint behouden diff --git a/crates/ui-egui/src/i18n/pl.tsv b/crates/ui-egui/src/i18n/pl.tsv index 2a47dd37ee..5808ddb8c2 100644 --- a/crates/ui-egui/src/i18n/pl.tsv +++ b/crates/ui-egui/src/i18n/pl.tsv @@ -4191,6 +4191,13 @@ theme Appearance Wygląd Pen Tool Narzędzie Pióro Quick Pen Tool Narzędzie Szybkie pióro Quick Pen Szybkie pióro + Quick Pen Toolbar Pasek narzędzi szybkiego pióra + Continuous Arc Łuk ciągły + Sharp Corner Arc Łuk z ostrym narożnikiem + Flip Arc Odwróć łuk + Hide Toolbar Ukryj pasek narzędzi + Pin Toolbar Position Przypnij położenie paska narzędzi + Reset Toolbar Position Resetuj położenie paska narzędzi Picas Pica Portuguese Portugalski Preserve Appearance and Overprints Zachowaj wygląd i nadruki diff --git a/crates/ui-egui/src/i18n/pt-br.tsv b/crates/ui-egui/src/i18n/pt-br.tsv index dfe335e174..2204a2bdc1 100644 --- a/crates/ui-egui/src/i18n/pt-br.tsv +++ b/crates/ui-egui/src/i18n/pt-br.tsv @@ -2319,6 +2319,13 @@ antiAlias Sharp Nítido Pen Tool Ferramenta Caneta Quick Pen Tool Ferramenta Caneta rápida Quick Pen Caneta rápida + Quick Pen Toolbar Barra de Ferramentas da Caneta rápida + Continuous Arc Arco Contínuo + Sharp Corner Arc Arco de Canto Agudo + Flip Arc Virar Arco + Hide Toolbar Ocultar Barra de Ferramentas + Pin Toolbar Position Fixar Posição da Barra de Ferramentas + Reset Toolbar Position Redefinir Posição da Barra de Ferramentas Pencil Lápis Pencil Tool Ferramenta Lápis Percent: Porcentagem: diff --git a/crates/ui-egui/src/i18n/ru.tsv b/crates/ui-egui/src/i18n/ru.tsv index 0adcd698ff..b3ca5d5d93 100644 --- a/crates/ui-egui/src/i18n/ru.tsv +++ b/crates/ui-egui/src/i18n/ru.tsv @@ -2843,6 +2843,13 @@ file-filter Templates Шаблоны Pen Tool Инструмент «Перо» Quick Pen Tool Инструмент «Быстрое перо» Quick Pen Быстрое перо + Quick Pen Toolbar Панель быстрого пера + Continuous Arc Непрерывная дуга + Sharp Corner Arc Дуга с острым углом + Flip Arc Отразить дугу + Hide Toolbar Скрыть панель инструментов + Pin Toolbar Position Закрепить положение панели инструментов + Reset Toolbar Position Сбросить положение панели инструментов Pencil Карандаш Pencil Tool Инструмент «Карандаш» per slice на фрагмент diff --git a/crates/ui-egui/src/i18n/sv.tsv b/crates/ui-egui/src/i18n/sv.tsv index 11ffb187f1..94a83ef975 100644 --- a/crates/ui-egui/src/i18n/sv.tsv +++ b/crates/ui-egui/src/i18n/sv.tsv @@ -2738,6 +2738,13 @@ font-technology Variable Variabla Pen Tool Pennverktyg Quick Pen Tool Snabbpennverktyg Quick Pen Snabbpenna + Quick Pen Toolbar Snabbpennans verktygsfält + Continuous Arc Kontinuerlig båge + Sharp Corner Arc Båge med skarpt hörn + Flip Arc Vänd båge + Hide Toolbar Dölj verktygsfältet + Pin Toolbar Position Fäst verktygsfältets position + Reset Toolbar Position Återställ verktygsfältets position Pencil Blyertspenna Pencil Tool Blyertsverktyg per slice per skiva diff --git a/crates/ui-egui/src/i18n/tr.tsv b/crates/ui-egui/src/i18n/tr.tsv index 36e6b490d9..2fcd6d3b54 100644 --- a/crates/ui-egui/src/i18n/tr.tsv +++ b/crates/ui-egui/src/i18n/tr.tsv @@ -2587,6 +2587,13 @@ shape Open Açık Pen Tool Kalem Aracı Quick Pen Tool Hızlı Kalem Aracı Quick Pen Hızlı Kalem + Quick Pen Toolbar Hızlı Kalem Araç Çubuğu + Continuous Arc Sürekli Yay + Sharp Corner Arc Keskin Köşeli Yay + Flip Arc Yayı Çevir + Hide Toolbar Araç Çubuğunu Gizle + Pin Toolbar Position Araç Çubuğu Konumunu Sabitle + Reset Toolbar Position Araç Çubuğu Konumunu Sıfırla Pencil Kalem Pencil Tool Kurşun Kalem Aracı per slice dilim başına diff --git a/crates/ui-egui/src/i18n/uk.tsv b/crates/ui-egui/src/i18n/uk.tsv index f5d9f57981..49f8383268 100644 --- a/crates/ui-egui/src/i18n/uk.tsv +++ b/crates/ui-egui/src/i18n/uk.tsv @@ -2853,6 +2853,13 @@ file-filter Templates Шаблони Pen Tool Інструмент «Перо» Quick Pen Tool Інструмент «Швидке перо» Quick Pen Швидке перо + Quick Pen Toolbar Панель швидкого пера + Continuous Arc Неперервна дуга + Sharp Corner Arc Дуга з гострим кутом + Flip Arc Відобразити дугу + Hide Toolbar Сховати панель інструментів + Pin Toolbar Position Закріпити положення панелі інструментів + Reset Toolbar Position Скинути положення панелі інструментів Pencil Олівець Pencil Tool Інструмент «Олівець» per slice на фрагмент diff --git a/crates/ui-egui/src/i18n/vi.tsv b/crates/ui-egui/src/i18n/vi.tsv index f89cf08d6a..13d02e5184 100644 --- a/crates/ui-egui/src/i18n/vi.tsv +++ b/crates/ui-egui/src/i18n/vi.tsv @@ -3166,6 +3166,13 @@ digits Hindi Hindi Pen Tool Công cụ Bút Quick Pen Tool Công cụ Bút nhanh Quick Pen Bút nhanh + Quick Pen Toolbar Thanh công cụ Bút nhanh + Continuous Arc Cung liên tục + Sharp Corner Arc Cung góc nhọn + Flip Arc Lật cung + Hide Toolbar Ẩn thanh công cụ + Pin Toolbar Position Ghim vị trí thanh công cụ + Reset Toolbar Position Đặt lại vị trí thanh công cụ Pencil Bút chì Pencil Tool Công cụ Bút chì per slice mỗi lát cắt diff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsv index 617d722dd5..f51baaa7e7 100644 --- a/crates/ui-egui/src/i18n/zh-hans.tsv +++ b/crates/ui-egui/src/i18n/zh-hans.tsv @@ -2704,6 +2704,13 @@ file-filter Templates 模板 Pen Tool 钢笔工具 Quick Pen Tool 快速钢笔工具 Quick Pen 快速钢笔 + Quick Pen Toolbar 快速钢笔工具栏 + Continuous Arc 连续弧线 + Sharp Corner Arc 尖角弧线 + Flip Arc 翻转弧线 + Hide Toolbar 隐藏工具栏 + Pin Toolbar Position 固定工具栏位置 + Reset Toolbar Position 重置工具栏位置 Pencil 铅笔 Pencil Tool 铅笔工具 per slice 每个切片 diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsv index 9fb4e824f2..d794ea15d9 100644 --- a/crates/ui-egui/src/i18n/zh-hant.tsv +++ b/crates/ui-egui/src/i18n/zh-hant.tsv @@ -4147,6 +4147,13 @@ liquify-list-end {0}, {1} {0}和{1} Pen Tool 筆型工具 Quick Pen Tool 快速筆型工具 Quick Pen 快速筆型 + Quick Pen Toolbar 快速筆型工具列 + Continuous Arc 連續弧線 + Sharp Corner Arc 尖角弧線 + Flip Arc 翻轉弧線 + Hide Toolbar 隱藏工具列 + Pin Toolbar Position 釘選工具列位置 + Reset Toolbar Position 重設工具列位置 Pencil 鉛筆 Pencil Tool 鉛筆工具 per slice 每個切片 diff --git a/crates/ui-egui/src/menus/run.rs b/crates/ui-egui/src/menus/run.rs index fcccdb5f00..8c2767e20b 100644 --- a/crates/ui-egui/src/menus/run.rs +++ b/crates/ui-egui/src/menus/run.rs @@ -687,6 +687,44 @@ fn run_ui_part6(app: &mut VectorcraftApp, id: &str, p: &Value) -> Option Ok(json!(std::mem::take(&mut app.ui.task_bar_hidden_actions))), + "window.quickPenToolbar" => flag(&mut app.ui.quick_pen_bar), + "window.quickPenToolbar.pin" => { + let place = &mut app.ui.quick_pen_bar_place; + opt_bool(p, "pinned").map(|pinned| { + let pinned = pinned.unwrap_or(!place.pinned); + if pinned && !place.pinned { + place.pin_at = place.shown_at; + } + place.pinned = pinned; + json!(pinned) + }) + } + "window.quickPenToolbar.reset" => { + app.ui.quick_pen_bar_place = Default::default(); + Ok(Value::Null) + } + "tool.quickPen.flipArc" => { + // C's flip, for the toolbar's Flip Arc button: false, with nothing changed beyond the + // edit finished first, while the last piece of the path being drawn is not a sharp-corner + // arc. Input held for an edit is finished first, so the key is made now rather than + // held; when that fails the error is returned and the flip is not made. + match app.session.finish_tool_edit() { + Ok(reqs) => crate::canvas::apply_requests(app, Ok(reqs)), + Err(e) => return Some(Err(e.to_string())), + } + let view = app.view_info(); + let key = vectorcraft_tools::ToolKey::Letter('c'); + if app.session.tool_id() != vectorcraft_tools::quickpen::ID || !app.session.tool_claims_key(key, view) { + return Some(Ok(json!(false))); + } + match app.session.tool_key(key, vectorcraft_tools::Mods::default(), view) { + Ok(reqs) => { + crate::canvas::apply_requests(app, Ok(reqs)); + Ok(json!(true)) + } + Err(e) => Err(e.to_string()), + } + } "window.dock" => { let ui = &mut app.ui; // The bars the last Tab hid show again, unless the toolbar or the Control bar was shown diff --git a/crates/ui-egui/src/menus/state.rs b/crates/ui-egui/src/menus/state.rs index 6cf32a6546..3fc578d754 100644 --- a/crates/ui-egui/src/menus/state.rs +++ b/crates/ui-egui/src/menus/state.rs @@ -99,6 +99,8 @@ pub fn checked(app: &VectorcraftApp, id: &str, p: &Value) -> Option { .get("action") .and_then(Value::as_str) .is_some_and(|a| crate::canvas::is_task_bar_action(a) && !app.ui.task_bar_hidden_actions.contains(a)), + "window.quickPenToolbar" => app.ui.quick_pen_bar, + "window.quickPenToolbar.pin" => app.ui.quick_pen_bar_place.pinned, "window.learn" => crate::panels::learn::visible(&app.ui), "window.panel" => { let panel = p.get("panel").and_then(Value::as_str).unwrap_or(""); diff --git a/crates/ui-egui/src/menus/tree.rs b/crates/ui-egui/src/menus/tree.rs index c2dd0ee991..3e68b98c92 100644 --- a/crates/ui-egui/src/menus/tree.rs +++ b/crates/ui-egui/src/menus/tree.rs @@ -685,6 +685,7 @@ pub fn menu_tree_named(english_names: bool) -> Vec<(&'static str, Vec)> { c("Control", "window.control"), c("Help Bar", "window.helpBar"), c("Contextual Task Bar", "window.taskBar"), + c("Quick Pen Toolbar", "window.quickPenToolbar"), c("Tools", "window.toolbar"), sub("Toolbars", crate::custom_toolbars::menu_items()), Sep, diff --git a/crates/ui-egui/src/menus/ui_commands.rs b/crates/ui-egui/src/menus/ui_commands.rs index f40d4b02b9..ad562ecd6c 100644 --- a/crates/ui-egui/src/menus/ui_commands.rs +++ b/crates/ui-egui/src/menus/ui_commands.rs @@ -700,6 +700,25 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "", "{} show every Contextual Task Bar action and chip that Bar Actions turned off, as the bar's More Options › Reset Bar Actions does; returns the ids shown again", ), + ( + "window.quickPenToolbar", + "Quick Pen Toolbar", + "", + "{} show or hide the toolbar the Quick Pen tool shows on the canvas (toggles; returns whether it shows), as Window › Quick Pen Toolbar and the toolbar's More Options › Hide Toolbar do; selecting the Quick Pen tool shows it again", + ), + ( + "window.quickPenToolbar.pin", + "Pin Toolbar Position", + "", + "{pinned?: bool} keep the Quick Pen toolbar where it is in the canvas window instead of following the drawing (true), let it follow the drawing again from where it is (false) or toggle (omitted), as the toolbar's More Options menu does; returns the new state", + ), + ("window.quickPenToolbar.reset", "Reset Toolbar Position", "", "{} unpin the Quick Pen toolbar and put it back beside the drawing"), + ( + "tool.quickPen.flipArc", + "Flip Arc", + "", + "{} flip the last sharp-corner arc of the path the Quick Pen tool is drawing to the other side of its chord, as C and the toolbar's Flip Arc button do, as one undo step; first finishes any pending tool edit (which can change the document), then returns false, changing nothing more, when the Quick Pen tool is not active, no path is being drawn or the last piece is not a sharp-corner arc", + ), ( "window.dock", "Panels", diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rs index 8bbd8e2815..f8bce4e088 100644 --- a/crates/ui-egui/src/state.rs +++ b/crates/ui-egui/src/state.rs @@ -519,6 +519,14 @@ pub struct UiState { /// Actions has off (`window.taskBar.actions`); none: the bar shows every action it offers. #[serde(deserialize_with = "crate::canvas::read_hidden_task_bar_actions")] pub task_bar_hidden_actions: std::collections::BTreeSet, + /// Window › Quick Pen Toolbar: the Quick Pen tool shows its toolbar on the canvas. Hide Toolbar + /// turns it off until the tool is selected again. Not saved. + #[serde(skip, default = "yes")] + pub quick_pen_bar: bool, + /// Where the Quick Pen toolbar was dragged or pinned. Not saved: the toolbar starts beside the + /// drawing at every launch. + #[serde(skip)] + pub quick_pen_bar_place: QuickPenBarPlace, /// The Pathfinder panel's Shape Mode buttons make a compound shape on a click, and give the /// permanent Pathfinder result on Alt-click (off, the default: the other way round). #[serde(default)] @@ -1151,6 +1159,25 @@ pub struct ToolbarEdits { pub advanced: Option>, } +/// Where the Quick Pen toolbar sits once its handle has moved it (`window.quickPenToolbar.pin`, +/// `window.quickPenToolbar.reset`). +#[derive(Clone, Copy, Debug, Default, PartialEq)] +pub struct QuickPenBarPlace { + /// More Options › Pin Toolbar Position: the toolbar stays where it is on the canvas instead of + /// following the drawing. + pub pinned: bool, + /// Where a pinned toolbar's top-left corner sits from the canvas's top-left (none when it was + /// pinned before it ever showed, until it is drawn). Unpinning leaves it for the next frame to + /// turn into `offset`. + pub pin_at: Option, + /// Where the toolbar was last drawn, from the canvas's top-left: where pinning holds it. + pub shown_at: Option, + /// How far an unpinned toolbar was dragged from its place, the document (`DocState::uid`) it + /// was moved in, and whether it was beside a path being drawn then (false: resting with no path + /// being drawn). It applies only in that document and that kind of place. + pub offset: Option<(u64, bool, egui::Vec2)>, +} + /// Where the Contextual Task Bar sits once its handle has moved it (`window.taskBar.pin`, /// `window.taskBar.reset`). #[derive(Clone, Copy, Debug, Default, PartialEq)] @@ -1298,6 +1325,8 @@ impl Default for UiState { task_bar: true, task_bar_place: TaskBarPlace::default(), task_bar_hidden_actions: Default::default(), + quick_pen_bar: true, + quick_pen_bar_place: QuickPenBarPlace::default(), shape_modes_compound: false, context_locked: None, context_intertwine: None, diff --git a/crates/ui-egui/src/tests.rs b/crates/ui-egui/src/tests.rs index b37ed0d10c..e0619ddaf7 100644 --- a/crates/ui-egui/src/tests.rs +++ b/crates/ui-egui/src/tests.rs @@ -30,6 +30,7 @@ mod plugins; mod printps; mod printtiling; mod puppetwarp; +mod quickpenbar; mod recolor; mod recovery; pub(super) mod removeanchors; diff --git a/crates/ui-egui/src/tests/quickpenbar.rs b/crates/ui-egui/src/tests/quickpenbar.rs new file mode 100644 index 0000000000..d78423eb6b --- /dev/null +++ b/crates/ui-egui/src/tests/quickpenbar.rs @@ -0,0 +1,348 @@ +//! The Quick Pen toolbar: it shows while the Quick Pen tool is active, its buttons set the tool's +//! action and flip the last sharp-corner arc, it follows the drawing beside the path's last point, +//! and its More Options menu's commands hide it, pin it and reset its place. + +use egui::{Event, PointerButton, Pos2, Rect, vec2}; +use serde_json::json; +use vectorcraft_doc::NodeKind; +use vectorcraft_geom::{Point, SubPath}; +use vectorcraft_tools::{Mods, PointerEvent, PointerKind, ToolKey}; + +use crate::{VectorcraftApp, canvas}; + +fn app() -> VectorcraftApp { + let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default()); + app.run("file.new", json!({"width": 400, "height": 300})).unwrap(); + app.select_tool("quickPen"); + app +} + +fn context() -> egui::Context { + let ctx = egui::Context::default(); + ctx.enable_accesskit(); + crate::theme::install_fonts(&ctx); + ctx +} + +/// One frame of the canvas; returns the buttons it drew, by name, from the accessibility tree. +fn frame(app: &mut VectorcraftApp, ctx: &egui::Context, events: Vec) -> Vec<(String, Rect, bool)> { + frame_in(app, ctx, events, vec2(1000.0, 700.0)) +} + +/// [`frame`] in a window of `size`. +fn frame_in(app: &mut VectorcraftApp, ctx: &egui::Context, events: Vec, size: egui::Vec2) -> Vec<(String, Rect, bool)> { + let screen = Rect::from_min_size(Pos2::ZERO, size); + let mut out = ctx.run_ui(egui::RawInput { screen_rect: Some(screen), events, ..Default::default() }, |ui| canvas::show(app, ui)); + out.textures_delta.clear(); + let Some(update) = out.platform_output.accesskit_update.as_ref() else { return vec![] }; + update + .nodes + .iter() + .filter(|(_, n)| n.role() == egui::accesskit::Role::Button) + .filter_map(|(_, n)| { + let b = n.bounds()?; + let r = Rect::from_min_max(Pos2::new(b.x0 as f32, b.y0 as f32), Pos2::new(b.x1 as f32, b.y1 as f32)); + Some((n.label()?.to_string(), r, !n.is_disabled())) + }) + .collect() +} + +/// Two frames, for the toolbar's area to settle; returns the second frame's buttons. +fn settle(app: &mut VectorcraftApp, ctx: &egui::Context) -> Vec<(String, Rect, bool)> { + frame(app, ctx, vec![]); + frame(app, ctx, vec![]) +} + +fn bar(ctx: &egui::Context) -> Option { + canvas::quick_pen_bar_rect(ctx) +} + +/// Click the toolbar's button named `name`, which must be enabled. +fn click_button(app: &mut VectorcraftApp, ctx: &egui::Context, name: &str) { + let named = settle(app, ctx); + let (_, r, on) = named.iter().find(|(n, _, _)| n == name).unwrap_or_else(|| panic!("no button named {name:?} in {named:?}")); + assert!(*on, "{name} is enabled"); + let p = r.center(); + let press = |pressed| Event::PointerButton { pos: p, button: PointerButton::Primary, pressed, modifiers: Default::default() }; + frame(app, ctx, vec![Event::PointerMoved(p)]); + frame(app, ctx, vec![press(true)]); + frame(app, ctx, vec![press(false)]); + frame(app, ctx, vec![]); +} + +/// A click of the tool at `x`, `y` in the document. +fn click_doc(app: &mut VectorcraftApp, x: f64, y: f64) { + let v = app.view_info(); + for kind in [PointerKind::Down, PointerKind::Up] { + app.session.pointer(&PointerEvent::new(kind, x, y), v).unwrap(); + } +} + +fn paths(app: &VectorcraftApp) -> Vec { + let mut v = vec![]; + app.session.active().unwrap().doc.walk(|n| { + if let NodeKind::Path { path, .. } = &n.kind { + v.extend(path.subpaths.iter().cloned()); + } + }); + v +} + +fn screen(app: &VectorcraftApp, x: f64, y: f64) -> Pos2 { + app.canvas_xf().unwrap().to_screen(Point::new(x, y)) +} + +fn near(p: Pos2, q: Pos2) { + assert!((p - q).length() < 1.5, "{p:?} is not at {q:?}"); +} + +/// The toolbar shows only with the Quick Pen tool, at the bottom center of the canvas while no path +/// is being drawn; its action buttons set the tool's action without drawing on the canvas under +/// them; Hide Toolbar and Window › Quick Pen Toolbar hide and show it. +#[test] +fn the_toolbar_shows_with_the_tool_and_its_buttons_set_the_action() { + let mut app = app(); + let ctx = context(); + let named = settle(&mut app, &ctx); + let r = bar(&ctx).expect("the toolbar shows with the Quick Pen tool"); + for name in ["Straight Line", "Continuous Arc", "Sharp Corner Arc", "Flip Arc", "More Options"] { + assert!(named.iter().any(|(n, _, _)| n == name), "{name} in {named:?}"); + } + assert!(!named.iter().any(|(n, _, on)| n == "Flip Arc" && *on), "Flip Arc waits for an arc"); + let canvas = app.canvas_xf().unwrap().rect; + assert!((r.center().x - canvas.center().x).abs() < 1.5 && (r.bottom() - (canvas.bottom() - 8.0)).abs() < 1.5, "{r:?} in {canvas:?}"); + + click_button(&mut app, &ctx, "Sharp Corner Arc"); + assert_eq!(app.session.tool_options()["action"], "sharpArc"); + click_button(&mut app, &ctx, "Continuous Arc"); + assert_eq!(app.session.tool_options()["action"], "continuousArc"); + click_button(&mut app, &ctx, "Straight Line"); + assert_eq!(app.session.tool_options()["action"], "line"); + assert!(paths(&app).is_empty(), "a click on the toolbar draws nothing"); + + assert_eq!(app.run("window.quickPenToolbar", json!({})).unwrap(), json!(false)); + assert_eq!(crate::menus::checked(&app, "window.quickPenToolbar", &json!({})), Some(false)); + settle(&mut app, &ctx); + assert!(bar(&ctx).is_none(), "hidden"); + assert_eq!(app.run("window.quickPenToolbar", json!({})).unwrap(), json!(true)); + settle(&mut app, &ctx); + assert!(bar(&ctx).is_some(), "shown again"); + + app.select_tool("pen"); + settle(&mut app, &ctx); + assert!(bar(&ctx).is_none(), "only with the Quick Pen tool"); + + // Hidden, it shows again when the tool is selected again. + app.select_tool("quickPen"); + settle(&mut app, &ctx); + assert_eq!(app.run("window.quickPenToolbar", json!({})).unwrap(), json!(false)); + settle(&mut app, &ctx); + assert!(bar(&ctx).is_none(), "hidden"); + app.select_tool("pen"); + app.select_tool("quickPen"); + settle(&mut app, &ctx); + assert!(bar(&ctx).is_some(), "selecting the tool shows it"); + assert_eq!(crate::menus::checked(&app, "window.quickPenToolbar", &json!({})), Some(true)); + // Selecting it again while it is active shows it too. + app.run("window.quickPenToolbar", json!({})).unwrap(); + settle(&mut app, &ctx); + assert!(bar(&ctx).is_none(), "hidden"); + app.run("tool.select", json!({"tool": "quickPen"})).unwrap(); + settle(&mut app, &ctx); + assert!(bar(&ctx).is_some(), "selected again"); +} + +/// The toolbar hides while a press drags on the canvas, and shows again once it is let go. +#[test] +fn the_toolbar_hides_while_a_press_drags_on_the_canvas() { + let mut app = app(); + let ctx = context(); + // The first click places the path's start; the press that follows drags out a piece. + click_doc(&mut app, 60.0, 60.0); + settle(&mut app, &ctx); + assert!(bar(&ctx).is_some()); + let (a, b) = (screen(&app, 100.0, 100.0), screen(&app, 200.0, 140.0)); + let press = |pos, pressed| Event::PointerButton { pos, button: PointerButton::Primary, pressed, modifiers: Default::default() }; + frame(&mut app, &ctx, vec![Event::PointerMoved(a), press(a, true)]); + frame(&mut app, &ctx, vec![Event::PointerMoved(a + (b - a) / 2.0)]); + frame(&mut app, &ctx, vec![Event::PointerMoved(b)]); + assert!(app.session.tool_busy(), "the press reached the tool"); + assert!(bar(&ctx).is_none(), "hidden mid-drag"); + frame(&mut app, &ctx, vec![press(b, false)]); + settle(&mut app, &ctx); + assert!(bar(&ctx).is_some(), "shown after the drag"); +} + +/// A middle-button drag on the canvas (a pan), which the tool takes no press from, hides the toolbar +/// too, and it shows again when the button is let go. +#[test] +fn the_toolbar_hides_while_the_canvas_pans() { + let mut app = app(); + let ctx = context(); + settle(&mut app, &ctx); + assert!(bar(&ctx).is_some()); + let (a, b) = (screen(&app, 100.0, 100.0), screen(&app, 200.0, 140.0)); + let press = |pos, pressed| Event::PointerButton { pos, button: PointerButton::Middle, pressed, modifiers: Default::default() }; + frame(&mut app, &ctx, vec![Event::PointerMoved(a), press(a, true)]); + frame(&mut app, &ctx, vec![Event::PointerMoved(a + (b - a) / 2.0)]); + frame(&mut app, &ctx, vec![Event::PointerMoved(b)]); + assert!(!app.session.tool_busy(), "the tool has no press under way"); + assert!(bar(&ctx).is_none(), "hidden mid-pan"); + frame(&mut app, &ctx, vec![press(b, false)]); + settle(&mut app, &ctx); + assert!(bar(&ctx).is_some(), "shown after the pan"); +} + +/// On a canvas narrower than the toolbar, its controls wrap onto more rows, so every button lies +/// on the canvas. +#[test] +fn the_toolbar_wraps_on_a_narrow_canvas() { + let mut app = app(); + let ctx = context(); + let size = vec2(130.0, 500.0); + frame_in(&mut app, &ctx, vec![], size); + let named = frame_in(&mut app, &ctx, vec![], size); + let canvas = app.canvas_xf().unwrap().rect; + assert!(canvas.width() < 150.0, "{canvas:?}"); + for name in ["Straight Line", "Continuous Arc", "Sharp Corner Arc", "Flip Arc", "More Options"] { + let (_, r, _) = named.iter().find(|(n, _, _)| n == name).unwrap_or_else(|| panic!("{name} in {named:?}")); + assert!(canvas.contains_rect(*r), "{name} at {r:?} is off the canvas {canvas:?}"); + } +} + +/// Flip Arc's command sends C only to the Quick Pen tool: with the Arc tool, which takes C while it +/// drags, it returns false and changes nothing. +#[test] +fn flip_arc_does_nothing_with_another_tool() { + let mut app = app(); + app.select_tool("arc"); + let v = app.view_info(); + app.session.pointer(&PointerEvent::new(PointerKind::Down, 50.0, 50.0), v).unwrap(); + app.session.pointer(&PointerEvent::new(PointerKind::Drag, 150.0, 120.0), v).unwrap(); + assert!(app.session.tool_claims_key(ToolKey::Letter('c'), v), "the Arc tool takes C mid-drag"); + let closed = app.session.tool_options()["closed"].clone(); + assert_eq!(app.run("tool.quickPen.flipArc", json!({})).unwrap(), json!(false)); + assert_eq!(app.session.tool_options()["closed"], closed, "the arc's C was not sent"); +} + +/// While a path is drawn, the toolbar sits 24 points off its last point, on the side the path +/// heads toward; Flip Arc flips the last sharp-corner arc as one undo step and is off after a line; +/// Escape sends the toolbar back to the bottom of the canvas. +#[test] +fn the_toolbar_follows_the_drawing_and_flips_the_last_arc() { + let mut app = app(); + let ctx = context(); + settle(&mut app, &ctx); + let resting = bar(&ctx).unwrap(); + app.run("tool.setOption", json!({"key": "action", "value": "sharpArc"})).unwrap(); + assert_eq!(app.run("tool.quickPen.flipArc", json!({})).unwrap(), json!(false), "no path being drawn"); + click_doc(&mut app, 100.0, 150.0); + click_doc(&mut app, 200.0, 150.0); + // A half circle above the chord, which arrives at (200, 150) heading down: right and below. + let mid = |app: &VectorcraftApp| paths(app)[0].anchors[1].p; + assert!(mid(&app).y < 150.0); + settle(&mut app, &ctx); + near(bar(&ctx).unwrap().min, screen(&app, 200.0, 150.0) + vec2(24.0, 24.0)); + + let undo = app.session.active().unwrap().history.undo.len(); + click_button(&mut app, &ctx, "Flip Arc"); + assert!(mid(&app).y > 150.0, "flipped below the chord"); + assert_eq!(app.session.active().unwrap().history.undo.len(), undo + 1); + + // A line drawn to the left: the toolbar goes to the left of its end, still below it. + app.run("tool.setOption", json!({"key": "action", "value": "line"})).unwrap(); + click_doc(&mut app, 120.0, 150.0); + let named = settle(&mut app, &ctx); + let r = bar(&ctx).unwrap(); + let end = screen(&app, 120.0, 150.0); + near(pos2_of(r.right(), r.top()), end + vec2(-24.0, 24.0)); + assert!(!named.iter().any(|(n, _, on)| n == "Flip Arc" && *on), "Flip Arc is off after a line"); + assert_eq!(app.run("tool.quickPen.flipArc", json!({})).unwrap(), json!(false)); + assert_eq!(app.session.active().unwrap().history.undo.len(), undo + 2, "the line, and no flip"); + + let v = app.view_info(); + app.session.tool_key(ToolKey::Escape, Mods::default(), v).unwrap(); + settle(&mut app, &ctx); + near(bar(&ctx).unwrap().min, resting.min); +} + +fn pos2_of(x: f32, y: f32) -> Pos2 { + Pos2::new(x, y) +} + +/// The toolbar stays shown while its handle is dragged farther than the toolbar's height, when the +/// press is no longer on it. +#[test] +fn the_toolbar_stays_while_its_handle_drags_far() { + let mut app = app(); + let ctx = context(); + settle(&mut app, &ctx); + let button = |pos, pressed| Event::PointerButton { pos, button: PointerButton::Primary, pressed, modifiers: Default::default() }; + let grip = pos2_of(bar(&ctx).unwrap().left() + 10.0, bar(&ctx).unwrap().center().y); + frame(&mut app, &ctx, vec![Event::PointerMoved(grip)]); + frame(&mut app, &ctx, vec![button(grip, true)]); + for k in 1..=6 { + frame(&mut app, &ctx, vec![Event::PointerMoved(grip + vec2(-20.0, -30.0) * k as f32)]); + assert!(bar(&ctx).is_some(), "shown at step {k}"); + } + frame(&mut app, &ctx, vec![button(grip + vec2(-120.0, -180.0), false)]); + settle(&mut app, &ctx); + assert!(bar(&ctx).is_some()); +} + +/// The handle drags the toolbar, which keeps that offset as it follows the drawing, but not in its +/// resting place with no path being drawn; pinned, it stays put; Reset Toolbar Position puts it +/// back beside the drawing, unpinned. +#[test] +fn the_toolbar_drags_pins_and_resets() { + let mut app = app(); + let ctx = context(); + click_doc(&mut app, 100.0, 100.0); + click_doc(&mut app, 150.0, 100.0); + settle(&mut app, &ctx); + let beside = |app: &VectorcraftApp, x: f64, y: f64| screen(app, x, y) + vec2(24.0, 24.0); + near(bar(&ctx).unwrap().min, beside(&app, 150.0, 100.0)); + let button = |pos, pressed| Event::PointerButton { pos, button: PointerButton::Primary, pressed, modifiers: Default::default() }; + let grip = pos2_of(bar(&ctx).unwrap().left() + 10.0, bar(&ctx).unwrap().center().y); + let by = vec2(30.0, 40.0); + frame(&mut app, &ctx, vec![Event::PointerMoved(grip)]); + frame(&mut app, &ctx, vec![button(grip, true)]); + frame(&mut app, &ctx, vec![Event::PointerMoved(grip + by)]); + frame(&mut app, &ctx, vec![button(grip + by, false)]); + settle(&mut app, &ctx); + near(bar(&ctx).unwrap().min, beside(&app, 150.0, 100.0) + by); + assert_eq!(paths(&app)[0].anchors.len(), 2, "dragging the handle draws nothing"); + + click_doc(&mut app, 200.0, 100.0); + settle(&mut app, &ctx); + near(bar(&ctx).unwrap().min, beside(&app, 200.0, 100.0) + by); + + // A drag made beside the drawing does not move the resting toolbar. + let resting = { + let canvas = app.canvas_xf().unwrap().rect.shrink(8.0); + let r = bar(&ctx).unwrap(); + Pos2::new(canvas.center().x - r.width() / 2.0, canvas.bottom() - r.height()) + }; + let v = app.view_info(); + app.session.tool_key(ToolKey::Escape, Mods::default(), v).unwrap(); + settle(&mut app, &ctx); + near(bar(&ctx).unwrap().min, resting); + // A new path, away from the first one's ends. + click_doc(&mut app, 100.0, 200.0); + click_doc(&mut app, 200.0, 200.0); + settle(&mut app, &ctx); + near(bar(&ctx).unwrap().min, beside(&app, 200.0, 200.0) + by); + + assert_eq!(app.run("window.quickPenToolbar.pin", json!({})).unwrap(), json!(true)); + assert_eq!(crate::menus::checked(&app, "window.quickPenToolbar.pin", &json!({})), Some(true)); + let pinned = bar(&ctx).unwrap().min; + click_doc(&mut app, 250.0, 200.0); + settle(&mut app, &ctx); + near(bar(&ctx).unwrap().min, pinned); + assert!(app.run("window.quickPenToolbar.pin", json!({"pinned": "yes"})).is_err()); + + app.run("window.quickPenToolbar.reset", json!({})).unwrap(); + assert!(!app.ui.quick_pen_bar_place.pinned); + settle(&mut app, &ctx); + near(bar(&ctx).unwrap().min, beside(&app, 250.0, 200.0)); +} diff --git a/docs/control-protocol.md b/docs/control-protocol.md index ee0cb11a79..dafab93a58 100644 --- a/docs/control-protocol.md +++ b/docs/control-protocol.md @@ -92,7 +92,7 @@ the two can still win that race. | `engine.execute` | `{command, params}` | run any engine or UI command (see `engine.commands`). A key of `params` that the command's params description doesn't name is an error naming it and the nearest key the command takes, before anything runs (`unknown parameter `widht`; did you mean `width`?`); see [Parameter keys](mcp.md#parameter-keys) | | `engine.commands` | | every command with label, shortcut, params doc, enablement | | `document.inspect` | `{depth?, childLimit?, ids?, kind?, limit?, offset?}` | layer tree, selection, the key object (`key`, null without one; a key ruler guide as `keyGuide`), history, paint defaults; `depth` / `childLimit` slice the layer tree as `document.node {summary: true}` does; `ids`, `kind`, `limit` and `offset` list just some nodes as `nodes` (with `total`) instead of the whole tree, see [mcp.md](mcp.md). Each node reports `opacity` below 1 and `blend` when it isn't Normal; objects and compound paths report `fill`, `stroke` and `strokeWidth`, a compound path's members `compoundMember: true` instead | -| `ui.inspect` | | tool, UI state, `screenMode` (0 normal, 1 full screen with menu bar, 2 full screen, 3 Presentation Mode), `taskBar` (`pinned`, and `rect` `[x, y, w, h]` while the Contextual Task Bar shows), `freeTransformWidget` (`[x, y, w, h]` while the Free Transform widget shows), view, canvas rect, window size, perf, background saves and exports still running, `nativeMenuBar` (true when the menus are in the macOS menu bar rather than the window; `ui.menu.list` lists the in-window menus either way), `fileDialog` (`"open"`, `"place"`, `"save"` or `"folder"` while a native file dialog is open, `null` otherwise; see below), `opening` (the paths of the documents still being read). Under `--automation-read-root` the reply leaves out the paths outside the read roots (see `docs/mcp.md`) | +| `ui.inspect` | | tool, UI state, `screenMode` (0 normal, 1 full screen with menu bar, 2 full screen, 3 Presentation Mode), `taskBar` (`pinned`, and `rect` `[x, y, w, h]` while the Contextual Task Bar shows), `quickPenToolbar` (the same for the Quick Pen toolbar), `freeTransformWidget` (`[x, y, w, h]` while the Free Transform widget shows), view, canvas rect, window size, perf, background saves and exports still running, `nativeMenuBar` (true when the menus are in the macOS menu bar rather than the window; `ui.menu.list` lists the in-window menus either way), `fileDialog` (`"open"`, `"place"`, `"save"` or `"folder"` while a native file dialog is open, `null` otherwise; see below), `opening` (the paths of the documents still being read). Under `--automation-read-root` the reply leaves out the paths outside the read roots (see `docs/mcp.md`) | | `ui.menu.list` / `ui.menu.invoke` | `{command, params}` | the full menu tree / invoke an item | | `ui.contextMenu.list` | | the canvas context menu for the current selection, flattened like `ui.menu.list` (`path` holds its submenus). `ui.click {x, y, button: "right"}` on the canvas opens it, after selecting the object there unless it is already selected. With the Artboard tool it lists the artboard entries (see `docs/mcp.md`), after selecting the artboard there unless it is already selected. While a menu opened over locked objects is open, it has an `Unlock` submenu with one item for each locked object under the pointer, topmost first and at most 20, labeled with the object's name, which runs `layer.setProps {ids: [id], locked: false}`. A locked group gets one item, and the locked objects inside it get none. Hidden objects, objects on hidden, locked or template layers, and in isolation mode objects outside the isolated group get no item | | `ui.tool.select` / `ui.tool.list` | `{tool}` | | @@ -507,6 +507,12 @@ Bar Position (`window.taskBar.reset`), which unpins it and puts it back under th Panel. As in Illustrator, neither the position nor the pin is saved: each launch starts with the bar under the selection. +The Quick Pen toolbar shows while the Quick Pen tool is active and Window › Quick Pen Toolbar +(`window.quickPenToolbar`) is on. Its handle drags it as the Contextual Task Bar's does. Its buttons set the tool's +action and flip the last sharp-corner arc (`tool.quickPen.flipArc`), and its More Options (…) menu has Hide Toolbar +(`window.quickPenToolbar`), Pin Toolbar Position (`window.quickPenToolbar.pin {pinned?}`) and Reset Toolbar Position +(`window.quickPenToolbar.reset`). `docs/mcp.md` (Drawing with the Quick Pen tool) says where it sits. + The Compound Shapes add-on's setting, `window.pathfinder.compoundShapes` (omitted params toggle; checked while on; kept with the preferences; off by default), swaps what a click and an Alt-click do on the Pathfinder panel's Shape Mode buttons: on, a click makes a compound shape (`object.compoundShape.make`) and Alt-click gives the permanent Pathfinder result. Selected members of a compound diff --git a/docs/mcp.md b/docs/mcp.md index bdb6c1394c..644ee6cba0 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -7301,6 +7301,26 @@ arc size of 180°, its 15° steps, the side an arc bulges to, what C and `[` `]` path are VectorCraft's own rules. The tool keeps `action` and `turn` with the preferences (`tool.setOption {tool: "quickPen", key, value}`). +Selecting the tool shows its toolbar on the canvas: Straight Line, Continuous Arc and Sharp Corner Arc set `action`, +Flip Arc flips the last sharp-corner arc as C does (`tool.quickPen.flipArc {}`, which first finishes any pending tool edit, +which can change the document, then returns false and changes nothing more when the Quick Pen tool is not active +or the last piece is not a sharp-corner arc), and More Options (…) has Hide +Toolbar (`window.quickPenToolbar`, which toggles; the toolbar stays hidden until the tool is selected again) and Reset +Toolbar Position (`window.quickPenToolbar.reset`), as the help page describes. +The handle at its left end drags it. While a path is being drawn, the toolbar sits beside the path's last point, 24 +screen points off it diagonally whatever the zoom, on the side the path heads toward (to the right and below for a path +drawn right and down), away from what was drawn, as the +[design write-up](https://adobe.design/ideas/behind-the-design-adobe-illustrator-s-quick-pen-tool) describes. The +following are VectorCraft's own rules. Where the side the path heads toward runs off the canvas, the toolbar goes on the +other side; with no path being drawn, it sits at the bottom center of the canvas. A drag's offset moves it from its +place beside the drawing, or from its resting place, in the document it was made in, and not where it would cover the +path's last point. More Options also has Pin Toolbar Position (`window.quickPenToolbar.pin {pinned?}`, omitted +toggles), which holds the toolbar at its place in the canvas window while the view scrolls or zooms, and Window › Quick +Pen Toolbar shows or hides it. It hides while a press drags on the canvas, and in a canvas pane narrower than the +toolbar its controls wrap onto more rows. `ui.inspect` gives `quickPenToolbar` (`pinned`, and `rect` while it shows); its position, +the pin and whether it shows are not saved. These commands run in the desktop app; the headless host does not run them, +so they need `--connect`. + `path.quickPen {start?: [x, y], id?, subpath?, keep?, pieces?, closed?}` draws such a path and selects it, as one undo step, and answers `{id}`. With `start`, it makes a new path with the current paint (a black stroke when the paint has neither fill nor stroke). With `id`, it draws on the open subpath `subpath` (0 when left out) of that path: its diff --git a/docs/ui-parity.md b/docs/ui-parity.md index 8f273db4ed..7d1d61416e 100644 --- a/docs/ui-parity.md +++ b/docs/ui-parity.md @@ -205,7 +205,7 @@ tools, never checked side by side) isn't captured row by row. | Busy cursor during long operations | done | Background open, save and export show the system progress cursor (gap G1) | | Each anchor snaps to Smart Guides and construction angles | done | `DrawSnap` | | Curvature tool: click/drag points, double-click or Alt-click for a corner, temporary Direct Selection, point conversion | partial | circular point markers without direction handles or duplicate markers, Anchor Size and Hide Edges regression-tested (#1236, in part); curve geometry: each stretch of three points follows the circle through them (handles along its tangent, chord/(3·cos²(α/2)) long, shorter in a turn tighter than 30°), open ends curving in, the same rule for the rubber band, dragged, inserted and converted points (#1236, in part); neighbours of a point dragged on an existing path keep their tangents, and modifiers requested in #975 remain | -| Quick Pen tool: straight lines, continuous arcs and sharp-corner arcs, Alt/Option to switch action, C to flip an arc, `[` / `]` for its size, Alt+P / Option+P, close on the first point, continue from an end, Escape to end ([help page](https://helpx.adobe.com/illustrator/web/add-and-edit-artwork/draw-and-edit-paths/draw-with-quick-pen-tool.html), [shortcuts](https://helpx.adobe.com/illustrator/web/add-and-edit-artwork/draw-and-edit-paths/quick-pen-tool-keyboard-shortcuts.html)) | partial | `path.quickPen` and the tool in `crates/tools/src/quickpen.rs`, in the Pen tool's group (#2660). Not yet: the on-canvas toolbar with its More menu, dragging a path's ends to change a line's or arc's length, Ctrl+scroll for the arc size, and editing and deleting with the tool | +| Quick Pen tool: straight lines, continuous arcs and sharp-corner arcs, Alt/Option to switch action, C to flip an arc, `[` / `]` for its size, Alt+P / Option+P, close on the first point, continue from an end, Escape to end ([help page](https://helpx.adobe.com/illustrator/web/add-and-edit-artwork/draw-and-edit-paths/draw-with-quick-pen-tool.html), [shortcuts](https://helpx.adobe.com/illustrator/web/add-and-edit-artwork/draw-and-edit-paths/quick-pen-tool-keyboard-shortcuts.html)) | partial | `path.quickPen` and the tool in `crates/tools/src/quickpen.rs`, in the Pen tool's group (#2660); the on-canvas toolbar with its actions, Flip Arc and its More menu (Hide Toolbar and Reset Toolbar Position, and VectorCraft's own Pin Toolbar Position) in `crates/ui-egui/src/canvas/quick_pen_bar.rs`. Not yet: dragging a path's ends to change a line's or arc's length, Ctrl+scroll for the arc size, and editing and deleting with the tool | | Icon-strip flyout resizing (#5713) | done | Canvas-side edge and bottom; user size persists after reopening and workspace restore; Glyphs and Artboards pointer/cursor regression | | Icon-strip flyout resizing from the top (storytold/craft-libs#1094) | done | Top edge (a 4 pt band over the tab strip) and the canvas-side top corner; the bottom and the icon-column edge stay; the moved top persists after reopening and workspace restore; `an_icon_flyout_grows_upward_from_its_top_edge_and_free_corner` | | Graphic Styles list fills a taller panel (#2992) | done | Docked, floating or in a resized flyout, the list takes the height above the panel's footer, as the Artboards list does; outside a sized panel it stays 220 pt; `the_list_fills_a_tall_panel_above_its_footer` |