pub struct MenuItem { /* private fields */ }Expand description
An item in a Material menu. Callers retain command and selection state.
Implementations§
Source§impl MenuItem
impl MenuItem
Sourcepub fn new(id: impl Into<ElementId>, label: impl Into<SharedString>) -> Self
pub fn new(id: impl Into<ElementId>, label: impl Into<SharedString>) -> Self
Creates a standard action menu item with the given element ID and label.
Sourcepub fn group(id: impl Into<ElementId>, title: impl Into<SharedString>) -> Self
pub fn group(id: impl Into<ElementId>, title: impl Into<SharedString>) -> Self
Creates a non-interactive section heading row that is skipped by keyboard navigation.
Sourcepub fn divider(id: impl Into<ElementId>) -> Self
pub fn divider(id: impl Into<ElementId>) -> Self
Creates a non-interactive horizontal divider row inside a menu that is skipped by keyboard navigation.
Sourcepub fn section(
id: impl Into<ElementId>,
name: impl Into<SharedString>,
rows: impl IntoIterator<Item = MenuItem>,
) -> Self
pub fn section( id: impl Into<ElementId>, name: impl Into<SharedString>, rows: impl IntoIterator<Item = MenuItem>, ) -> Self
Creates a surfaced group with rows in the owning menu’s navigation order.
Sourcepub fn group_appearance(self, appearance: MenuSurfaceStyle) -> Self
pub fn group_appearance(self, appearance: MenuSurfaceStyle) -> Self
Sets the styled section’s surface appearance.
Sourcepub fn inactive_shape(self, shape: CornerShape) -> Self
pub fn inactive_shape(self, shape: CornerShape) -> Self
Sets the section shape used after the pointer leaves the section.
Sourcepub fn appearance(self, style: MenuItemStyle) -> Self
pub fn appearance(self, style: MenuItemStyle) -> Self
Configures the appearance of an action, checked or selected row.
Sourcepub fn tone(self, tone: SemanticTone) -> Self
pub fn tone(self, tone: SemanticTone) -> Self
Applies a Material 3 semantic tone to this row’s foreground and selected roles.
Explicit MenuItemStyle overrides and disabled styling still take precedence.
Sourcepub fn destructive(self) -> Self
pub fn destructive(self) -> Self
Shorthand for .tone(SemanticTone::Danger) on destructive menu commands.
Sourcepub fn shortcut(self, text: impl Into<SharedString>) -> Self
pub fn shortcut(self, text: impl Into<SharedString>) -> Self
Renders a desktop shortcut hint in the trailing slot using LabelSmall
and OnSurfaceVariant (or disabled color when disabled), unless an
explicit .trailing(...) overrides it.
Turns this row into a submenu trigger containing the given child items.
Sourcepub fn disabled(self, disabled: bool) -> Self
pub fn disabled(self, disabled: bool) -> Self
Marks the item as disabled, preventing activation and applying disabled styling.
Sourcepub fn checked(self, checked: bool) -> Self
pub fn checked(self, checked: bool) -> Self
Turns this row into a checkable menu item with the given caller-owned checked state.
Sourcepub fn selected(self, selected: bool) -> Self
pub fn selected(self, selected: bool) -> Self
Turns this row into a selectable menu item with the given caller-owned selected state.
Sourcepub fn content<E: IntoElement>(self, build: impl Fn() -> E + 'static) -> Self
pub fn content<E: IntoElement>(self, build: impl Fn() -> E + 'static) -> Self
Replaces the visible label while retaining the name passed to new.
Supply a repeatable factory so the content also appears during exit.
Sourcepub fn leading<E: IntoElement>(self, build: impl Fn() -> E + 'static) -> Self
pub fn leading<E: IntoElement>(self, build: impl Fn() -> E + 'static) -> Self
Supplies a decorative element at the logical start of an unmarked row.
Sourcepub fn supporting<E: IntoElement>(self, build: impl Fn() -> E + 'static) -> Self
pub fn supporting<E: IntoElement>(self, build: impl Fn() -> E + 'static) -> Self
Supplies additional visual content below the label.
Sourcepub fn trailing<E: IntoElement>(self, build: impl Fn() -> E + 'static) -> Self
pub fn trailing<E: IntoElement>(self, build: impl Fn() -> E + 'static) -> Self
Supplies decorative content at the logical end of the row.
Sourcepub fn selection_icon<E: IntoElement>(
self,
build: impl Fn() -> E + 'static,
) -> Self
pub fn selection_icon<E: IntoElement>( self, build: impl Fn() -> E + 'static, ) -> Self
Replaces the leading check mark of a checked or selected row.
Sourcepub fn on_checked_change(
self,
callback: impl Fn(bool, &mut Window, &mut App) + 'static,
) -> Self
pub fn on_checked_change( self, callback: impl Fn(bool, &mut Window, &mut App) + 'static, ) -> Self
Requests the inverse of the supplied checked value on activation.
The checked callback takes precedence over on_activate on checked rows.
Sourcepub fn on_activate(
self,
action: impl Fn(&mut Window, &mut App) + 'static,
) -> Self
pub fn on_activate( self, action: impl Fn(&mut Window, &mut App) + 'static, ) -> Self
Registers a callback invoked when an action, checked, or selected row is activated.
Auto Trait Implementations§
impl !RefUnwindSafe for MenuItem
impl !Send for MenuItem
impl !Sync for MenuItem
impl !UnwindSafe for MenuItem
impl Forget for MenuItem
impl Freeze for MenuItem
impl Move for MenuItem
impl Unpin for MenuItem
impl UnsafeUnpin for MenuItem
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more