mirror of
https://github.com/storytold/cadcraft.git
synced 2026-10-24 19:06:56 -06:00
The canvas hides the OS cursor (CursorIcon::None, which winit turns into
ShowCursor(FALSE) on Windows) and draws its own crosshair, so Windows
Magnifier's "follow the mouse pointer", screen readers, recorders and
remote desktops lose the pointer there. View > Accessibility > Show System
Cursor (ui.toggle.systemcursor, ui.set {"systemCursor": true}, or
CADCRAFT_SYSTEM_CURSOR=1 at startup) keeps a system crosshair visible at
the centre of the drawn one.
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
38 lines
1.6 KiB
Rust
38 lines
1.6 KiB
Rust
//! The OS cursor over the drawing area (#39): hidden under the drawn crosshair by default, kept
|
|
//! visible with `systemCursor` so screen magnifiers and other assistive tech can follow it.
|
|
|
|
use cadcraft_engine::Session;
|
|
use cadcraft_ui_egui::{CadApp, Services};
|
|
|
|
/// The cursor icon the app asks for with the pointer in the middle of the drawing area.
|
|
fn canvas_cursor(app: &mut CadApp) -> egui::CursorIcon {
|
|
let ctx = egui::Context::default();
|
|
let mut icon = egui::CursorIcon::Default;
|
|
// A few frames: layout settles and the pointer hover is known from the second frame on.
|
|
for _ in 0..3 {
|
|
let raw = egui::RawInput {
|
|
screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1280.0, 800.0))),
|
|
events: vec![egui::Event::PointerMoved(egui::pos2(640.0, 400.0))],
|
|
..Default::default()
|
|
};
|
|
let mut out = ctx.run_ui(raw, |ui| {
|
|
app.logic(ui.ctx());
|
|
app.ui(ui);
|
|
});
|
|
icon = out.platform_output.cursor_icon;
|
|
out.textures_delta.clear(); // no renderer here
|
|
}
|
|
icon
|
|
}
|
|
|
|
#[test]
|
|
fn system_cursor_stays_visible_over_the_canvas_when_requested() {
|
|
let mut app = CadApp::new(Session::new(), Services::default());
|
|
app.ui.system_cursor = false;
|
|
assert_eq!(canvas_cursor(&mut app), egui::CursorIcon::None, "default: the drawn crosshair replaces the OS cursor");
|
|
|
|
app.run("ui.toggle.systemcursor", serde_json::json!({ "on": true })).ok();
|
|
assert!(app.ui.system_cursor);
|
|
assert_eq!(canvas_cursor(&mut app), egui::CursorIcon::Crosshair, "systemCursor keeps an OS cursor for magnifiers");
|
|
}
|