Skip to main content

MenuItem

Struct MenuItem 

Source
pub struct MenuItem { /* private fields */ }
Expand description

An item in a Material menu. Callers retain command and selection state.

Implementations§

Source§

impl MenuItem

Source

pub fn new(id: impl Into<ElementId>, label: impl Into<SharedString>) -> MenuItem

Creates a standard action menu item with the given element ID and label.

Source

pub fn group( id: impl Into<ElementId>, title: impl Into<SharedString>, ) -> MenuItem

Creates a non-interactive section heading row that is skipped by keyboard navigation.

Source

pub fn divider(id: impl Into<ElementId>) -> MenuItem

Creates a non-interactive horizontal divider row inside a menu that is skipped by keyboard navigation.

Source

pub fn section( id: impl Into<ElementId>, name: impl Into<SharedString>, rows: impl IntoIterator<Item = MenuItem>, ) -> MenuItem

Creates a surfaced group with rows in the owning menu’s navigation order.

Source

pub fn group_appearance(self, appearance: MenuSurfaceStyle) -> MenuItem

Sets the styled section’s surface appearance.

Source

pub fn inactive_shape(self, shape: CornerShape) -> MenuItem

Sets the section shape used after the pointer leaves the section.

Source

pub fn appearance(self, style: MenuItemStyle) -> MenuItem

Configures the appearance of an action, checked or selected row.

Source

pub fn tone(self, tone: SemanticTone) -> MenuItem

Applies a Material 3 semantic tone to this row’s foreground and selected roles. Explicit MenuItemStyle overrides and disabled styling still take precedence.

Source

pub fn destructive(self) -> MenuItem

Shorthand for .tone(SemanticTone::Danger) on destructive menu commands.

Source

pub fn shortcut(self, text: impl Into<SharedString>) -> MenuItem

Renders a desktop shortcut hint in the trailing slot using LabelSmall and OnSurfaceVariant (or disabled color when disabled), unless an explicit .trailing(...) overrides it.

Source

pub fn submenu(self, items: impl IntoIterator<Item = MenuItem>) -> MenuItem

Turns this row into a submenu trigger containing the given child items.

Source

pub fn disabled(self, disabled: bool) -> MenuItem

Marks the item as disabled, preventing activation and applying disabled styling.

Source

pub fn checked(self, checked: bool) -> MenuItem

Turns this row into a checkable menu item with the given caller-owned checked state.

Source

pub fn selected(self, selected: bool) -> MenuItem

Turns this row into a selectable menu item with the given caller-owned selected state.

Source

pub fn content<E>(self, build: impl Fn() -> E + 'static) -> MenuItem
where E: IntoElement,

Replaces the visible label while retaining the name passed to new. Supply a repeatable factory so the content also appears during exit.

Source

pub fn leading<E>(self, build: impl Fn() -> E + 'static) -> MenuItem
where E: IntoElement,

Supplies a decorative element at the logical start of an unmarked row.

Source

pub fn supporting<E>(self, build: impl Fn() -> E + 'static) -> MenuItem
where E: IntoElement,

Supplies additional visual content below the label.

Source

pub fn trailing<E>(self, build: impl Fn() -> E + 'static) -> MenuItem
where E: IntoElement,

Supplies decorative content at the logical end of the row.

Source

pub fn selection_icon<E>(self, build: impl Fn() -> E + 'static) -> MenuItem
where E: IntoElement,

Replaces the leading check mark of a checked or selected row.

Source

pub fn on_checked_change( self, callback: impl Fn(bool, &mut Window, &mut App) + 'static, ) -> MenuItem

Requests the inverse of the supplied checked value on activation. The checked callback takes precedence over on_activate on checked rows.

Source

pub fn on_activate( self, action: impl Fn(&mut Window, &mut App) + 'static, ) -> MenuItem

Registers a callback invoked when an action, checked, or selected row is activated.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more