Add `Pointer::is_decidedly_dragging` and `could_any_button_be_click` (#2979)
* Add Pointer::is_decidedly_dragging and could_any_button_be_click This allows users to distinguish between click and drags while they are not yet done. * Fix warning in eframe * fix typo
This commit is contained in:
parent
faf31365d2
commit
e9fa6c8ff6
|
|
@ -557,6 +557,7 @@ impl EpiIntegration {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::unused_self)]
|
||||||
pub fn save(&mut self, _app: &mut dyn epi::App, _window: &winit::window::Window) {
|
pub fn save(&mut self, _app: &mut dyn epi::App, _window: &winit::window::Window) {
|
||||||
#[cfg(feature = "persistence")]
|
#[cfg(feature = "persistence")]
|
||||||
if let Some(storage) = self.frame.storage_mut() {
|
if let Some(storage) = self.frame.storage_mut() {
|
||||||
|
|
|
||||||
|
|
@ -894,8 +894,9 @@ impl PointerState {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// If the pointer button is down, will it register as a click when released?
|
/// If the pointer button is down, will it register as a click when released?
|
||||||
#[inline(always)]
|
///
|
||||||
pub(crate) fn could_any_button_be_click(&self) -> bool {
|
/// See also [`Self::is_decidedly_dragging`].
|
||||||
|
pub fn could_any_button_be_click(&self) -> bool {
|
||||||
if !self.any_down() {
|
if !self.any_down() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -913,6 +914,22 @@ impl PointerState {
|
||||||
true
|
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 released,
|
||||||
|
/// 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?
|
/// Is the primary button currently down?
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn primary_down(&self) -> bool {
|
pub fn primary_down(&self) -> bool {
|
||||||
|
|
|
||||||
|
|
@ -477,6 +477,11 @@ impl Memory {
|
||||||
self.interaction.drag_id = Some(id);
|
self.interaction.drag_id = Some(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn stop_dragging(&mut self) {
|
||||||
|
self.interaction.drag_id = None;
|
||||||
|
}
|
||||||
|
|
||||||
/// Forget window positions, sizes etc.
|
/// Forget window positions, sizes etc.
|
||||||
/// Can be used to auto-layout windows.
|
/// Can be used to auto-layout windows.
|
||||||
pub fn reset_areas(&mut self) {
|
pub fn reset_areas(&mut self) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue