Fix `InputState::any_touches` and add `InputState::has_touch_screen` (#4247)

Add `InputState::has_touch_screen` to query if there ever has been any
touches (which is what `any_touches` used to return).
This commit is contained in:
Emil Ernerfeldt 2024-03-27 16:14:17 +01:00 committed by GitHub
parent a15e6c2122
commit bc5ce77819
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 12 additions and 2 deletions

View File

@ -485,6 +485,11 @@ impl InputState {
/// True if there currently are any fingers touching egui.
pub fn any_touches(&self) -> bool {
self.touch_states.values().any(|t| t.any_touches())
}
/// True if we have ever received a touch event.
pub fn has_touch_screen(&self) -> bool {
!self.touch_states.is_empty()
}

View File

@ -177,6 +177,11 @@ impl TouchState {
}
}
/// Are there currently any fingers touching the surface?
pub fn any_touches(&self) -> bool {
!self.active_touches.is_empty()
}
pub fn info(&self) -> Option<MultiTouchInfo> {
self.gesture_state.as_ref().map(|state| {
// state.previous can be `None` when the number of simultaneous touches has just

View File

@ -128,7 +128,7 @@ impl Label {
// dragging select text, or scroll the enclosing [`ScrollArea`] (if any)?
// Since currently copying selected text in not supported on `eframe` web,
// we prioritize touch-scrolling:
let allow_drag_to_select = ui.input(|i| !i.any_touches());
let allow_drag_to_select = ui.input(|i| !i.has_touch_screen());
let mut select_sense = if allow_drag_to_select {
Sense::click_and_drag()

View File

@ -527,7 +527,7 @@ impl<'t> TextEdit<'t> {
// Since currently copying selected text in not supported on `eframe` web,
// we prioritize touch-scrolling:
let allow_drag_to_select =
ui.input(|i| !i.any_touches()) || ui.memory(|mem| mem.has_focus(id));
ui.input(|i| !i.has_touch_screen()) || ui.memory(|mem| mem.has_focus(id));
let sense = if interactive {
if allow_drag_to_select {