1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-31 22:00:03 -04:00

Improve drag-code

This commit is contained in:
Emil Ernerfeldt
2023-05-04 21:24:58 +02:00
parent 951bc988b3
commit aa30414caf
3 changed files with 21 additions and 10 deletions

View File

@@ -894,7 +894,8 @@ impl PointerState {
}
/// If the pointer button is down, will it register as a click when released?
#[inline(always)]
///
/// See also [`Self::is_decidedly_dragging`].
pub fn could_any_button_be_click(&self) -> bool {
if !self.any_down() {
return false;
@@ -913,6 +914,22 @@ impl PointerState {
true
}
/// Just because the mouse is down doesn't mean we are dragging.
/// We could be at the start of a click.
/// But if the mouse is down long enough, or has moved far enough,
/// then we consider it a drag.
///
/// This function can return true on the same frame the drag is relased,
/// but NOT on the first frame it was started.
///
/// See also [`Self::could_any_button_be_click`].
pub fn is_decidedly_dragging(&self) -> bool {
(self.any_down() || self.any_released())
&& !self.any_pressed()
&& !self.could_any_button_be_click()
&& !self.any_click()
}
/// Is the primary button currently down?
#[inline(always)]
pub fn primary_down(&self) -> bool {