pub struct SubMenuItem { /* private fields */ }Expand description
A menu row that opens a flyout submenu when hovered.
Visually a MenuItem with a right-pointing chevron; pair the
trigger with a body closure that fills the child menu. Use inside any
elegance menu — a MenuBar dropdown body or a
Menu popup. The submenu opens to the right and stays open while
the pointer remains over either the trigger or the flyout panel.
MenuBar::new("app").show(ui, |bar| {
bar.menu("File", |ui| {
ui.add(MenuItem::new("New"));
SubMenuItem::new("Open Recent").show(ui, |ui| {
ui.add(MenuItem::new("theme.rs"));
ui.add(MenuItem::new("README.md"));
});
ui.add(MenuItem::new("Save"));
});
});Hover-to-flyout, click-to-pin, and proper “stay open while child is
open” behavior come from egui’s built-in submenu machinery; this
type just wires our MenuItem visual into that pipeline.
Implementations§
Source§impl SubMenuItem
impl SubMenuItem
Sourcepub fn new(label: impl Into<WidgetText>) -> Self
pub fn new(label: impl Into<WidgetText>) -> Self
Create a new submenu trigger with the given label.
Sourcepub fn icon(self, icon: impl Into<WidgetText>) -> Self
pub fn icon(self, icon: impl Into<WidgetText>) -> Self
Show a leading icon (any text, typically a unicode glyph) in the gutter to the left of the label.
Sourcepub fn enabled(self, enabled: bool) -> Self
pub fn enabled(self, enabled: bool) -> Self
Disable the submenu trigger. Disabled triggers do not open the flyout and render with muted text.
Sourcepub fn show<R>(self, ui: &mut Ui, body: impl FnOnce(&mut Ui) -> R) -> Option<R>
pub fn show<R>(self, ui: &mut Ui, body: impl FnOnce(&mut Ui) -> R) -> Option<R>
Render the trigger row and attach the flyout submenu. The body
closure populates the child menu and is invoked while the flyout
is open. Returns Some(R) with the body’s return value while the
submenu is open, None while closed.