-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
no way to open context menus on touchscreens #3444
Labels
bug
Something is broken
Comments
for anyone dealing with the same issue, i wrote this workaround: use egui::{
Ui,
Response
};
// cannot be longer than .7~ seconds because after that Response.hovered() returns false
// probably it could be longer by using pointer_pos check instead of hovered() but .4s is a good speed so w/e
const LONG_PRESS_TIME: f64 = 0.4;
pub trait TouchEnabledContextMenu {
fn context_menu_touch_enabled(self, ui: &mut Ui, add_contents: impl FnOnce(&mut Ui)) -> Self;
}
impl TouchEnabledContextMenu for Response {
fn context_menu_touch_enabled(self, ui: &mut Ui, add_contents: impl FnOnce(&mut Ui)) -> Self {
let popup_id = ui.make_persistent_id(self.id.with("context_touch_menu"));
let is_open = ui.memory(|mem| mem.is_popup_open(popup_id));
let mut should_open = false;
if self.secondary_clicked() {
should_open = true
} else if self.hovered() && !is_open {
ui.input(|i| {
if let Some(pst) = i.pointer.press_start_time() {
if (i.time - pst) > LONG_PRESS_TIME {
should_open = true
}
}
});
};
if should_open {
ui.memory_mut(|mem| mem.toggle_popup(popup_id));
}
egui::popup::popup_above_or_below_widget(
ui,
popup_id,
&self,
egui::AboveOrBelow::Above,
|ui| {
ui.set_min_width(120.0); // popup is extremely thin without this, regardless of contents
add_contents(ui);
}
);
self
}
} |
This might be a duplicate of #865, but best kept open for the useful workaround. |
hacknus
pushed a commit
to hacknus/egui
that referenced
this issue
Oct 30, 2024
* Closes emilk#3444 * Closes emilk#865 On a touch screen, if you press down on a widget and hold for 0.6 seconds (`MAX_CLICK_DURATION`), it will now trigger a secondary click, i.e. `Response::secondary_clicked` will be `true`. This means you can now open context menus on touch screens.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
When using context_menu it seems to be only accessible by secondary click and can therefore not be opened on a touch screen device.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
A reasonable default I feel would be to have it open on a long press.
I reckon it would be somewhat straightforard to implement with
egui::PointerState::press_start_time
- at least that's what I will do for a workaround in my project, but perhaps it should be part of the API as well.Smartphone (please complete the following information):
The text was updated successfully, but these errors were encountered: