Magnetic Lasso: the Standard cursor is the tool icon (#12151, #11690)

With Other Cursors set to Standard (or Precise swapped by Caps Lock) the
Magnetic Lasso showed a plain crosshair. The reference application shows
the tool's icon with its hotspot on the lasso's top-left tip; the Width
circle stays on the precise side.

Co-Authored-By: Hector Villarreal <1501713+hectorviov@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
committed 2026-11-08 22:19:01 +01:00
1 parent 63f6cde667
commit 08fb210964
2 files changed
+32 -14

No files matched your search

+10 -7
View File
@@ -483,15 +483,18 @@ pub fn draw(app: &PhotocraftApp, painter: &egui::Painter, xf: &ViewXform, hover:
}
}
/// The cursor over the canvas: a crosshair; Preferences › Cursors › Other Cursors › Precise also
/// shows the detection width around it, and Caps Lock swaps the preference either way, as in
/// Photoshop (#11690).
/// The cursor over the canvas: the tool's icon with its top-left tip on the point; Preferences ›
/// Cursors › Other Cursors › Precise shows the detection width around a crosshair instead, and
/// Caps Lock swaps the preference either way, as in Photoshop (#11690).
pub fn cursor(app: &PhotocraftApp, painter: &egui::Painter, p: Pos2, zoom: f32) -> egui::CursorIcon {
if crate::canvas::precise_other_cursor(app) {
let r = (app.ui.tool_options.magnetic_width.clamp(1.0, 256.0) * zoom).max(2.0);
painter.circle_stroke(p, r + 0.5, Stroke::new(1.0, Color32::from_black_alpha(140)));
painter.circle_stroke(p, r, Stroke::new(1.0, Color32::from_white_alpha(220)));
if !crate::canvas::precise_other_cursor(app) {
// The icon's lasso tip is at (1.8, 3.6) of its 24-unit box.
crate::icons::cursor(painter.ctx(), crate::icons::tool_icon(Tool::MagneticLasso), p, vec2(1.8, 3.6) / 24.0, 22.0);
return egui::CursorIcon::None;
}
let r = (app.ui.tool_options.magnetic_width.clamp(1.0, 256.0) * zoom).max(2.0);
painter.circle_stroke(p, r + 0.5, Stroke::new(1.0, Color32::from_black_alpha(140)));
painter.circle_stroke(p, r, Stroke::new(1.0, Color32::from_white_alpha(220)));
egui::CursorIcon::Crosshair
}
@@ -1,6 +1,7 @@
//! Caps Lock and the Magnetic Lasso's cursor (#11690): it swaps Preferences › Cursors › Other
//! Cursors, so with Standard and Caps Lock on the pointer shows a circle as big as the detection
//! Width (scaled with zoom), and with Precise and Caps Lock on it doesn't.
//! Width (scaled with zoom), and with Precise and Caps Lock on it is the tool's icon, as with
//! Standard alone.
use serde_json::json;
@@ -19,13 +20,19 @@ fn app(other: &str, caps_lock: bool) -> PhotocraftApp {
/// The radii of the circles `cursor` draws at `zoom`, and the OS cursor it asks for.
fn drawn(app: &PhotocraftApp, zoom: f32) -> (Vec<f32>, egui::CursorIcon) {
let (radii, icon, _) = drawn_with_others(app, zoom);
(radii, icon)
}
/// As [`drawn`], plus how many shapes that are not circles it draws (the icon).
fn drawn_with_others(app: &PhotocraftApp, zoom: f32) -> (Vec<f32>, egui::CursorIcon, usize) {
let ctx = egui::Context::default();
ctx.begin_pass(egui::RawInput::default());
let painter = ctx.layer_painter(egui::LayerId::background());
let icon = super::cursor(app, &painter, egui::pos2(100.0, 100.0), zoom);
let mut out = ctx.end_pass();
out.textures_delta.clear();
let radii = out
let radii: Vec<f32> = out
.shapes
.iter()
.filter_map(|c| match &c.shape {
@@ -33,7 +40,8 @@ fn drawn(app: &PhotocraftApp, zoom: f32) -> (Vec<f32>, egui::CursorIcon) {
_ => None,
})
.collect();
(radii, icon)
let others = out.shapes.len() - radii.len();
(radii, icon, others)
}
#[test]
@@ -47,13 +55,20 @@ fn caps_lock_on_standard_draws_the_width_circle_scaled_with_zoom() {
}
#[test]
fn caps_lock_on_precise_swaps_back_to_no_circle() {
let (radii, _) = drawn(&app("precise", true), 1.0);
fn caps_lock_on_precise_swaps_back_to_the_tool_icon() {
let (radii, icon, others) = drawn_with_others(&app("precise", true), 1.0);
assert!(radii.is_empty(), "no width circle: {radii:?}");
assert_eq!(icon, egui::CursorIcon::None, "the OS cursor hides behind the icon");
assert!(others > 0, "the tool icon is drawn");
}
#[test]
fn without_caps_lock_the_preference_decides() {
assert!(drawn(&app("standard", false), 1.0).0.is_empty(), "Standard: no circle");
assert!(!drawn(&app("precise", false), 1.0).0.is_empty(), "Precise: the width circle");
let (radii, icon, others) = drawn_with_others(&app("standard", false), 1.0);
assert!(radii.is_empty(), "Standard: no circle");
assert_eq!(icon, egui::CursorIcon::None, "Standard: the tool icon, not a crosshair");
assert!(others > 0, "Standard: the tool icon is drawn");
let (radii, icon) = drawn(&app("precise", false), 1.0);
assert!(!radii.is_empty(), "Precise: the width circle");
assert_eq!(icon, egui::CursorIcon::Crosshair, "Precise: with the crosshair");
}