From 5ef7ff4132bac0fe1291ae5da4f4309898f276c2 Mon Sep 17 00:00:00 2001 From: yoriswind Date: Tue, 1 Dec 2026 18:12:20 -0800 Subject: [PATCH 1/4] Hide the brush cursor while painting when enabled --- crates/engine-core/src/prefs.rs | 2 + .../canvas/no_cursor_while_painting_tests.rs | 128 ++++++++++++++++++ crates/ui-egui/src/canvas/paint_tool.rs | 3 +- crates/ui-egui/src/canvas/tools/retouch.rs | 2 +- .../ui-egui/src/prefs/prefs_ui/custom_rows.rs | 33 ++++- crates/ui-egui/src/prefs/prefs_ui/fields.rs | 7 + crates/ui-egui/src/tools/brush_cursor.rs | 12 +- docs/scorecard.md | 4 +- 8 files changed, 182 insertions(+), 9 deletions(-) create mode 100644 crates/ui-egui/src/canvas/no_cursor_while_painting_tests.rs diff --git a/crates/engine-core/src/prefs.rs b/crates/engine-core/src/prefs.rs index 76d893ed93..ebea45d9f4 100644 --- a/crates/engine-core/src/prefs.rs +++ b/crates/engine-core/src/prefs.rs @@ -921,6 +921,7 @@ pub struct Cursors { pub painting: PaintingCursor, pub show_crosshair_in_brush_tip: bool, pub show_only_crosshair_while_painting: bool, + pub no_cursor_while_painting: bool, pub other: OtherCursor, /// Brush preview (HUD) colour. pub brush_preview_color: String, @@ -932,6 +933,7 @@ impl Default for Cursors { painting: PaintingCursor::NormalTip, show_crosshair_in_brush_tip: false, show_only_crosshair_while_painting: false, + no_cursor_while_painting: false, other: OtherCursor::Standard, brush_preview_color: "#ff0000".into(), } diff --git a/crates/ui-egui/src/canvas/no_cursor_while_painting_tests.rs b/crates/ui-egui/src/canvas/no_cursor_while_painting_tests.rs new file mode 100644 index 0000000000..36186f1c8c --- /dev/null +++ b/crates/ui-egui/src/canvas/no_cursor_while_painting_tests.rs @@ -0,0 +1,128 @@ +//! #16827: the stroke cursor is hidden only while painting. The Cursors page enforces the two +//! options' exclusivity and can recover from a preferences file with both set. + +use craft::behavior::{Cursor, PaintedCursor}; +use craft::ui::runtime::windows::WindowHost; +use egui::accesskit::{Role, Toggled}; +use egui::{Key, Modifiers, PointerButton}; +use egui_kittest::Harness; +use egui_kittest::kittest::Queryable as _; +use photocraft_engine::prefs::Cursors; +use serde_json::json; + +use crate::PhotocraftApp; +use crate::canvas::paint_tool::stroking; +use crate::guide_cursor_tests::{harness, hover, screen}; +use crate::state::Tool; + +type AppHarness = Harness<'static, Box>; + +const NO_CURSOR: &str = "cursors.noCursorWhilePainting"; +const ONLY_CROSSHAIR: &str = "cursors.showOnlyCrosshairWhilePainting"; +const HIDE_LABEL: &str = "No Cursor While Painting"; +const CROSSHAIR_LABEL: &str = "Show only crosshair while painting"; + +fn paint_prefs(h: &mut AppHarness, hide: bool, crosshair: bool) { + h.state_mut().run("prefs.set", json!({"values": { (NO_CURSOR): hide, (ONLY_CROSSHAIR): crosshair }})).unwrap(); +} + +fn canvas_cursor(h: &AppHarness) -> Cursor { + h.state().canvas_tools.last_response.as_ref().and_then(|r| r.cursor.clone()).expect("active canvas cursor") +} + +fn primary(h: &mut AppHarness, x: f32, pressed: bool, modifiers: Modifiers) { + let pos = screen(h, x, 150.0); + h.event(egui::Event::PointerButton { pos, button: PointerButton::Primary, pressed, modifiers }); + h.run_steps(2); +} + +#[test] +fn preference_is_off_in_older_cursor_settings() { + let old: Cursors = serde_json::from_value(json!({"showOnlyCrosshairWhilePainting": true})).unwrap(); + assert!(old.show_only_crosshair_while_painting); + assert!(!old.no_cursor_while_painting); +} + +#[test] +fn hides_during_a_real_stroke_and_restores_the_tip_on_release() { + let mut h = harness(Tool::Brush); + h.state_mut().background_jobs = false; + h.state_mut().run("layer.new.layer", json!({})).unwrap(); + h.state_mut().session.tools.brush.size = 40.0; + WindowHost::of(&h.ctx).set_caps_lock(Some(false)); + let hidden = Cursor::Painted(PaintedCursor::Hidden); + let crosshair = Cursor::Painted(PaintedCursor::Crosshair); + for (hide, only_crosshair) in [(false, false), (true, false), (true, true)] { + paint_prefs(&mut h, hide, only_crosshair); + hover(&mut h, 100.0, 150.0, Modifiers::NONE); + let tip = canvas_cursor(&h); + assert!(matches!(tip, Cursor::Painted(PaintedCursor::Circle { .. } | PaintedCursor::Outline { .. })), "{tip:?}"); + primary(&mut h, 100.0, true, Modifiers::NONE); + assert!(stroking(h.state()).is_some(), "the press starts a paint stroke"); + let expected = if only_crosshair { + &crosshair + } else if hide { + &hidden + } else { + &tip + }; + assert_eq!(&canvas_cursor(&h), expected); + hover(&mut h, 110.0, 150.0, Modifiers::NONE); + assert!(stroking(h.state()).is_some(), "the drag is still a paint stroke"); + if hide { + assert_eq!(&canvas_cursor(&h), expected); + } + primary(&mut h, 110.0, false, Modifiers::NONE); + assert!(stroking(h.state()).is_none(), "the release ends the stroke"); + hover(&mut h, 100.0, 150.0, Modifiers::NONE); + assert_eq!(canvas_cursor(&h), tip, "the brush tip returns"); + } + + paint_prefs(&mut h, true, false); + hover(&mut h, 100.0, 150.0, Modifiers::ALT); + let sampler = canvas_cursor(&h); + assert_ne!(sampler, hidden); + primary(&mut h, 100.0, true, Modifiers::ALT); + assert!(stroking(h.state()).is_none(), "the Alt press is owned by the sampler"); + assert_eq!(canvas_cursor(&h), sampler, "the sampler keeps its cursor with the button down"); + primary(&mut h, 100.0, false, Modifiers::ALT); +} + +fn check(h: &AppHarness, label: &str) -> (bool, Option) { + let node = h.get_by_role_and_label(Role::CheckBox, label); + let node = node.accesskit_node(); + (!node.is_disabled(), node.toggled()) +} + +fn toggle_with_keyboard(h: &mut AppHarness, label: &str) { + h.get_by_role_and_label(Role::CheckBox, label).focus(); + h.run_steps(2); + assert!(h.get_by_role_and_label(Role::CheckBox, label).is_focused()); + h.key_press(Key::Space); + h.run_steps(2); +} + +#[test] +fn mutually_exclusive_checkbox_drafts_can_be_changed_with_space() { + let mut h = harness(Tool::Brush); + paint_prefs(&mut h, true, true); + h.state_mut().run("prefs.set", json!({"path": "interface.language", "value": "en"})).unwrap(); + h.run_steps(2); + crate::prefs_ui::open_preferences(h.state_mut(), "cursors"); + h.run_steps(4); + let on = (true, Some(Toggled::True)); + let off = (true, Some(Toggled::False)); + let disabled = (false, Some(Toggled::False)); + assert_eq!(check(&h, CROSSHAIR_LABEL), on); + assert_eq!(check(&h, HIDE_LABEL), disabled); + toggle_with_keyboard(&mut h, CROSSHAIR_LABEL); + assert_eq!(check(&h, CROSSHAIR_LABEL), off); + assert_eq!(check(&h, HIDE_LABEL), off, "clearing the effective option clears the stale hidden draft"); + toggle_with_keyboard(&mut h, HIDE_LABEL); + assert_eq!(check(&h, HIDE_LABEL), on); + assert_eq!(check(&h, CROSSHAIR_LABEL), disabled); + assert!(h.state().session.prefs().cursors.show_only_crosshair_while_painting, "changes are still in the draft"); + crate::prefs_ui::apply_window(h.state_mut()).unwrap(); + assert!(h.state().session.prefs().cursors.no_cursor_while_painting); + assert!(!h.state().session.prefs().cursors.show_only_crosshair_while_painting); +} diff --git a/crates/ui-egui/src/canvas/paint_tool.rs b/crates/ui-egui/src/canvas/paint_tool.rs index 0d7ba055f5..b4fdae03a0 100644 --- a/crates/ui-egui/src/canvas/paint_tool.rs +++ b/crates/ui-egui/src/canvas/paint_tool.rs @@ -531,7 +531,8 @@ impl CanvasTool for PaintTool<'_> { if let Some(cursor) = click_tool_cursor(tool, cx.precise()) { return cursor; } - crate::brush_cursor::cursor(app, cx) + // This tool owns the paint state while the canvas host runs. + crate::brush_cursor::cursor(app, cx, self.state.stroke.is_some()) }) } diff --git a/crates/ui-egui/src/canvas/tools/retouch.rs b/crates/ui-egui/src/canvas/tools/retouch.rs index 64b29421ee..d8d931924d 100644 --- a/crates/ui-egui/src/canvas/tools/retouch.rs +++ b/crates/ui-egui/src/canvas/tools/retouch.rs @@ -336,7 +336,7 @@ impl CanvasTool for SourceTool<'_> { /// The painting tool's brush cursor with ⌥ held: the tip with its centre mark, or the Healing /// Brush's sample target (`cursor_policy::source_target`). fn cursor(&self, cx: &ToolContext<'_>) -> Cursor { - self.scope.with_app(|app| crate::brush_cursor::cursor(app, cx)) + self.scope.with_app(|app| crate::brush_cursor::cursor(app, cx, false)) } fn command_form(&self) -> ToolPath { diff --git a/crates/ui-egui/src/prefs/prefs_ui/custom_rows.rs b/crates/ui-egui/src/prefs/prefs_ui/custom_rows.rs index 92cbda9b71..1cfb9f7b83 100644 --- a/crates/ui-egui/src/prefs/prefs_ui/custom_rows.rs +++ b/crates/ui-egui/src/prefs/prefs_ui/custom_rows.rs @@ -10,7 +10,7 @@ use craft::theme_store::ui::AppearancePage; use craft::theme_store::{SelectionChange, SuiteView}; use craft::ui::buttons::Button; use craft::ui::choice::Checkbox; -use craft::ui::contract::{Bind, Entry, Props as _, Show as _, ShowContainer as _}; +use craft::ui::contract::{Bind, Entry, FieldLayout, Props as _, Show as _, ShowContainer as _}; use craft::ui::display::Text; use craft::ui::form::Field; use craft::ui::layout_components::Row; @@ -22,7 +22,7 @@ use craft::ui::style::TypeRole; use craft::ui::text::{NumberField, TextField, TextWords}; use serde_json::{Value, json}; -use super::fields::{PrefPages, choice_label}; +use super::fields::{PAINT_CROSSHAIR, PAINT_NO_CURSOR, PAINT_NO_CURSOR_LABEL, PrefPages, choice_label}; use super::{PhotocraftApp, prefs}; use craft::ui::patterns::preferences::{CustomSettings, SettingsDraft}; @@ -98,6 +98,7 @@ impl CustomSettings for PrefsCustom { "tools.tabletInput" => tablet_input_row(ui, draft), APPEARANCE_MODE => self.appearance_row(ui, draft), RAW_RESOLUTION => raw_resolution_row(ui, draft), + PAINT_CROSSHAIR | PAINT_NO_CURSOR => painting_cursor_row(ui, key, draft, self.lang), _ => {} } false @@ -141,6 +142,34 @@ fn help(ui: &mut egui::Ui, text: &str) { Text::new(text.to_string()).role(TypeRole::Caption).show(ui); } +/// Draws either mutually exclusive stroke cursor option over the current draft. +fn painting_cursor_row(ui: &mut egui::Ui, key: &str, draft: &mut SettingsDraft, fallback_lang: crate::i18n::Lang) { + let crosshair = draft.get(PAINT_CROSSHAIR).unwrap_or(false); + // An edited preferences file can contain both. Show the effective crosshair option so it can be turned off. + let hidden = !crosshair && draft.get(PAINT_NO_CURSOR).unwrap_or(false); + let (checked, enabled, other, english) = if key == PAINT_CROSSHAIR { + (crosshair, !hidden, PAINT_NO_CURSOR, "Show only crosshair while painting") + } else { + (hidden, !crosshair, PAINT_CROSSHAIR, PAINT_NO_CURSOR_LABEL) + }; + let i18n = crate::i18n::framework_i18n(); + let code = draft.get::("interface.language"); + let lang = match code.as_deref() { + Some("auto") => i18n.system_lang(), + code => code.and_then(|code| i18n.from_code(code)).or_else(|| i18n.from_code(fallback_lang.code())).unwrap_or(craft::i18n::Lang::EN), + }; + let label = i18n.tid(lang, &format!("setting.{key}"), english); + let label = if label.is_empty() { english } else { label }; + let mut value = checked; + Field::new(label.to_owned()).id_salt(key).layout(FieldLayout::After).enabled(enabled).show(ui, |ui, _| { + Checkbox::new(Bind::bound(&mut value)).show(ui); + }); + if value != checked { + draft.set(key, &value); + draft.set(other, &false); + } +} + /// A select over `(id, label)` options; the id picked this pass. fn choose(ui: &mut egui::Ui, label: &str, salt: &'static str, current: String, options: &[(String, String)]) -> Option { let entries: Vec> = options.iter().map(|(id, name)| Entry::new(id.clone(), name.clone())).collect(); diff --git a/crates/ui-egui/src/prefs/prefs_ui/fields.rs b/crates/ui-egui/src/prefs/prefs_ui/fields.rs index d56107481c..964451a23f 100644 --- a/crates/ui-egui/src/prefs/prefs_ui/fields.rs +++ b/crates/ui-egui/src/prefs/prefs_ui/fields.rs @@ -8,6 +8,10 @@ use photocraft_engine::prefs::{self, SECTIONS}; use serde::{Deserialize, Serialize}; use serde_json::{Map, Value}; +pub(super) const PAINT_CROSSHAIR: &str = "cursors.showOnlyCrosshairWhilePainting"; +pub(super) const PAINT_NO_CURSOR: &str = "cursors.noCursorWhilePainting"; +pub(super) const PAINT_NO_CURSOR_LABEL: &str = "No Cursor While Painting"; + /// The engine's editable preference pages, by their serde names: the settings struct the window's document is /// built over. The engine's other preference fields (shortcuts, layouts, remembered dialogs) are not Preferences /// pages and stay out of the document. @@ -182,6 +186,9 @@ pub(super) fn rules(ctx: &egui::Context) -> Vec { for path in ["interface.appearanceMode", "performance.renderingMode", "performance.memoryUsageMb", "performance.memoryUsagePercent"] { tweak(&mut rules, path, |r| r.custom_rows()); } + // The two stroke cursor checkboxes need to read each other's draft value to decide whether they are enabled. + tweak(&mut rules, PAINT_CROSSHAIR, |r| r.custom_rows()); + tweak(&mut rules, PAINT_NO_CURSOR, |r| r.label(PAINT_NO_CURSOR_LABEL).custom_rows()); // The favourite fonts are the user's library, not a Type setting. tweak(&mut rules, "type.favoriteFonts", |r| r.keep_on_reset()); diff --git a/crates/ui-egui/src/tools/brush_cursor.rs b/crates/ui-egui/src/tools/brush_cursor.rs index fe4eb523bf..948740d515 100644 --- a/crates/ui-egui/src/tools/brush_cursor.rs +++ b/crates/ui-egui/src/tools/brush_cursor.rs @@ -6,7 +6,7 @@ //! [`cursor`] builds it per call. use craft::behavior::kurbo::Rect; -use craft::behavior::{Cursor, CursorIcon, PointerSample}; +use craft::behavior::{Cursor, CursorIcon, PaintedCursor, PointerSample}; use craft::keymap::Mods; use craft::ui::canvas::ToolContext; use craft::ui::canvas_controls::brush::{BrushCursor, BrushCursorOptions, BrushTip, BrushTipOutline, PaintingCursor, TipPose, TipRings}; @@ -130,7 +130,7 @@ fn painting_cursor(pref: PaintingPref) -> PaintingCursor { /// The cursor of the active painting tool over the canvas. Reads the tip [`sync_tip`] built; with no view or no /// tip it is the system arrow. -pub(crate) fn cursor(app: &PhotocraftApp, cx: &ToolContext<'_>) -> Cursor { +pub(crate) fn cursor(app: &PhotocraftApp, cx: &ToolContext<'_>, painting: bool) -> Cursor { let arrow = Cursor::System(CursorIcon::Default); let Some(space) = cx.space() else { return arrow }; let tool = app.ui.tool; @@ -142,8 +142,10 @@ pub(crate) fn cursor(app: &PhotocraftApp, cx: &ToolContext<'_>) -> Cursor { if crate::canvas::cursor_policy::source_target(tool, option, prefs.painting, cx.caps_lock) { return crate::canvas::cursor_policy::sample_target(); } + if painting && prefs.no_cursor_while_painting && !prefs.show_only_crosshair_while_painting { + return Cursor::Painted(PaintedCursor::Hidden); + } let centre = crate::canvas::cursor_policy::brush_tip_centre(tool, option, prefs.show_crosshair_in_brush_tip); - let painting = crate::canvas::paint_tool::stroking(app).is_some(); // The framework's Standard cursor is the tool's icon. let icon = crate::icons::tool_icon(tool); let brush = &app.session.tools.brush; @@ -178,3 +180,7 @@ pub(crate) fn cursor(app: &PhotocraftApp, cx: &ToolContext<'_>) -> Cursor { #[cfg(test)] #[path = "../canvas/eraser_block_caps_lock_cursor_tests.rs"] mod eraser_block_caps_lock_cursor_tests; + +#[cfg(test)] +#[path = "../canvas/no_cursor_while_painting_tests.rs"] +mod no_cursor_while_painting_tests; diff --git a/docs/scorecard.md b/docs/scorecard.md index e984cf914e..692d5d4bee 100644 --- a/docs/scorecard.md +++ b/docs/scorecard.md @@ -9,7 +9,7 @@ Generated by `cargo xtask scorecard` from `perf/budgets.toml`, `perf/baseline.js | [Performance](#performance) | 3 | 22 | 59 | 93 scenarios: 3 within budget, 22 over budget or failing, 9 tracked only, 55 not run, 4 not measurable yet (baseline 2026-10-05) | | [File compatibility](#file-compatibility) | 11 | 14 | 2 | io corpus: oracle ≥ 148/170, round trip ≥ 169/170; psd-tools corpus: oracle ≥ 249/309, round trip ≥ 308/309; photoshop oracles: oracle ≥ 190/258, round trip ≥ 258/258 | | [Tools](#tools) | 36 | 9 | 0 | | -| [Workspace and UI](#workspace-and-ui) | 15 | 6 | 2 | settings that do nothing: 9 of 204 (target 0) | +| [Workspace and UI](#workspace-and-ui) | 15 | 6 | 2 | settings that do nothing: 9 of 205 (target 0) | | [Type](#type) | 5 | 6 | 0 | | | [Automation](#automation) | 6 | 4 | 2 | 663 of 663 menu items live (100.0%) | | [Reliability](#reliability) | 5 | 2 | 0 | never-crash lints on 28 of 28 crates; panic_hunt present | @@ -217,7 +217,7 @@ Corpus floors (`crates/io/tests/it/corpus.rs`): the enforced minimums; the corpu ## Workspace and UI -**Settings that do nothing: 9 of 204** (target 0, #204). Counted by the prefs audit (`xtask/src/scorecard.rs`): a `Preferences` field counts as read when code outside the prefs model (`prefs.rs` except its `impl Session` blocks; tests excluded; the schema-driven dialog never names a field) accesses `section.field`, or `.section` and `.field` in the same file, or calls a section method that reads `self.field`. It is a heuristic lower bound: a generic name can look read when it isn't. +**Settings that do nothing: 9 of 205** (target 0, #204). Counted by the prefs audit (`xtask/src/scorecard.rs`): a `Preferences` field counts as read when code outside the prefs model (`prefs.rs` except its `impl Session` blocks; tests excluded; the schema-driven dialog never names a field) accesses `section.field`, or `.section` and `.field` in the same file, or calls a section method that reads `self.field`. It is a heuristic lower bound: a generic name can look read when it isn't. Unread: `general.color_picker`, `workspace.auto_show_hidden_panels`, `workspace.enable_floating_document_window_docking`, `workspace.enable_narrow_options_bar`, `performance.legacy_compositing`, `plug_ins.show_extension_panels`, `plug_ins.allow_scripts_to_connect`, `type_.text_engine`, `enhanced_controls.scrubby_slider_acceleration`. From 2d865a1e16b133e6a761890109aa712823975284 Mon Sep 17 00:00:00 2001 From: yoriswind Date: Tue, 1 Dec 2026 18:25:36 -0800 Subject: [PATCH 2/4] Import the brush test access tree trait --- crates/ui-egui/src/canvas/no_cursor_while_painting_tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ui-egui/src/canvas/no_cursor_while_painting_tests.rs b/crates/ui-egui/src/canvas/no_cursor_while_painting_tests.rs index 36186f1c8c..fd2fe385cd 100644 --- a/crates/ui-egui/src/canvas/no_cursor_while_painting_tests.rs +++ b/crates/ui-egui/src/canvas/no_cursor_while_painting_tests.rs @@ -6,7 +6,7 @@ use craft::ui::runtime::windows::WindowHost; use egui::accesskit::{Role, Toggled}; use egui::{Key, Modifiers, PointerButton}; use egui_kittest::Harness; -use egui_kittest::kittest::Queryable as _; +use egui_kittest::kittest::{NodeT as _, Queryable as _}; use photocraft_engine::prefs::Cursors; use serde_json::json; From dd20a107797912c8bd854b37556eda1ea78699dd Mon Sep 17 00:00:00 2001 From: yoriswind Date: Tue, 1 Dec 2026 18:34:20 -0800 Subject: [PATCH 3/4] Preserve Caps Lock cursors during brush strokes --- .../canvas/no_cursor_while_painting_tests.rs | 30 +++++++++++++++++++ crates/ui-egui/src/tools/brush_cursor.rs | 2 +- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/canvas/no_cursor_while_painting_tests.rs b/crates/ui-egui/src/canvas/no_cursor_while_painting_tests.rs index fd2fe385cd..d404f99d52 100644 --- a/crates/ui-egui/src/canvas/no_cursor_while_painting_tests.rs +++ b/crates/ui-egui/src/canvas/no_cursor_while_painting_tests.rs @@ -88,6 +88,36 @@ fn hides_during_a_real_stroke_and_restores_the_tip_on_release() { primary(&mut h, 100.0, false, Modifiers::ALT); } +#[test] +fn caps_lock_keeps_the_precise_crosshair_and_the_block_square_during_strokes() { + let crosshair = Cursor::Painted(PaintedCursor::Crosshair); + let hidden = Cursor::Painted(PaintedCursor::Hidden); + for tool in [Tool::Brush, Tool::Eraser] { + let mut h = harness(tool); + h.state_mut().background_jobs = false; + h.state_mut().run("layer.new.layer", json!({})).unwrap(); + h.state_mut().run("edit.fill", json!({"contents": "color", "color": "#ff8000"})).unwrap(); + h.state_mut().ui.tool_options.eraser_mode = "block".into(); + h.state_mut().session.tools.brush.size = 40.0; + paint_prefs(&mut h, true, false); + WindowHost::of(&h.ctx).set_caps_lock(Some(true)); + hover(&mut h, 100.0, 150.0, Modifiers::NONE); + let expected = canvas_cursor(&h); + if tool == Tool::Brush { + assert_eq!(expected, crosshair); + } else { + assert!(matches!(expected, Cursor::Painted(_))); + assert_ne!(expected, crosshair); + assert_ne!(expected, hidden); + } + + primary(&mut h, 100.0, true, Modifiers::NONE); + assert!(stroking(h.state()).is_some()); + assert_eq!(canvas_cursor(&h), expected); + primary(&mut h, 100.0, false, Modifiers::NONE); + } +} + fn check(h: &AppHarness, label: &str) -> (bool, Option) { let node = h.get_by_role_and_label(Role::CheckBox, label); let node = node.accesskit_node(); diff --git a/crates/ui-egui/src/tools/brush_cursor.rs b/crates/ui-egui/src/tools/brush_cursor.rs index 948740d515..19118eb9c8 100644 --- a/crates/ui-egui/src/tools/brush_cursor.rs +++ b/crates/ui-egui/src/tools/brush_cursor.rs @@ -142,7 +142,7 @@ pub(crate) fn cursor(app: &PhotocraftApp, cx: &ToolContext<'_>, painting: bool) if crate::canvas::cursor_policy::source_target(tool, option, prefs.painting, cx.caps_lock) { return crate::canvas::cursor_policy::sample_target(); } - if painting && prefs.no_cursor_while_painting && !prefs.show_only_crosshair_while_painting { + if painting && prefs.no_cursor_while_painting && !prefs.show_only_crosshair_while_painting && !cx.caps_lock { return Cursor::Painted(PaintedCursor::Hidden); } let centre = crate::canvas::cursor_policy::brush_tip_centre(tool, option, prefs.show_crosshair_in_brush_tip); From 67fa838052656bccfa135d0b63b3f5d8825d529f Mon Sep 17 00:00:00 2001 From: yoriswind Date: Tue, 1 Dec 2026 19:05:08 -0800 Subject: [PATCH 4/4] Exercise Caps Lock with visible cursors in the stroke fixture --- .../canvas/no_cursor_while_painting_tests.rs | 40 +++++++++++-------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/crates/ui-egui/src/canvas/no_cursor_while_painting_tests.rs b/crates/ui-egui/src/canvas/no_cursor_while_painting_tests.rs index d404f99d52..2b45cc13a2 100644 --- a/crates/ui-egui/src/canvas/no_cursor_while_painting_tests.rs +++ b/crates/ui-egui/src/canvas/no_cursor_while_painting_tests.rs @@ -89,7 +89,7 @@ fn hides_during_a_real_stroke_and_restores_the_tip_on_release() { } #[test] -fn caps_lock_keeps_the_precise_crosshair_and_the_block_square_during_strokes() { +fn caps_lock_keeps_the_brush_crosshair_and_the_block_eraser_icon_during_strokes() { let crosshair = Cursor::Painted(PaintedCursor::Crosshair); let hidden = Cursor::Painted(PaintedCursor::Hidden); for tool in [Tool::Brush, Tool::Eraser] { @@ -98,23 +98,31 @@ fn caps_lock_keeps_the_precise_crosshair_and_the_block_square_during_strokes() { h.state_mut().run("layer.new.layer", json!({})).unwrap(); h.state_mut().run("edit.fill", json!({"contents": "color", "color": "#ff8000"})).unwrap(); h.state_mut().ui.tool_options.eraser_mode = "block".into(); - h.state_mut().session.tools.brush.size = 40.0; + // In Normal Brush Tip mode a wide aliased cell returns the hidden SDK pointer; + // Standard supplies a visible icon so we can observe the preference taking effect. + h.state_mut().run("prefs.set", json!({"path": "cursors.painting", "value": "standard"})).unwrap(); paint_prefs(&mut h, true, false); - WindowHost::of(&h.ctx).set_caps_lock(Some(true)); - hover(&mut h, 100.0, 150.0, Modifiers::NONE); - let expected = canvas_cursor(&h); - if tool == Tool::Brush { - assert_eq!(expected, crosshair); - } else { - assert!(matches!(expected, Cursor::Painted(_))); - assert_ne!(expected, crosshair); - assert_ne!(expected, hidden); - } - primary(&mut h, 100.0, true, Modifiers::NONE); - assert!(stroking(h.state()).is_some()); - assert_eq!(canvas_cursor(&h), expected); - primary(&mut h, 100.0, false, Modifiers::NONE); + for caps in [false, true] { + WindowHost::of(&h.ctx).set_caps_lock(Some(caps)); + hover(&mut h, 100.0, 150.0, Modifiers::NONE); + let idle = canvas_cursor(&h); + if caps && tool == Tool::Brush { + assert_eq!(idle, crosshair); + } else { + assert!( + matches!(&idle, Cursor::Painted(PaintedCursor::Tool { icon, .. }) if *icon == crate::icons::tool_icon(tool)), + "expected the {tool:?} icon, got {idle:?}" + ); + } + + primary(&mut h, 100.0, true, Modifiers::NONE); + assert!(stroking(h.state()).is_some()); + assert_eq!(&canvas_cursor(&h), if caps { &idle } else { &hidden }); + primary(&mut h, 100.0, false, Modifiers::NONE); + assert!(stroking(h.state()).is_none()); + assert_eq!(canvas_cursor(&h), idle); + } } }