Skip to content
Open
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
13 changes: 11 additions & 2 deletions crates/egui/src/containers/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
use crate::style::StyleModifier;
use crate::{
Button, Color32, Context, Frame, Id, InnerResponse, IntoAtoms, Layout, Popup,
PopupCloseBehavior, Response, Style, Ui, UiBuilder, UiKind, UiStack, UiStackInfo, Widget as _,
PopupCloseBehavior, Response, SetOpenCommand, Style, Ui, UiBuilder, UiKind, UiStack,
UiStackInfo, Widget as _,
};
use emath::{Align, RectAlign, Vec2, vec2};
use epaint::Stroke;
Expand Down Expand Up @@ -325,7 +326,15 @@ impl<'a> MenuButton<'a> {
let response = self.button.ui(ui);
let mut config = self.config.unwrap_or_else(|| MenuConfig::find(ui));
config.bar = false;
let inner = Popup::menu(&response)

let mut menu = Popup::menu(&response);
if Popup::is_any_open(ui.ctx()) && response.hovered() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally this should check that the other open menu is of the same group. Maybe @lucasmerlin can help with that?

Currently we get this weird behavior:

Image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch – I'd be happy to add this if I can get some pointers, but I'm not sure about the concept of menu groups (the word "group" doesn't appear at all in containers/menu.rs)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. You'd basically need to check if you're in the same MenuBar. Slightly ugly, but we could look up if we are within a MenuBar via UiStack by adding a UiKind::MenuBar and then store the MenuBar id in OpenPopup within memory.
Then, in the MenuButton get the bar id of the currently open popup, if it matches our bar id, open the popup on hover.

Not sure if there is a simpler way but this is the best thing I can come up with right now.

// If another menu is already open, then open this menu on hover
// (instead of requiring a click). This is a typical UI for
// top-of-window menu bars.
menu = menu.open_memory(Some(SetOpenCommand::Bool(true)));
}
let inner = menu
.close_behavior(config.close_behavior)
.style(config.style.clone())
.info(
Expand Down
Loading