Cursors: Use Precise Cursors and Caps Lock hide the brush tip outline again

The view info the canvas gives the tools never set its precise flag, so
the Blob Brush and the Eraser drew their tip outline around the precise
crosshair whatever the setting. Nothing passed the host's Caps Lock
state to the session either, so `view.capsLock` changed nothing.

- The view info's precise flag is on while Use Precise Cursors or Caps
  Lock is on, as before the move to the shared canvas.
- The canvas passes each change of the host's Caps Lock state to
  `view.capsLock`; a `view.capsLock` call stays in effect until the next
  change.
- The canvas's pointer follows the same flag, so with both on the
  drawing tools keep the crosshair.
This commit is contained in:
dotCooCoo
2026-11-25 21:43:49 -08:00
parent 2b7dd67ac0
commit fb68251203
5 changed files with 101 additions and 2 deletions
+1
View File
@@ -150,6 +150,7 @@ impl VectorcraftApp {
carry_target: None,
last_drag: None,
escaped_press: false,
host_caps_lock: None,
committed_preview: false,
panes: Default::default(),
windows: crate::doc_windows::Windows::new(known),
+22 -1
View File
@@ -406,7 +406,28 @@ impl VectorcraftApp {
shape_widgets: self.ui.view.shape_widgets,
screen: self.screen_frame(),
artboard: self.view().map_or(0, |v| v.artboard),
..ViewInfo::default()
precise: self.precise_cursors(),
}
}
/// Whether the drawing tools show precise cursors: General › Use Precise Cursors is on, or Caps Lock is
/// (`Session::caps_lock`, which the canvas keeps at the host's state and `view.capsLock` sets). The canvas's pointer
/// and the tools' brush tips both follow it.
pub(crate) fn precise_cursors(&self) -> bool {
self.session.prefs.use_precise_cursors || self.session.caps_lock
}
/// Takes the host's Caps Lock state `on` when it changes: the session follows it until the next change, and a
/// `view.capsLock` call between changes stays in place.
pub(crate) fn follow_caps_lock(&mut self, on: bool) {
if self.canvas.host_caps_lock == Some(on) {
return;
}
self.canvas.host_caps_lock = Some(on);
if self.session.caps_lock != on
&& let Err(err) = self.run("view.capsLock", serde_json::json!({ "on": on }))
{
log::error!("Could not update the Caps Lock state: {err}");
}
}
}
+3
View File
@@ -107,6 +107,9 @@ pub struct CanvasCache {
/// Escape cancelled the tool's press while the button is still down: its release still sends the tool its Up,
/// which gives back a selection tool Cmd lent.
pub escaped_press: bool,
/// The host's Caps Lock state at the last canvas pass, which `VectorcraftApp::follow_caps_lock` compares with the
/// next reading; `None` before the first pass.
pub host_caps_lock: Option<bool>,
/// A press on the canvas committed a panel field's running preview before the tool took the press, as the field's
/// commit came first in production: the field's own commit later in the pass has nothing left to run.
pub committed_preview: bool,
+6 -1
View File
@@ -194,6 +194,11 @@ pub(crate) fn show_document(app: &mut VectorcraftApp, ui: &mut Ui, win: Win, kin
};
let pasteboard = app.session.documents().get(win.0).map(|st| artboards::pasteboard_color(app, st, app.outline_view()));
let layers = move || bounds;
let host_caps_lock = craft::ui::runtime::lock_keys::caps_lock(ui.ctx());
app.follow_caps_lock(host_caps_lock);
// The canvas reverses the state it is given while the host's Caps Lock is on: given this, it shows the precise
// cursors the tools are told about.
let precise = app.precise_cursors() != host_caps_lock;
let prefs = &app.session.prefs;
let mut canvas = Canvas::new("Document")
.id(canvas_id(win))
@@ -205,7 +210,7 @@ pub(crate) fn show_document(app: &mut VectorcraftApp, ui: &mut Ui, win: Win, kin
.body_nudges(ARROWS)
.rulers(x, y)
.with_rulers(strips)
.precise_cursors(prefs.use_precise_cursors);
.precise_cursors(precise);
if let Some(pasteboard) = pasteboard {
canvas = canvas.pasteboard(pasteboard);
}
@@ -67,3 +67,72 @@ fn bucket_modifier_only_hover_updates_the_visible_cursor() {
assert_ne!(alt, plain, "Alt shows the Eyedropper's cursor");
assert_eq!(shown(&mut app, egui::Modifiers::NONE), plain, "and letting go brings the bucket back");
}
/// The Blob Brush's or the Eraser's tip outline at the pointer, as the canvas draws it this pass.
fn shows_tip(app: &mut VectorcraftApp) -> bool {
let view = app.view_info();
app.session.overlays(view).iter().any(|o| matches!(o, vectorcraft_tools::Overlay::Path { .. }))
}
/// Use Precise Cursors or Caps Lock, or both, gives the Blob Brush and the Eraser only the crosshair: the tool draws no
/// tip outline around it. With both off, each shows its own pointer and the tip outline.
#[test]
fn precise_cursors_hide_the_brush_tip_outline() {
use craft::ui::runtime::windows::WindowHost;
let crosshair = Some(crate::cursors::tool_cursor(vectorcraft_tools::Cursor::Crosshair));
for tool in ["blobBrush", "eraser"] {
let mut app = VectorcraftApp::new(Session::new(), Default::default());
app.run("file.new", serde_json::json!({"width": 400, "height": 300})).unwrap();
app.select_tool(tool);
let ctx = crate::testing::ui_context();
frame(&mut app, &ctx, vec![]);
let at = app.canvas_view().unwrap().to_screen(Point::new(200.0, 150.0));
for (preference, caps_lock) in [(false, false), (true, false), (false, true), (true, true), (false, false)] {
app.run("prefs.set", serde_json::json!({"key": "usePreciseCursors", "value": preference})).unwrap();
WindowHost::of(&ctx).set_caps_lock(Some(caps_lock));
frame(&mut app, &ctx, vec![egui::Event::PointerMoved(at)]);
frame(&mut app, &ctx, vec![egui::Event::PointerMoved(at + egui::vec2(1.0, 0.0))]);
let precise = preference || caps_lock;
let case = format!("{tool}, Use Precise Cursors {preference}, Caps Lock {caps_lock}");
assert_eq!(app.session.caps_lock, caps_lock, "{case}: the session takes the host's Caps Lock state");
assert_eq!(app.view_info().precise, precise, "{case}");
assert_eq!(shows_tip(&mut app), !precise, "{case}");
assert_eq!(craft::ui::runtime::cursor::current(&ctx) == crosshair, precise, "{case}");
}
}
}
/// `view.capsLock` sets the Caps Lock state the tools and the canvas's pointer follow until the host's state changes.
#[test]
fn the_caps_lock_command_gives_the_brushes_the_crosshair() {
use craft::ui::runtime::windows::WindowHost;
let crosshair = Some(crate::cursors::tool_cursor(vectorcraft_tools::Cursor::Crosshair));
let mut app = VectorcraftApp::new(Session::new(), Default::default());
app.run("file.new", serde_json::json!({"width": 400, "height": 300})).unwrap();
app.select_tool("blobBrush");
let ctx = crate::testing::ui_context();
WindowHost::of(&ctx).set_caps_lock(Some(false));
frame(&mut app, &ctx, vec![]);
let at = app.canvas_view().unwrap().to_screen(Point::new(200.0, 150.0));
frame(&mut app, &ctx, vec![egui::Event::PointerMoved(at)]);
assert!(shows_tip(&mut app));
app.run("view.capsLock", serde_json::json!({"on": true})).unwrap();
frame(&mut app, &ctx, vec![egui::Event::PointerMoved(at + egui::vec2(1.0, 0.0))]);
assert!(app.session.caps_lock, "the host's unchanged state leaves the command's in place");
assert!(!shows_tip(&mut app));
assert_eq!(craft::ui::runtime::cursor::current(&ctx), crosshair);
app.run("view.capsLock", serde_json::json!({"on": false})).unwrap();
frame(&mut app, &ctx, vec![egui::Event::PointerMoved(at)]);
assert!(shows_tip(&mut app));
assert_ne!(craft::ui::runtime::cursor::current(&ctx), crosshair);
// With the host's Caps Lock on, the command turns it off for the tools and the canvas's pointer alike.
WindowHost::of(&ctx).set_caps_lock(Some(true));
frame(&mut app, &ctx, vec![egui::Event::PointerMoved(at + egui::vec2(1.0, 0.0))]);
assert!(!shows_tip(&mut app));
assert_eq!(craft::ui::runtime::cursor::current(&ctx), crosshair);
app.run("view.capsLock", serde_json::json!({"on": false})).unwrap();
frame(&mut app, &ctx, vec![egui::Event::PointerMoved(at)]);
assert!(!app.session.caps_lock);
assert!(shows_tip(&mut app));
assert_ne!(craft::ui::runtime::cursor::current(&ctx), crosshair);
}