When zooming into a plot by right click + drag, the zoom does not take the mouse location where the user pressed down, but instead the mouse location where egui has decided that this is a drag action. But egui waits for a few pixels of mouse movement before declaring it as dragged. As a consequence it is very hard to place the initial corner of the zoom correctly. The issue is worse in slow applications, where it is easy to move the mouse a large distance between two consecutive frames.
The source of the bug is /src/plot.rs:1162:
// Save last click to allow boxed zooming
if response.drag_started() && response.dragged_by(self.boxed_zoom_pointer_button) {
// it would be best for egui that input has a memory of the last click pos
// because it's a common pattern
mem.last_click_pos_for_zoom = response.hover_pos();
}
response.hover_pos() is not the position that we want here. The solution is simple:
// Save last click to allow boxed zooming
if response.drag_started() && response.dragged_by(self.boxed_zoom_pointer_button) {
// it would be best for egui that input has a memory of the last click pos
// because it's a common pattern
mem.last_click_pos_for_zoom = ui.input(|i| i.pointer.press_origin());
}
I was initially worried about potential deadlocks, because ui.input() has a big warning about it, but the same code to get the proper mouse coordinates is already present in /src/plot.rs:1132 for zooming by dragging an axis, so it does not seem to be an issue.
(sorry for not forking, cloning, commiting, pushing and making a pull request. That's a lot of work for a simple one line change. I hope this is fine too)
When zooming into a plot by right click + drag, the zoom does not take the mouse location where the user pressed down, but instead the mouse location where egui has decided that this is a drag action. But egui waits for a few pixels of mouse movement before declaring it as dragged. As a consequence it is very hard to place the initial corner of the zoom correctly. The issue is worse in slow applications, where it is easy to move the mouse a large distance between two consecutive frames.
The source of the bug is
/src/plot.rs:1162:response.hover_pos()is not the position that we want here. The solution is simple:I was initially worried about potential deadlocks, because
ui.input()has a big warning about it, but the same code to get the proper mouse coordinates is already present in/src/plot.rs:1132for zooming by dragging an axis, so it does not seem to be an issue.(sorry for not forking, cloning, commiting, pushing and making a pull request. That's a lot of work for a simple one line change. I hope this is fine too)