Skip to main content

SubMenuItem

Struct SubMenuItem 

Source
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

Source

pub fn new(label: impl Into<WidgetText>) -> Self

Create a new submenu trigger with the given label.

Source

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.

Source

pub fn enabled(self, enabled: bool) -> Self

Disable the submenu trigger. Disabled triggers do not open the flyout and render with muted text.

Source

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.

Trait Implementations§

Source§

impl Debug for SubMenuItem

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(value: T, _simd: S) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.