PhotoCraft: An open-source, photo editor written by scratch in pure Rust
fix(ui): an open Free Transform box takes Zoom tool drags and clicks (part of #4799) (#4808)
Marco Arnulfo78dea7c6e4b5
diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rsindex ea6da7253..c9425910e 100644--- a/crates/ui-egui/src/canvas.rs+++ b/crates/ui-egui/src/canvas.rs@@ -3255,7 +3255,8 @@ pub fn canvas_view(app: &mut PhotocraftApp, ui: &mut egui::Ui, idx: usize, rect:(buttons.started, buttons.dragged, buttons.stopped, buttons.clicked) = (false, false, false, false);}// Zoom tool drags: scrubby zoom or a zoom rectangle (zoom_tool.rs); clicks step below.- if tool == Tool::Zoom && crate::zoom_tool::drag(app, &ctx, &mut view, &xf, &buttons, response.interact_pointer_pos()) {+ // Like the Hand, the selected Zoom yields to an open Free Transform box (#4799).+ if tool == Tool::Zoom && !transform_owns_pointer && crate::zoom_tool::drag(app, &ctx, &mut view, &xf, &buttons, response.interact_pointer_pos()) {(buttons.started, buttons.dragged, buttons.stopped) = (false, false, false);}// A drag is only recognised once the pointer has moved past egui's click distance: the@@ -3389,7 +3390,7 @@ pub fn canvas_view(app: &mut PhotocraftApp, ui: &mut egui::Ui, idx: usize, rect:let click_mods = ui.input(|i| pointer_button_modifiers(&i.events, click_button)).unwrap_or(mods);let d = xf.to_doc(p);match tool {- Tool::Zoom => {+ Tool::Zoom if !transform_owns_pointer => {let nz = crate::zoom_levels::step(view.zoom, if zoom_out(click_mods.alt) { -1 } else { 1 }, view.doc_size);let center = app.session.prefs().tools.zoom_clicked_point_to_center;zoom_about(&mut view, &xf, p, nz, center, ppp);diff --git a/crates/ui-egui/src/transform_undo_tests.rs b/crates/ui-egui/src/transform_undo_tests.rsindex 2944456c8..832b22190 100644--- a/crates/ui-egui/src/transform_undo_tests.rs+++ b/crates/ui-egui/src/transform_undo_tests.rs@@ -241,6 +241,33 @@ fn the_hand_tool_does_not_steal_a_free_transform_drag() {assert!(width(&h) > 150, "the committed resize applied: {}", width(&h));}+/// With the Zoom tool selected, a Free Transform drag resizes the box rather than zooming the view:+/// the open box owns the pointer, as it does for the Hand (#4799).+#[test]+fn the_zoom_tool_does_not_steal_a_free_transform_drag() {+ let mut h = harness_tool(Tool::Zoom);+ begin(&mut h);+ let q0 = quad(&h);+ let (zoom0, center0) = (h.state().ui.views[0].zoom, h.state().ui.views[0].center);+ let inside = screen(&h, [150.0, 130.0]);+ h.event(egui::Event::PointerMoved(inside));+ h.run_steps(1);+ for pressed in [true, false] {+ h.event(egui::Event::PointerButton { pos: inside, button: PointerButton::Primary, pressed, modifiers: Modifiers::NONE });+ h.run_steps(1);+ }+ h.run_steps(2);+ assert_eq!(h.state().ui.views[0].zoom, zoom0, "a click inside the box did not zoom");+ drag(&mut h, q0[2], [300.0, 220.0]);+ let q1 = quad(&h);+ assert!(!close(q1, q0), "the drag scaled the box, not the view: {q1:?}");+ assert_eq!(h.state().ui.views[0].zoom, zoom0, "the Zoom tool did not zoom");+ assert_eq!(h.state().ui.views[0].center, center0, "the Zoom tool did not move the view");+ key(&mut h, Modifiers::NONE, Key::Enter);+ assert!(h.state().ui.transform.is_none(), "the transform committed");+ assert!(width(&h) > 150, "the committed resize applied: {}", width(&h));+}+/// With the (freehand) Lasso selected, a Free Transform of a lasso selection follows the drag: the/// Lasso reads its own pointer events, and dropped the moves and release of a drag it hadn't/// started, so the box never changed (#2153).