Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix InputState::any_touches and add InputState::has_touch_screen #4247

Merged
merged 2 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions crates/egui/src/input_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
5 changes: 5 additions & 0 deletions crates/egui/src/input_state/touch_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion crates/egui/src/widgets/label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion crates/egui/src/widgets/text_edit/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading