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.
This commit is contained in:
Emil Ernerfeldt 2024-03-31 20:20:46 +02:00 committed by GitHub
parent bb06befef1
commit aa2f87e0ff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 2 deletions

View File

@ -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()))