mirror of
https://github.com/emilk/egui.git
synced 2026-09-02 06:40:06 -04:00
Add Sense::LONG_CLICK
This commit is contained in:
@@ -682,6 +682,7 @@ fn install_touchstart(runner_ref: &WebRunner, target: &EventTarget) -> Result<()
|
|||||||
|event: web_sys::TouchEvent, runner| {
|
|event: web_sys::TouchEvent, runner| {
|
||||||
let mut should_stop_propagation = true;
|
let mut should_stop_propagation = true;
|
||||||
let mut should_prevent_default = true;
|
let mut should_prevent_default = true;
|
||||||
|
push_touches(runner, egui::TouchPhase::Start, &event);
|
||||||
if let Some((pos, _)) = primary_touch_pos(runner, &event) {
|
if let Some((pos, _)) = primary_touch_pos(runner, &event) {
|
||||||
let egui_event = egui::Event::PointerButton {
|
let egui_event = egui::Event::PointerButton {
|
||||||
pos,
|
pos,
|
||||||
@@ -691,10 +692,9 @@ fn install_touchstart(runner_ref: &WebRunner, target: &EventTarget) -> Result<()
|
|||||||
};
|
};
|
||||||
should_stop_propagation = (runner.web_options.should_stop_propagation)(&egui_event);
|
should_stop_propagation = (runner.web_options.should_stop_propagation)(&egui_event);
|
||||||
should_prevent_default = (runner.web_options.should_prevent_default)(&egui_event);
|
should_prevent_default = (runner.web_options.should_prevent_default)(&egui_event);
|
||||||
runner.input.raw.events.push(egui_event);
|
// runner.input.raw.events.push(egui_event);
|
||||||
}
|
}
|
||||||
|
|
||||||
push_touches(runner, egui::TouchPhase::Start, &event);
|
|
||||||
runner.needs_repaint.repaint_asap();
|
runner.needs_repaint.repaint_asap();
|
||||||
|
|
||||||
// Use web options to tell if the web event should be propagated to parent elements based on the egui event.
|
// Use web options to tell if the web event should be propagated to parent elements based on the egui event.
|
||||||
@@ -721,7 +721,7 @@ fn install_touchmove(runner_ref: &WebRunner, target: &EventTarget) -> Result<(),
|
|||||||
(runner.web_options.should_stop_propagation)(&egui_event);
|
(runner.web_options.should_stop_propagation)(&egui_event);
|
||||||
let should_prevent_default =
|
let should_prevent_default =
|
||||||
(runner.web_options.should_prevent_default)(&egui_event);
|
(runner.web_options.should_prevent_default)(&egui_event);
|
||||||
runner.input.raw.events.push(egui_event);
|
// runner.input.raw.events.push(egui_event);
|
||||||
|
|
||||||
push_touches(runner, egui::TouchPhase::Move, &event);
|
push_touches(runner, egui::TouchPhase::Move, &event);
|
||||||
runner.needs_repaint.repaint();
|
runner.needs_repaint.repaint();
|
||||||
@@ -746,6 +746,7 @@ fn install_touchend(runner_ref: &WebRunner, target: &EventTarget) -> Result<(),
|
|||||||
runner,
|
runner,
|
||||||
egui::pos2(touch.client_x() as f32, touch.client_y() as f32),
|
egui::pos2(touch.client_x() as f32, touch.client_y() as f32),
|
||||||
) {
|
) {
|
||||||
|
push_touches(runner, egui::TouchPhase::End, &event);
|
||||||
// First release mouse to click:
|
// First release mouse to click:
|
||||||
let mut should_stop_propagation = true;
|
let mut should_stop_propagation = true;
|
||||||
let mut should_prevent_default = true;
|
let mut should_prevent_default = true;
|
||||||
@@ -758,15 +759,14 @@ fn install_touchend(runner_ref: &WebRunner, target: &EventTarget) -> Result<(),
|
|||||||
should_stop_propagation &=
|
should_stop_propagation &=
|
||||||
(runner.web_options.should_stop_propagation)(&egui_event);
|
(runner.web_options.should_stop_propagation)(&egui_event);
|
||||||
should_prevent_default &= (runner.web_options.should_prevent_default)(&egui_event);
|
should_prevent_default &= (runner.web_options.should_prevent_default)(&egui_event);
|
||||||
runner.input.raw.events.push(egui_event);
|
// runner.input.raw.events.push(egui_event);
|
||||||
// Then remove hover effect:
|
// Then remove hover effect:
|
||||||
should_stop_propagation &=
|
should_stop_propagation &=
|
||||||
(runner.web_options.should_stop_propagation)(&egui::Event::PointerGone);
|
(runner.web_options.should_stop_propagation)(&egui::Event::PointerGone);
|
||||||
should_prevent_default &=
|
should_prevent_default &=
|
||||||
(runner.web_options.should_prevent_default)(&egui::Event::PointerGone);
|
(runner.web_options.should_prevent_default)(&egui::Event::PointerGone);
|
||||||
runner.input.raw.events.push(egui::Event::PointerGone);
|
// runner.input.raw.events.push(egui::Event::PointerGone);
|
||||||
|
|
||||||
push_touches(runner, egui::TouchPhase::End, &event);
|
|
||||||
|
|
||||||
runner.needs_repaint.repaint_asap();
|
runner.needs_repaint.repaint_asap();
|
||||||
|
|
||||||
|
|||||||
@@ -145,6 +145,7 @@ pub(crate) fn interact(
|
|||||||
if let Some(widget) = interaction
|
if let Some(widget) = interaction
|
||||||
.potential_click_id
|
.potential_click_id
|
||||||
.and_then(|id| widgets.get(id))
|
.and_then(|id| widgets.get(id))
|
||||||
|
&& widget.sense.senses_long_click()
|
||||||
{
|
{
|
||||||
dragged = None;
|
dragged = None;
|
||||||
clicked = Some(widget.id);
|
clicked = Some(widget.id);
|
||||||
|
|||||||
@@ -19,6 +19,14 @@ bitflags::bitflags! {
|
|||||||
/// Anything interactive + labels that can be focused
|
/// Anything interactive + labels that can be focused
|
||||||
/// for the benefit of screen readers.
|
/// for the benefit of screen readers.
|
||||||
const FOCUSABLE = 1<<2;
|
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,10 +61,10 @@ impl Sense {
|
|||||||
Self::FOCUSABLE
|
Self::FOCUSABLE
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sense clicks and hover, but not drags.
|
/// Sense clicks, long clicks and hover, but not drags.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn click() -> Self {
|
pub fn click() -> Self {
|
||||||
Self::CLICK | Self::FOCUSABLE
|
Self::CLICK | Self::FOCUSABLE | Self::LONG_CLICK
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sense drags and hover, but not clicks.
|
/// Sense drags and hover, but not clicks.
|
||||||
@@ -75,7 +83,7 @@ impl Sense {
|
|||||||
/// See [`crate::PointerState::is_decidedly_dragging`] for details.
|
/// See [`crate::PointerState::is_decidedly_dragging`] for details.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn click_and_drag() -> Self {
|
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.
|
/// Returns true if we sense either clicks or drags.
|
||||||
@@ -89,6 +97,11 @@ impl Sense {
|
|||||||
self.contains(Self::CLICK)
|
self.contains(Self::CLICK)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn senses_long_click(&self) -> bool {
|
||||||
|
self.contains(Self::LONG_CLICK)
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn senses_drag(&self) -> bool {
|
pub fn senses_drag(&self) -> bool {
|
||||||
self.contains(Self::DRAG)
|
self.contains(Self::DRAG)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ use eframe::glow;
|
|||||||
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
use core::any::Any;
|
use core::any::Any;
|
||||||
|
use log::info;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
||||||
|
|||||||
Reference in New Issue
Block a user