From 523df5804c6dafba88bae77ae6dd9936374dad57 Mon Sep 17 00:00:00 2001 From: Hector Villarreal Date: Sat, 21 Nov 2026 05:23:56 -0600 Subject: [PATCH 1/2] Magic Eraser: its own icon cursor With Standard Other Cursors the Magic Eraser's cursor is its toolbar icon, the hotspot on the eraser's end at the lower left of the glyph, also with Shift held. Precise Other Cursors and Caps Lock keep the crosshair, as for the Paint Bucket. Fixes #12001 --- crates/ui-egui/src/canvas/cursor_policy.rs | 15 +++++-- .../src/canvas/magic_eraser_cursor_tests.rs | 45 +++++++++++++++++++ 2 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 crates/ui-egui/src/canvas/magic_eraser_cursor_tests.rs diff --git a/crates/ui-egui/src/canvas/cursor_policy.rs b/crates/ui-egui/src/canvas/cursor_policy.rs index f5e6180877..5aac0cc5f0 100644 --- a/crates/ui-egui/src/canvas/cursor_policy.rs +++ b/crates/ui-egui/src/canvas/cursor_policy.rs @@ -50,17 +50,22 @@ pub(crate) fn sample_target() -> Cursor { /// The pointer of a painting tool that acts on a click and has no brush tip: the Paint Bucket's /// arrow with the bucket below right of it, the hotspot on the arrow's tip, so a click fills the -/// pixel under the tip (#12539), and the Magic Eraser's crosshair. Precise Other Cursors (or Caps -/// Lock, `precise`) gives the Paint Bucket the crosshair too (#3968). `None` for a tool that -/// strokes with the brush. +/// pixel under the tip (#12539), and the Magic Eraser's own icon with the hotspot on the eraser's +/// end at the lower left (#12001). Precise Other Cursors (or Caps Lock, `precise`) gives both the +/// crosshair (#3968). `None` for a tool that strokes with the brush. pub(crate) fn click_tool_cursor(tool: Tool, precise: bool) -> Option { match tool { Tool::PaintBucket if !precise => Some(Cursor::Painted(PaintedCursor::pointer_tool(PointerGlyph::Arrow, crate::icons::tool_icon(tool)))), + Tool::MagicEraser if !precise => Some(Cursor::Painted(PaintedCursor::tool(crate::icons::tool_icon(tool), MAGIC_ERASER_HOTSPOT, None))), Tool::PaintBucket | Tool::MagicEraser => Some(Cursor::Painted(PaintedCursor::Crosshair)), _ => None, } } +/// The Magic Eraser icon's point that sits on the pointer, in its 24-unit box: the middle of the eraser's end, which +/// lies at the lower left of the `eraser_magic` glyph (#12001). +pub(crate) const MAGIC_ERASER_HOTSPOT: egui::Vec2 = egui::vec2(4.6, 18.4); + /// Path Selection's own pointer (#13295): the light arrow, and the solid one with ⌥ (without ⌘) /// where a press would land on a component (`path_components::over_component`). ⌘ keeps the light /// one; Precise Other Cursors (or Caps Lock, `precise`) the crosshair. `mods` and `at` are the @@ -161,3 +166,7 @@ mod triangle_alt_eyedropper_tests; #[cfg(test)] #[path = "custom_shape_alt_eyedropper_tests.rs"] mod custom_shape_alt_eyedropper_tests; + +#[cfg(test)] +#[path = "magic_eraser_cursor_tests.rs"] +mod magic_eraser_cursor_tests; diff --git a/crates/ui-egui/src/canvas/magic_eraser_cursor_tests.rs b/crates/ui-egui/src/canvas/magic_eraser_cursor_tests.rs new file mode 100644 index 0000000000..55cf2e5701 --- /dev/null +++ b/crates/ui-egui/src/canvas/magic_eraser_cursor_tests.rs @@ -0,0 +1,45 @@ +//! #12001: the Magic Eraser's cursor is its own toolbar icon with the hotspot on the eraser's end at the lower left, +//! also with Shift held; Precise Other Cursors and Caps Lock give the crosshair. Driven through real egui input on +//! the real canvas; the assertions read the cursor the tool asked the tool host for. + +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; + +/// A point away from the harness's guide at x = 200. +const AT: [f32; 2] = [100.0, 150.0]; + +fn cursor_with(h: &mut Harness<'static, Box>, mods: Modifiers) -> Option { + hover(h, AT[0], AT[1], mods); + h.state().canvas_tools.last_response.as_ref().and_then(|r| r.cursor.clone()) +} + +#[test] +fn the_standard_cursor_is_the_magic_eraser_icon_with_its_tip_at_the_lower_left() { + let mut h = harness(Tool::MagicEraser); + let Some(Cursor::Painted(PaintedCursor::Tool { icon, hotspot, badge, .. })) = cursor_with(&mut h, Modifiers::NONE) else { + panic!("an icon cursor, not the crosshair"); + }; + assert_eq!(icon, crate::icons::tool_icon(Tool::MagicEraser), "the toolbar's own icon"); + assert!(hotspot.x < 12.0 && hotspot.y > 12.0, "the hotspot sits at the lower left of the 24-unit box: {hotspot:?}"); + assert!(badge.is_none()); + assert_eq!(cursor_with(&mut h, Modifiers::SHIFT), cursor_with(&mut h, Modifiers::NONE), "Shift keeps it"); +} + +#[test] +fn precise_other_cursors_and_caps_lock_give_the_crosshair() { + let mut h = harness(Tool::MagicEraser); + let crosshair = Some(Cursor::Painted(PaintedCursor::Crosshair)); + h.state_mut().run("prefs.set", json!({"path": "cursors.other", "value": "precise"})).unwrap(); + assert_eq!(cursor_with(&mut h, Modifiers::NONE), crosshair, "Precise: the crosshair"); + h.state_mut().run("prefs.set", json!({"path": "cursors.other", "value": "standard"})).unwrap(); + assert_ne!(cursor_with(&mut h, Modifiers::NONE), crosshair, "Standard again: the icon"); + WindowHost::of(&h.ctx).set_caps_lock(Some(true)); + assert_eq!(cursor_with(&mut h, Modifiers::NONE), crosshair, "Caps Lock: the crosshair"); +} From 92345d222ac6491607b705c269afb989d385de2e Mon Sep 17 00:00:00 2001 From: Hector Villarreal Date: Sat, 21 Nov 2026 12:36:06 -0600 Subject: [PATCH 2/2] Magic Eraser cursor test: pin the hotspot by value (CodeRabbit on #16251) --- crates/ui-egui/src/canvas/magic_eraser_cursor_tests.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/canvas/magic_eraser_cursor_tests.rs b/crates/ui-egui/src/canvas/magic_eraser_cursor_tests.rs index 55cf2e5701..aed908d1fe 100644 --- a/crates/ui-egui/src/canvas/magic_eraser_cursor_tests.rs +++ b/crates/ui-egui/src/canvas/magic_eraser_cursor_tests.rs @@ -27,7 +27,8 @@ fn the_standard_cursor_is_the_magic_eraser_icon_with_its_tip_at_the_lower_left() panic!("an icon cursor, not the crosshair"); }; assert_eq!(icon, crate::icons::tool_icon(Tool::MagicEraser), "the toolbar's own icon"); - assert!(hotspot.x < 12.0 && hotspot.y > 12.0, "the hotspot sits at the lower left of the 24-unit box: {hotspot:?}"); + // The eraser end of the glyph, at the lower left of its 24-unit box: pinned by value so a moved constant fails. + assert_eq!(hotspot, egui::vec2(4.6, 18.4), "the eraser tip"); assert!(badge.is_none()); assert_eq!(cursor_with(&mut h, Modifiers::SHIFT), cursor_with(&mut h, Modifiers::NONE), "Shift keeps it"); }