Browse Source
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
pull/2981/head
Emil Ernerfeldt
2 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with
25 additions and
2 deletions
crates/eframe/src/native/epi_integration.rs
crates/egui/src/input_state.rs
crates/egui/src/memory.rs
@ -557,6 +557,7 @@ impl EpiIntegration {
}
}
#[ allow(clippy::unused_self) ]
pub fn save ( & mut self , _app : & mut dyn epi ::App , _window : & winit ::window ::Window ) {
#[ cfg(feature = " persistence " ) ]
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?
#[ 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 ( ) {
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 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?
#[ inline(always) ]
pub fn primary_down ( & self ) -> bool {
@ -477,6 +477,11 @@ impl Memory {
self . interaction . drag_id = Some ( id ) ;
}
#[ inline(always) ]
pub fn stop_dragging ( & mut self ) {
self . interaction . drag_id = None ;
}
/// Forget window positions, sizes etc.
/// Can be used to auto-layout windows.
pub fn reset_areas ( & mut self ) {