PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Hand tool: a middle-button pan keeps panning when ⌘ or ⌥ goes down (#6434)
Khawar Zamman Wani57519aee7dee
diff --git a/crates/ui-egui/src/hold_keys.rs b/crates/ui-egui/src/hold_keys.rsindex e492515e6..8b8bef092 100644--- a/crates/ui-egui/src/hold_keys.rs+++ b/crates/ui-egui/src/hold_keys.rs@@ -124,10 +124,11 @@ fn cmd_move_held(app: &PhotocraftApp, i: &InputState) -> bool {/// without ⌘) Zoom Out, as in Photoshop; the Modifier Keys panel's latched keys count. Not while/// Free Transform is open (its box keeps ⌘ for the distort handles), and a modifier pressed during/// a Hand press doesn't turn it into a zoom, release included: only a press made with it held-/// zooms (that one is latched by [`for_frame`] until the button comes up).+/// zooms (that one is latched by [`for_frame`] until the button comes up). A middle-button pan+/// stays a pan whatever is held.fn hand_zoom(app: &PhotocraftApp, i: &InputState) -> Option<Temporary> {let p = &i.pointer;- let hand_press = (p.primary_down() || p.primary_released()) && !p.primary_pressed();+ let hand_press = ((p.primary_down() || p.primary_released()) && !p.primary_pressed()) || p.middle_down();if app.ui.tool != Tool::Hand || app.ui.transform.is_some() || hand_press {return None;}diff --git a/crates/ui-egui/src/hold_keys/tests.rs b/crates/ui-egui/src/hold_keys/tests.rsindex e88ec917a..c66bdc920 100644--- a/crates/ui-egui/src/hold_keys/tests.rs+++ b/crates/ui-egui/src/hold_keys/tests.rs@@ -857,6 +857,31 @@ fn modifiers_pressed_during_a_hand_pan_keep_panning() {}}+/// A middle-button pan with the Hand selected keeps panning when ⌘ or ⌥ goes down during it.+#[test]+fn modifiers_pressed_during_a_middle_button_pan_keep_panning() {+ for m in [Modifiers::COMMAND, Modifiers::ALT] {+ let mut h = harness(Tool::Hand);+ let (z0, c0) = (h.state().ui.views[0].zoom, h.state().ui.views[0].center);+ let p = screen(&h, 200.0, 150.0);+ h.event(Event::PointerMoved(p));+ h.run_steps(1);+ h.event(Event::PointerButton { pos: p, button: PointerButton::Middle, pressed: true, modifiers: Modifiers::NONE });+ h.run_steps(1);+ hold_mods(&mut h, m);+ assert_eq!(held_tool(h.state(), &h.ctx), None, "{m:?}");+ let q = p + vec2(60.0, 40.0);+ h.event(Event::PointerMoved(q));+ h.run_steps(2);+ h.event(Event::PointerButton { pos: q, button: PointerButton::Middle, pressed: false, modifiers: platform(m) });+ h.run_steps(1);+ hold_mods(&mut h, Modifiers::NONE);+ let v = &h.state().ui.views[0];+ assert_eq!(v.zoom, z0, "{m:?}: no zoom");+ assert!(v.center[0] < c0[0] - 30.0 && v.center[1] < c0[1] - 20.0, "{m:?}: panned {c0:?} -> {:?}", v.center);+ }+}+/// Free Transform keeps ⌘ (its distort handles) while the Hand is selected.#[test]fn cmd_with_the_hand_tool_is_not_a_zoom_during_free_transform() {