From f5a25ea60f84f75d33dc87caf159ab723176243d Mon Sep 17 00:00:00 2001 From: Deepak Jain Date: Wed, 25 Nov 2026 10:42:52 -0800 Subject: [PATCH] Show the Freeform Pen nib over the canvas Use the Freeform Pen icon for ordinary hover and switch to the crosshair for Caps Lock or Precise Other Cursors. Keep the existing Continue badge on selected path ends. Signed-off-by: Deepak Jain --- .../ui-egui/src/tools/vector_ui/freeform.rs | 14 +++++++-- .../tools/vector_ui/freeform_cursor_tests.rs | 30 +++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 crates/ui-egui/src/tools/vector_ui/freeform_cursor_tests.rs diff --git a/crates/ui-egui/src/tools/vector_ui/freeform.rs b/crates/ui-egui/src/tools/vector_ui/freeform.rs index b635c1b68f..960a5f63b2 100644 --- a/crates/ui-egui/src/tools/vector_ui/freeform.rs +++ b/crates/ui-egui/src/tools/vector_ui/freeform.rs @@ -278,11 +278,17 @@ impl CanvasTool for FreeformPenTool { } fn cursor(&self, cx: &ToolContext<'_>) -> Cursor { + if cx.precise() { + return Cursor::Painted(PaintedCursor::Crosshair); + } if cx.pointer.as_ref().and_then(|pointer| self.end_at(pointer, cx)).is_some_and(|end| end.selected) { - // The nib is at the lower left of the same 24-point icon box the Pen uses. return Cursor::Painted(PaintedCursor::tool(crate::icons::tool_icon(Tool::FreeformPen), Vec2::Y * 24.0, Some(CursorBadge::Continue))); } - Cursor::System(CursorIcon::Default) + if cx.pointer.is_none() || cx.mods.alt || cx.mods.cmd { + return Cursor::System(CursorIcon::Default); + } + const FREEFORM_NIB: Vec2 = Vec2::new(3.0, 5.0); + Cursor::Painted(PaintedCursor::tool(crate::icons::tool_icon(Tool::FreeformPen), FREEFORM_NIB, None)) } fn command_form(&self) -> ToolPath { @@ -297,3 +303,7 @@ mod freeform_pen_tests; #[cfg(test)] #[path = "freeform_continue_endpoint_tests.rs"] mod freeform_continue_endpoint_tests; + +#[cfg(test)] +#[path = "freeform_cursor_tests.rs"] +mod freeform_cursor_tests; diff --git a/crates/ui-egui/src/tools/vector_ui/freeform_cursor_tests.rs b/crates/ui-egui/src/tools/vector_ui/freeform_cursor_tests.rs new file mode 100644 index 0000000000..88a281d5a2 --- /dev/null +++ b/crates/ui-egui/src/tools/vector_ui/freeform_cursor_tests.rs @@ -0,0 +1,30 @@ +use craft::behavior::{Cursor, PaintedCursor}; +use craft::ui::runtime::windows::WindowHost; +use egui::Modifiers; +use egui_kittest::Harness; +use serde_json::json; + +use crate::PhotocraftApp; +use crate::guide_cursor_tests::{harness, hover}; +use crate::state::Tool; + +fn canvas_cursor(app: &mut Harness<'static, Box>) -> Option { + hover(app, 100.0, 150.0, Modifiers::NONE); + app.state().canvas_tools.last_response.as_ref()?.cursor.clone() +} + +#[test] +fn freeform_hover_switches_between_its_nib_and_the_precise_crosshair() { + let mut app = harness(Tool::FreeformPen); + let nib = Some(Cursor::Painted(PaintedCursor::tool(crate::icons::tool_icon(Tool::FreeformPen), egui::vec2(3.0, 5.0), None))); + let crosshair = Some(Cursor::Painted(PaintedCursor::Crosshair)); + assert_eq!(canvas_cursor(&mut app), nib); + + WindowHost::of(&app.ctx).set_caps_lock(Some(true)); + assert_eq!(canvas_cursor(&mut app), crosshair); + WindowHost::of(&app.ctx).set_caps_lock(Some(false)); + assert_eq!(canvas_cursor(&mut app), nib); + + app.state_mut().run("prefs.set", json!({"path": "cursors.other", "value": "precise"})).unwrap(); + assert_eq!(canvas_cursor(&mut app), crosshair); +}