diff --git a/crates/egui/src/input_state.rs b/crates/egui/src/input_state.rs index eccda3f5c..2c61a12d2 100644 --- a/crates/egui/src/input_state.rs +++ b/crates/egui/src/input_state.rs @@ -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 { diff --git a/crates/egui_extras/src/dock/branch/tabs.rs b/crates/egui_extras/src/dock/branch/tabs.rs index 5b8c1302f..5ad17cb42 100644 --- a/crates/egui_extras/src/dock/branch/tabs.rs +++ b/crates/egui_extras/src/dock/branch/tabs.rs @@ -3,8 +3,7 @@ use std::collections::HashMap; use egui::{vec2, Rect}; use crate::dock::{ - is_being_dragged, is_possible_drag, Behavior, DropContext, InsertionPoint, LayoutInsertion, - NodeId, Nodes, + is_being_dragged, Behavior, DropContext, InsertionPoint, LayoutInsertion, NodeId, Nodes, }; #[derive(Clone, Debug, Default, serde::Serialize, serde::Deserialize)] @@ -58,8 +57,7 @@ impl Tabs { let next_active = self.tab_bar_ui(behavior, ui, rect, nodes, drop_context, node_id); // When dragged, don't show it (it is "being held") - let is_active_being_dragged = - ui.memory(|mem| mem.is_being_dragged(self.active.id())) && is_possible_drag(ui.ctx()); + let is_active_being_dragged = is_being_dragged(ui.ctx(), self.active); if !is_active_being_dragged { nodes.node_ui(behavior, drop_context, ui, self.active); } diff --git a/crates/egui_extras/src/dock/mod.rs b/crates/egui_extras/src/dock/mod.rs index d62036913..98f635b15 100644 --- a/crates/egui_extras/src/dock/mod.rs +++ b/crates/egui_extras/src/dock/mod.rs @@ -165,11 +165,7 @@ enum SimplifyAction { } fn is_possible_drag(ctx: &egui::Context) -> bool { - ctx.input(|input| { - !input.pointer.any_pressed() - && !input.pointer.could_any_button_be_click() - && !input.pointer.any_click() - }) + ctx.input(|input| input.pointer.is_decidedly_dragging()) } fn is_being_dragged(ctx: &egui::Context, node_id: NodeId) -> bool {