Files
cadcraft/crates/ui-egui/tests/it/system_cursor.rs
aiongg 9cf115e808 CI: one test binary per crate, nextest, line tables only (#1989)
* Build: line tables only in dev, no debug info for dependencies

* Tests: one integration-test binary per crate

Each crate's tests/*.rs becomes a module of tests/it/main.rs. Files that
install process-wide state (the file io hooks, user aliases, SAVETIME and
SAVEFILEPATH, user linetype and pattern files, registered fonts) stay their
own test binaries.

* xtask ci: nextest, tests without examples, one wasm check call
2026-10-23 13:34:26 -04:00

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");
}