From 8a30a026fef2e9cade5ea4e9259da493a5f4428d Mon Sep 17 00:00:00 2001 From: aiongg Date: Tue, 17 Nov 2026 00:21:36 +0000 Subject: [PATCH 1/3] The anchor tools' empty-canvas part shows the tool's off-path cursor --- crates/draw/src/ui/pen/anchor_tool.rs | 2 +- crates/draw/src/ui/pen/bezier/mod.rs | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/crates/draw/src/ui/pen/anchor_tool.rs b/crates/draw/src/ui/pen/anchor_tool.rs index cf5869631..e36351012 100644 --- a/crates/draw/src/ui/pen/anchor_tool.rs +++ b/crates/draw/src/ui/pen/anchor_tool.rs @@ -47,7 +47,7 @@ impl<'a> AnchorTool<'a> { } /// The cursor of `tool` off the overlay's parts with `mods` held; `precise` is the canvas's precise cursor. -fn cursor_of(tool: PathTool, mods: Mods, precise: bool) -> PaintedCursor { +pub(super) fn cursor_of(tool: PathTool, mods: Mods, precise: bool) -> PaintedCursor { // The pen's tip is the bottom left corner of the icon's box. let pen = |badge| PaintedCursor::tool(ToolIcon::Pen.icon(), Vec2::Y * ICON_BOX, Some(badge)); match tool { diff --git a/crates/draw/src/ui/pen/bezier/mod.rs b/crates/draw/src/ui/pen/bezier/mod.rs index ccb906b27..32d580dc9 100644 --- a/crates/draw/src/ui/pen/bezier/mod.rs +++ b/crates/draw/src/ui/pen/bezier/mod.rs @@ -14,7 +14,7 @@ mod words; use craft_behavior::geometry::{SelectionOperation, axis_or_diagonal}; use craft_behavior::kurbo::{Point, Rect as DocRect, Vec2}; use craft_behavior::{ - Axis, CanvasView, CursorPriority, EditCommand, GesturePhase, Granularity, HitLevel, HitPriority, HitShape, Intent, MoveMods, NavMove, NavShape, + Axis, CanvasView, Cursor, CursorPriority, EditCommand, GesturePhase, Granularity, HitLevel, HitPriority, HitShape, Intent, MoveMods, NavMove, NavShape, PartKey, PartRef, PointerButton, PressPhase, PressStart, Roving, Sense, }; use craft_keymap::{Chord, Key, Mods}; @@ -41,7 +41,8 @@ pub use model::{AnchorDelete, EditPath, EditSubpath, HandleSide, Knot, KnotRef, pub use style::BezierStyle; pub use words::BezierWords; -use super::PathOptionsSettings; +use super::anchor_tool::cursor_of; +use super::{PathOptionsSettings, PathTool}; /// Insert on a picked anchor adds one halfway along the segment leaving it. const INSERT: Chord = Chord::plain(Key::Insert); @@ -831,9 +832,16 @@ impl<'a> BezierOverlay<'a> { } if matches!(self.tool, BezierTool::AddAnchor | BezierTool::DeleteAnchor) && let Some(result) = cx.part_if_declared(EMPTY) - && matches!(result.press.phase, PressPhase::Down { start, .. } if start.button == PointerButton::Primary) { - self.report.pressed_empty = true; + // The part covers the canvas background, so it owns the cursor the host tool shows off the paths too. + if result.hover_pos.is_some() { + let tool = if self.tool == BezierTool::AddAnchor { PathTool::AddAnchor } else { PathTool::DeleteAnchor }; + let cursor = cursor_of(tool, result.press.mods, space.precise()); + cx.cursor(Cursor::Painted(cursor), CursorPriority::Part); + } + if matches!(result.press.phase, PressPhase::Down { start, .. } if start.button == PointerButton::Primary) { + self.report.pressed_empty = true; + } } // A press none of the parts carries any more (its part went with the paths) is over for the overlay. if !pressed && cx.press_slot::().is_some() { From cebb673c916d4b4dc65d47275bab4e2f37d386dc Mon Sep 17 00:00:00 2001 From: aiongg Date: Tue, 17 Nov 2026 00:25:38 +0000 Subject: [PATCH 2/3] Outline draft: a shift freehand drag locks one line only where the tool asks (the Freeform Pen); the selection Lasso keeps the pointer's path --- crates/behavior/src/geometry/draft.rs | 18 +++++++++++++++++- crates/behavior/tests/geometry/draft.rs | 10 +++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/crates/behavior/src/geometry/draft.rs b/crates/behavior/src/geometry/draft.rs index 506e02792..de17eec38 100644 --- a/crates/behavior/src/geometry/draft.rs +++ b/crates/behavior/src/geometry/draft.rs @@ -152,6 +152,8 @@ pub struct OutlineDraft { document: Option, /// A ⇧ freehand drag's line: where it began and the unit direction it locked to (the nearest of eight). lock: Option<(Point, Vec2)>, + /// Whether ⇧ holds a freehand drag to one line ([`locking_drags`](Self::locking_drags)). + locks_drag: bool, } impl OutlineDraft { @@ -168,9 +170,19 @@ impl OutlineDraft { alt_from_press: false, document: None, lock: None, + locks_drag: false, } } + /// Whether a Mixed draft's freehand drag with ⇧ held stays on one line ([`drag_step`](Self::drag_step)). Off, ⇧ + /// leaves a freehand drag alone: a selection Lasso's ⇧ at the press adds to the selection, and a drag keeps the + /// pointer's path. The Freeform Pen turns it on. + #[must_use] + pub fn locking_drags(mut self, on: bool) -> Self { + self.locks_drag = on; + self + } + /// The rules this draft follows. pub fn kind(&self) -> DraftKind { self.kind @@ -274,7 +286,7 @@ impl OutlineDraft { Some(DraftEvent::Changed) } - /// Where a freehand point of `at` goes. With ⇧ held a Mixed draft's drag follows one line: once the pointer has + /// Where a freehand point of `at` goes. With ⇧ held a [locking](Self::locking_drags) Mixed draft's drag follows one line: once the pointer has /// travelled [`LOCK_DISTANCE`] screen points from the last vertex, the nearest of eight directions from there /// is locked and every later point is the pointer's projection onto it, however the pointer wanders, until ⇧ is /// released. Before the lock the point stays at the vertex. Otherwise [`shift_step`](Self::shift_step). @@ -283,6 +295,10 @@ impl OutlineDraft { self.lock = None; return self.shift_step(at); } + if !self.locks_drag { + self.lock = None; + return at.at; + } let Some(&last) = self.points.last() else { return at.at }; let (origin, direction) = match self.lock { Some(lock) => lock, diff --git a/crates/behavior/tests/geometry/draft.rs b/crates/behavior/tests/geometry/draft.rs index f26dd8524..289031591 100644 --- a/crates/behavior/tests/geometry/draft.rs +++ b/crates/behavior/tests/geometry/draft.rs @@ -72,7 +72,7 @@ fn shift_steps_keep_the_shorter_diagonal_offset() { #[test] fn shift_holds_a_freehand_drag_to_one_line() { let shift = |x: f64, y: f64| DraftPoint::new(Point::new(x, y), Mods::SHIFT, 1.0); - let mut draft = OutlineDraft::new(DraftKind::Mixed, REACH); + let mut draft = OutlineDraft::new(DraftKind::Mixed, REACH).locking_drags(true); draft.press(at(10.0, 60.0, 1.0), true); for (x, y) in [(30.0, 63.0), (50.0, 55.0), (80.0, 68.0), (100.0, 52.0)] { draft.drag(shift(x, y)); @@ -82,6 +82,14 @@ fn shift_holds_a_freehand_drag_to_one_line() { assert!(points.len() >= 3, "{points:?}"); assert!(points.iter().all(|p| p.y == 60.0), "the drag stays on the horizontal line through its start: {points:?}"); assert_eq!(points.last().map(|p| p.x), Some(100.0), "and follows the pointer along it"); + + // A selection Lasso's ⇧ at the press adds to the selection: its drag keeps the pointer's path. + let mut lasso = OutlineDraft::new(DraftKind::Mixed, REACH); + lasso.press(at(10.0, 60.0, 1.0), true); + for (x, y) in [(30.0, 63.0), (50.0, 55.0)] { + lasso.drag(shift(x, y)); + } + assert_eq!(lasso.points().last(), Some(&Point::new(50.0, 55.0))); } #[test] From 2c7ce20114e804bafab2e6b6350f01a37c207be6 Mon Sep 17 00:00:00 2001 From: aiongg Date: Tue, 17 Nov 2026 00:29:18 +0000 Subject: [PATCH 3/3] Empty-part cursor: copy the part result before the cursor call --- crates/draw/src/ui/pen/bezier/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/draw/src/ui/pen/bezier/mod.rs b/crates/draw/src/ui/pen/bezier/mod.rs index 32d580dc9..a9c5bff6f 100644 --- a/crates/draw/src/ui/pen/bezier/mod.rs +++ b/crates/draw/src/ui/pen/bezier/mod.rs @@ -833,13 +833,13 @@ impl<'a> BezierOverlay<'a> { if matches!(self.tool, BezierTool::AddAnchor | BezierTool::DeleteAnchor) && let Some(result) = cx.part_if_declared(EMPTY) { + let (press, hover) = (result.press, result.hover_pos); // The part covers the canvas background, so it owns the cursor the host tool shows off the paths too. - if result.hover_pos.is_some() { + if hover.is_some() { let tool = if self.tool == BezierTool::AddAnchor { PathTool::AddAnchor } else { PathTool::DeleteAnchor }; - let cursor = cursor_of(tool, result.press.mods, space.precise()); - cx.cursor(Cursor::Painted(cursor), CursorPriority::Part); + cx.cursor(Cursor::Painted(cursor_of(tool, press.mods, space.precise())), CursorPriority::Part); } - if matches!(result.press.phase, PressPhase::Down { start, .. } if start.button == PointerButton::Primary) { + if matches!(press.phase, PressPhase::Down { start, .. } if start.button == PointerButton::Primary) { self.report.pressed_empty = true; } }