Skip to content

Conversation

@emilk
Copy link
Owner

@emilk emilk commented Nov 12, 2025

Useful in many cases. In a follow-up PR I will use it to prevent drift when dragging/resizing windows

@emilk emilk added feature New feature or request egui labels Nov 12, 2025
@github-actions
Copy link

github-actions bot commented Nov 12, 2025

Preview available at https://egui-pr-preview.github.io/pr/7708-emilkdrag-delta
Note that it might take a couple seconds for the update to show up after the preview_build workflow has completed.

View snapshot changes at kitdiff

@emilk emilk requested a review from Copilot November 12, 2025 21:24
Copy link
Contributor

Copilot AI left a 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
Copy link

Copilot AI Nov 12, 2025

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.

Suggested change
None
Some(Vec2::ZERO)

Copilot uses AI. Check for mistakes.
self.press_origin
}

/// How far has the pointer moved since the start of the drag (if any)?
Copy link

Copilot AI Nov 12, 2025

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.'

Suggested change
/// 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.

Copilot uses AI. Check for mistakes.
@emilk emilk merged commit 115adac into main Nov 12, 2025
49 of 50 checks passed
@emilk emilk deleted the emilk/drag-delta branch November 12, 2025 21:26
emilk added a commit that referenced this pull request Nov 12, 2025
* 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.
emilk added a commit that referenced this pull request Nov 13, 2025
…#7708)

Useful in many cases. In a follow-up PR I will use it to prevent drift
when dragging/resizing windows
emilk added a commit that referenced this pull request Nov 13, 2025
* 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.
This was referenced Nov 13, 2025
emilk added a commit to rerun-io/rerun that referenced this pull request Nov 26, 2025
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

egui feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants