Update ScrollArea drag velocity when drag stopped#5175
Merged
emilk merged 2 commits intoemilk:masterfrom Oct 2, 2024
Merged
Conversation
Fixes emilk#5174. The drag velocity was not being updated unless the cursor counted as "dragging", which only happens when it's in motion. This effectively guarantees that the drag velocity will never be zero, even if the cursor is not moving, and results in spurious scroll velocity being applied when the cursor is released. Instead, we update the velocity only when the drag is stopped, which is when the kinetic scrolling actually needs to begin.
|
Preview available at https://egui-pr-preview.github.io/pr/5175-fix-drag-velocity |
emilk
approved these changes
Sep 30, 2024
Comment on lines
+643
to
+651
| for d in 0..2 { | ||
| if scroll_enabled[d] { | ||
| ui.input(|input| { | ||
| state.vel[d] = input.pointer.velocity()[d]; | ||
| }); | ||
| } else { | ||
| state.vel[d] = 0.0; | ||
| } | ||
| } |
Owner
There was a problem hiding this comment.
It would be nice if we could write this as
Suggested change
| for d in 0..2 { | |
| if scroll_enabled[d] { | |
| ui.input(|input| { | |
| state.vel[d] = input.pointer.velocity()[d]; | |
| }); | |
| } else { | |
| state.vel[d] = 0.0; | |
| } | |
| } | |
| state.vel = scroll_enabled.to_vec2() * input.pointer.velocity(); |
(requires implementing adding a fn to_vec2(&self) to Vec2b)
hacknus
pushed a commit
to hacknus/egui
that referenced
this pull request
Oct 30, 2024
Fixes emilk#5174. The drag velocity was not being updated unless the cursor counted as "dragging", which only happens when it's in motion. This effectively guarantees that the drag velocity will never be zero, even if the cursor is not moving, and results in spurious scroll velocity being applied when the cursor is released. Instead, we update the velocity only when the drag is stopped, which is when the kinetic scrolling actually needs to begin. Note that we immediately *apply* the scroll velocity on the same frame that we first set it, to avoid a 1-frame gap where the scroll area doesn't move. I believe that *not* setting `scroll_stuck_to_end` and `offset_target` when the drag is released is the correct thing to do, as they should apply immediately once the user stops dragging. Should we maybe clear the drag velocity instead if `scroll_stuck_to_end` is true or `offset_target` exists? * Closes emilk#5174 * [x] I have followed the instructions in the PR template
jb55
added a commit
to damus-io/egui
that referenced
this pull request
Mar 10, 2025
This reverts commit ac2466d.
jb55
added a commit
to damus-io/egui
that referenced
this pull request
Mar 10, 2025
This reverts commit ac2466d.
jb55
added a commit
to damus-io/egui
that referenced
this pull request
Mar 10, 2025
This reverts commit ac2466d.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5174.
The drag velocity was not being updated unless the cursor counted as "dragging", which only happens when it's in motion. This effectively guarantees that the drag velocity will never be zero, even if the cursor is not moving, and results in spurious scroll velocity being applied when the cursor is released.
Instead, we update the velocity only when the drag is stopped, which is when the kinetic scrolling actually needs to begin. Note that we immediately apply the scroll velocity on the same frame that we first set it, to avoid a 1-frame gap where the scroll area doesn't move.
I believe that not setting
scroll_stuck_to_endandoffset_targetwhen the drag is released is the correct thing to do, as they should apply immediately once the user stops dragging. Should we maybe clear the drag velocity instead ifscroll_stuck_to_endis true oroffset_targetexists?