PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Shape tools: the click-to-open-dialog tolerance is the same on HiDPI displays (#4205) (#4207)
David Mann4566f5f55fe6
diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rsindex ebbfc7a40..911e428a6 100644--- a/crates/ui-egui/src/canvas.rs+++ b/crates/ui-egui/src/canvas.rs@@ -5176,7 +5176,7 @@ pub(crate) fn finish_gesture(app: &mut PhotocraftApp, d: Drag) {Tool::FreeformPen => crate::vector_ui::freeform_finish(app, &d.points, d.lasso.as_ref().map_or(&[], |l| l.straight())),// Photoshop: a click without dragging opens Create Rectangle / Ellipse / … instead.t if crate::vector_ui::is_shape_tool(t)- && crate::shape_dialog::is_click(d.start, &d.points, app.current_zoom())+ && crate::shape_dialog::is_click(d.start, &d.points, app.point_zoom())&& crate::shape_dialog::open(app, t, d.start).is_some() => {}t if crate::vector_ui::is_shape_tool(t) => crate::vector_ui::finish_shape(app, t, d.start, [end[0], end[1]], d.live),Tool::PathSelection => crate::vector_ui::path_selection_finish(app, d.start, [end[0], end[1]]),diff --git a/crates/ui-egui/src/shape_dialog_tests.rs b/crates/ui-egui/src/shape_dialog_tests.rsindex fde2cf78c..a0b5c6159 100644--- a/crates/ui-egui/src/shape_dialog_tests.rs+++ b/crates/ui-egui/src/shape_dialog_tests.rs@@ -141,6 +141,20 @@ fn click_slop_scales_with_zoom() {assert!(is_click([10.0, 10.0], &[], 0.0));}+/// #4205: the click slop is in screen points, so on a 2x (HiDPI) display at 100 % a 2 pt jitter+/// (4 device px = 4 document px) is still a click that opens Create Rectangle, not a tiny shape.+#[test]+fn a_click_with_jitter_opens_the_dialog_on_hidpi() {+ let mut app = app();+ app.ppp = 2.0;+ let i = app.session.active_index().unwrap();+ app.ui.views[i].zoom = 1.0;+ let before = layers(&app);+ press(&mut app, Tool::Rectangle, [20.0, 30.0], [24.0, 30.0]);+ only_dialog(&app);+ assert_eq!(layers(&app), before, "a jittery click draws nothing");+}+#[test]fn cancel_draws_nothing_and_ok_remembers_the_size() {let mut app = app();