-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Update ScrollArea drag velocity when drag stopped #5175
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 |
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.
Makes sense!
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; | ||
} | ||
} |
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.
It would be nice if we could write this as
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
)
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
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_end
andoffset_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 ifscroll_stuck_to_end
is true oroffset_target
exists?