diff --git a/crates/egui/src/interaction.rs b/crates/egui/src/interaction.rs index bfac38da7..11c4079a3 100644 --- a/crates/egui/src/interaction.rs +++ b/crates/egui/src/interaction.rs @@ -145,6 +145,7 @@ pub(crate) fn interact( if let Some(widget) = interaction .potential_click_id .and_then(|id| widgets.get(id)) + && widget.sense.senses_long_click() { dragged = None; clicked = Some(widget.id); diff --git a/crates/egui/src/sense.rs b/crates/egui/src/sense.rs index c3b3af7f2..48da3c850 100644 --- a/crates/egui/src/sense.rs +++ b/crates/egui/src/sense.rs @@ -19,6 +19,14 @@ bitflags::bitflags! { /// Anything interactive + labels that can be focused /// for the benefit of screen readers. const FOCUSABLE = 1<<2; + + /// Sense long clicks + /// + /// By default, anything that senses clicks also senses long clicks. + /// You can remove this flag if you want to sense clicks but not long clicks. + /// + /// Sensing for long clicks might cause problems when you need to sense precise drags + const LONG_CLICK = 1<<3; } } @@ -53,12 +61,12 @@ impl Sense { Self::FOCUSABLE } - /// Sense clicks and hover, but not drags, and make the widget focusable. + /// Sense clicks, long clicks and hover, but not drags, and make the widget focusable. /// /// Use [`Sense::CLICK`] if you don't want the widget to be focusable. #[inline] pub fn click() -> Self { - Self::CLICK | Self::FOCUSABLE + Self::CLICK | Self::FOCUSABLE | Self::LONG_CLICK } /// Sense drags and hover, but not clicks. Make the widget focusable. @@ -79,7 +87,7 @@ impl Sense { /// See [`crate::PointerState::is_decidedly_dragging`] for details. #[inline] pub fn click_and_drag() -> Self { - Self::CLICK | Self::FOCUSABLE | Self::DRAG + Self::CLICK | Self::LONG_CLICK | Self::FOCUSABLE | Self::DRAG } /// Returns true if we sense either clicks or drags. @@ -93,6 +101,11 @@ impl Sense { self.contains(Self::CLICK) } + #[inline] + pub fn senses_long_click(&self) -> bool { + self.contains(Self::LONG_CLICK) + } + #[inline] pub fn senses_drag(&self) -> bool { self.contains(Self::DRAG)