Skip to content

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

Merge PR #6826: Don't pan the canvas when a dialog's title bar is dragged (#6810)

aionggb8605f8447ad
diff --cc crates/ui-egui/src/dialogs.rs
index 9584f3f89,c4020de08..ccba0e36c
--- a/crates/ui-egui/src/dialogs.rs
+++ b/crates/ui-egui/src/dialogs.rs
@@@ -40,27 -61,9 +61,27 @@@ pub fn pan_delta(ctx: &egui::Context, c
(p.press_origin(), p.middle_down() || (p.primary_down() && (hand || i.key_down(egui::Key::Space))), p.delta())
});
let origin = origin?;
- (panning && canvas.contains(origin) && !rects.iter().any(|r| r.contains(origin))).then_some(delta)
+ (panning && !grabbed && canvas.contains(origin) && !rects.iter().any(|r| r.contains(origin))).then_some(delta)
}
+/// The primary button's drag and click on the free canvas under an open dialog, as the canvas
+/// response would report them if it weren't inert: for the held Zoom (⌘Space / ⌥Space, #6460).
+/// A drag counts from egui's drag threshold, like `drag_started`.
+pub fn free_buttons(ctx: &egui::Context, canvas: egui::Rect) -> crate::paint_mouse::Buttons {
+ let id = egui::Id::new("pc-dialog-free-drag");
+ let was = ctx.data(|d| d.get_temp::<bool>(id)).unwrap_or(false);
+ let rects = rects(ctx);
+ let open_popup = egui::Popup::is_any_open(ctx);
+ let free = |p: egui::Pos2| !open_popup && canvas.contains(p) && !rects.iter().any(|r| r.contains(p));
+ let (down, dragging, clicked) = ctx.input(|i| {
+ let p = &i.pointer;
+ let dragging = p.primary_down() && p.is_decidedly_dragging() && (was || p.press_origin().is_some_and(free));
+ (p.primary_down(), dragging, p.primary_clicked() && p.interact_pos().is_some_and(free))
+ });
+ ctx.data_mut(|d| d.insert_temp(id, dragging));
+ crate::paint_mouse::Buttons { started: dragging && !was, dragged: dragging, stopped: was && !down, clicked }
+}
+
/// A click or drag with the primary button started on the free canvas under an open dialog, Space
/// not held: where the pointer is this frame. The press itself counts even when it is released in
/// the same frame (a quick click, `ui.click`); the drag only while it stays on the free canvas.