Skip to content

Hide hover UI when showing the context menu #4138

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

Merged
merged 1 commit into from
Mar 6, 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
7 changes: 7 additions & 0 deletions crates/egui/src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,13 @@ pub(crate) fn context_menu(
inner_response
}

/// Returns `true` if the context menu is opened for this widget.
pub(crate) fn context_menu_opened(response: &Response) -> bool {
let menu_id = Id::new(CONTEXT_MENU_ID_STR);
let bar_state = BarState::load(&response.ctx, menu_id);
bar_state.is_menu_open(response.id)
}

/// Stores the state for the context menu.
#[derive(Clone, Default)]
pub(crate) struct MenuRootManager {
Expand Down
11 changes: 11 additions & 0 deletions crates/egui/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,10 @@ impl Response {
return true;
}

if self.context_menu_opened() {
return false;
}

if self.enabled {
if !self.hovered || !self.ctx.input(|i| i.pointer.has_pointer()) {
return false;
Expand Down Expand Up @@ -849,6 +853,13 @@ impl Response {
menu::context_menu(self, add_contents)
}

/// Returns whether a context menu is currently open for this widget.
///
/// See [`Self::context_menu`].
pub fn context_menu_opened(&self) -> bool {
menu::context_menu_opened(self)
}

/// Draw a debug rectangle over the response displaying the response's id and whether it is
/// enabled and/or hovered.
///
Expand Down