-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add Response::total_drag_delta and PointerState::total_drag_delta
#7708
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Preview available at https://egui-pr-preview.github.io/pr/7708-emilkdrag-delta View snapshot changes at kitdiff |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds new methods to track the total drag delta (accumulated distance) since the start of a drag operation, complementing the existing per-frame drag delta functionality.
- Added
PointerState::total_drag_delta()to calculate total distance dragged from press origin - Added
Response::total_drag_delta()that applies layer transformations to the total drag delta - Updated documentation to clarify existing methods measure per-frame deltas
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| crates/egui/src/response.rs | Added Response::total_drag_delta() method and updated documentation to distinguish between per-frame and total drag deltas |
| crates/egui/src/input_state/mod.rs | Added PointerState::total_drag_delta() to compute total drag distance from press origin |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } | ||
| Some(delta) | ||
| } else { | ||
| None |
Copilot
AI
Nov 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function returns None when not dragged, but also returns None when dragged if total_drag_delta() returns None (e.g., when latest_pos or press_origin is None). This creates ambiguity about whether the item is not being dragged or if position data is unavailable. Consider returning Some(Vec2::ZERO) when not dragged to distinguish between these cases, or document this behavior clearly.
| None | |
| Some(Vec2::ZERO) |
| self.press_origin | ||
| } | ||
|
|
||
| /// How far has the pointer moved since the start of the drag (if any)? |
Copilot
AI
Nov 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation should clarify when this method returns None. Based on the implementation, it returns None when either latest_pos or press_origin is None, not just when there is no drag. Consider updating the comment to: 'How far has the pointer moved since the start of the drag? Returns None if position data is unavailable.'
| /// How far has the pointer moved since the start of the drag (if any)? | |
| /// How far has the pointer moved since the start of the drag? | |
| /// Returns `None` if position data is unavailable. |
* Follows #7708 * Related to #202 This fixes a particular issue where resizing a window would move it, and resizing it back would not restore it. You can still move a window by resizing it (I didn't focus on that bug here), but at least now the window will return to its original position when you move back the mouse.
…#7708) Useful in many cases. In a follow-up PR I will use it to prevent drift when dragging/resizing windows
* Follows #7708 * Related to #202 This fixes a particular issue where resizing a window would move it, and resizing it back would not restore it. You can still move a window by resizing it (I didn't focus on that bug here), but at least now the window will return to its original position when you move back the mouse.
Changes in snapshot images should be pixel-alignment improvements thanks to * emilk/egui#7710 --- ## egui changelog ### ⭐ Added * Add `Plugin::on_widget_under_pointer` to support widget inspector [#7652](emilk/egui#7652) by [@juancampa](https://github.com/juancampa) * Add `Response::total_drag_delta` and `PointerState::total_drag_delta` [#7708](emilk/egui#7708) by [@emilk](https://github.com/emilk) ### 🔧 Changed * Improve accessibility and testability of `ComboBox` [#7658](emilk/egui#7658) by [@lucasmerlin](https://github.com/lucasmerlin) ### 🐛 Fixed * Fix `profiling::scope` compile error when profiling using `tracing` backend [#7646](emilk/egui#7646) by [@PPakalns](https://github.com/PPakalns) * Fix edge cases in "smart aiming" in sliders [#7680](emilk/egui#7680) by [@emilk](https://github.com/emilk) * Hide scroll bars when dragging other things [#7689](emilk/egui#7689) by [@emilk](https://github.com/emilk) * Prevent widgets sometimes appearing to move relative to each other [#7710](emilk/egui#7710) by [@emilk](https://github.com/emilk) * Fix `ui.response().interact(Sense::click())` being flakey [#7713](emilk/egui#7713) by [@lucasmerlin](https://github.com/lucasmerlin) ## eframe changelog * Fix jittering during window resize on MacOS for WGPU/Metal [#7641](emilk/egui#7641) by [@aspcartman](https://github.com/aspcartman) * Make sure `native_pixels_per_point` is set during app creation [#7683](emilk/egui#7683) by [@emilk](https://github.com/emilk) --------- Co-authored-by: Lucas Meurer <[email protected]> Co-authored-by: lucasmerlin <[email protected]>
Useful in many cases. In a follow-up PR I will use it to prevent drift when dragging/resizing windows