Skip to content
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

Add Pointer::is_decidedly_dragging and could_any_button_be_click #2979

Merged
merged 3 commits into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/eframe/src/native/epi_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
21 changes: 19 additions & 2 deletions crates/egui/src/input_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions crates/egui/src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down