Boxed zoom takes wrong mouse location as a starting point for the rectangle
Nobody has claimed this yet.
Assessment
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Newbie friendliness
- 90/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Quiet
- Tech stack
- rust
- Domain
- data-visualization
Research direction
Read /src/plot.rs around lines 1132 and 1162, comparing the existing axis-drag coordinate handling with boxed zoom. Update the boxed-zoom starting position to use the pointer's press origin, then verify that right-click dragging begins the rectangle at the original mouse-down location.
Written by the indexing model from the issue text.
Description
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)
- Dominant language
- Rust
- Stars
- 467
- Forks
- 107
- Avg merge
- 15m
- Merged PRs (30d)
- 3
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from emilk/egui_plot
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
-
bug
Difficulty 3/5 1-2 days Newbie friendliness 65/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 45/100
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Eynzof/Hermes-CN-Desktop#610 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
gitbutlerapp/gitbutler#15998 · 1 comment ·
-
bug triage:deciding
Difficulty 1/5 Under an hour Newbie friendliness 88/100
open-telemetry/otel-arrow#4132 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100