mirror of
https://github.com/emilk/egui.git
synced 2026-06-26 22:53:14 -04:00
Merge branch 'lucas/add-sense-long-click' into lucas/malmal/main
# Conflicts: # crates/egui/src/sense.rs
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user