From aa2f87e0ff004ec0bec439ea16ca0c9235eff84f Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sun, 31 Mar 2024 20:20:46 +0200 Subject: [PATCH] Allow zoom/pan a plot as long as it contains the mouse cursor (#4292) This is a fix meant mostly for Rerun, where we sometiems paint a vertical time-line over the plot (which is interactive). Before this PR you couldn't zoom or pan the plot while hovering that line, which was really annoying. --- crates/egui_plot/src/lib.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/crates/egui_plot/src/lib.rs b/crates/egui_plot/src/lib.rs index 6056f46b..bae90383 100644 --- a/crates/egui_plot/src/lib.rs +++ b/crates/egui_plot/src/lib.rs @@ -1076,8 +1076,13 @@ impl Plot { } } - let hover_pos = response.hover_pos(); - if let Some(hover_pos) = hover_pos { + // Note: we catch zoom/pan if the response contains the pointer, even if it isn't hovered. + // For instance: The user is painting another interactive widget on top of the plot + // but they still want to be able to pan/zoom the plot. + if let (true, Some(hover_pos)) = ( + response.contains_pointer, + ui.input(|i| i.pointer.hover_pos()), + ) { if allow_zoom.any() { let mut zoom_factor = if data_aspect.is_some() { Vec2::splat(ui.input(|i| i.zoom_delta()))