Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

test(ui-egui): the Pen-while-panning test expects Windows' fist bitmap

Khawar Zamman Waniff411fa9e14c
diff --git a/crates/ui-egui/src/hold_keys/tests.rs b/crates/ui-egui/src/hold_keys/tests.rs
index f4e006441..7f90eb387 100644
--- a/crates/ui-egui/src/hold_keys/tests.rs
+++ b/crates/ui-egui/src/hold_keys/tests.rs
@@ -215,7 +215,15 @@ fn the_pen_path_being_drawn_stays_visible_while_space_pans() {
painted_paths(&h).iter().any(|pts| pts.first().is_some_and(|p| near(p, a)) && pts.last().is_some_and(|p| near(p, b))),
"the Pen path from {a:?} to {b:?} is drawn while panning"
);
- assert_eq!(h.output().platform_output.cursor_icon, crate::tool_cursor::hand(&h.ctx, true), "the fist while panning (#2196)");
+ // The fist (#2196): the OS's own on macOS and Linux; on Windows our bitmap, over the
+ // `Crosshair` fallback `CursorLifecycle` leaves under it.
+ let out = &h.output().platform_output;
+ let fist = if cfg!(target_os = "windows") {
+ (egui::CursorIcon::Crosshair, crate::tool_cursor::hand_bitmap(&h.ctx, true).map(|i| i.rgba))
+ } else {
+ (egui::CursorIcon::Grabbing, None)
+ };
+ assert_eq!((out.cursor_icon, out.cursor_image.as_ref().map(|i| i.rgba.clone())), fist, "the fist while panning (#2196)");
release(&mut h, 190.0, 230.0, Modifiers::NONE);
key(&mut h, Key::Space, false, Modifiers::NONE);
h.run_steps(2);
diff --git a/crates/ui-egui/src/tool_cursor.rs b/crates/ui-egui/src/tool_cursor.rs
index 8b67b96d6..bc4757a3a 100644
--- a/crates/ui-egui/src/tool_cursor.rs
+++ b/crates/ui-egui/src/tool_cursor.rs
@@ -152,6 +152,12 @@ fn hand_with(ctx: &egui::Context, closed: bool, bitmap: bool) -> CursorIcon {
if closed { CursorIcon::Grabbing } else { CursorIcon::Grab }
}
+/// The bitmap [`hand`] hands Windows, for tests that check the Hand's pointer on every platform.
+#[cfg(test)]
+pub(crate) fn hand_bitmap(ctx: &egui::Context, closed: bool) -> Option<CustomCursorImage> {
+ rasterize(&Shape::Hand { closed }, native_scale(ctx))
+}
+
/// The Zoom tool's pointer: a magnifier with a plus, or a minus when it zooms `out`. winit maps
/// `ZoomIn` and `ZoomOut` to the plain arrow on Windows (#3735), so there it is a bitmap; macOS and
/// the Linux themes already draw magnifiers.