From 454af7aa6c1e42abb6b162ea02843561695dc91c Mon Sep 17 00:00:00 2001 From: ozwaldorf Date: Sun, 24 Aug 2025 08:43:31 -0400 Subject: [PATCH] fix: `SubMenu` should not display when ui is disabled (#7428) Adds a check for `ui.is_enabled()` when displaying the SubMenu items. There were a few places the condition could be placed, but I figured there was simplest. The inner button will already not be able to be clicked due to ui being disabled. cc @lucasmerlin * [x] I have followed the instructions in the PR template --------- Co-authored-by: Emil Ernerfeldt --- crates/egui/src/containers/menu.rs | 4 +++- crates/egui_demo_lib/src/demo/popups.rs | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/egui/src/containers/menu.rs b/crates/egui/src/containers/menu.rs index 1e2cbfa2..c83b5297 100644 --- a/crates/egui/src/containers/menu.rs +++ b/crates/egui/src/containers/menu.rs @@ -446,7 +446,9 @@ impl SubMenu { let is_hovered = hover_pos.is_some_and(|pos| button_rect.contains(pos)); // The clicked handler is there for accessibility (keyboard navigation) - if (!is_any_open && is_hovered) || button_response.clicked() { + let should_open = + ui.is_enabled() && (button_response.clicked() || (is_hovered && !is_any_open)); + if should_open { set_open = Some(true); is_open = true; // Ensure that all other sub menus are closed when we open the menu diff --git a/crates/egui_demo_lib/src/demo/popups.rs b/crates/egui_demo_lib/src/demo/popups.rs index 4574d99e..9998dd59 100644 --- a/crates/egui_demo_lib/src/demo/popups.rs +++ b/crates/egui_demo_lib/src/demo/popups.rs @@ -53,6 +53,9 @@ impl PopupsDemo { ui.close(); } }); + ui.add_enabled_ui(false, |ui| { + ui.menu_button("SubMenus can be disabled", |_| {}); + }); ui.menu_image_text_button( include_image!("../../data/icon.png"), "I have an icon!",