#[non_exhaustive]pub struct MenuItem { /* private fields */ }Expand description
A command in a menu.
The key names the row’s element id and the
MenuEvent::Activated payload, so it
comes from the domain and is unique in the menu, submenus included.
An item does one thing when chosen: it dispatches an
action, whose shortcut the row shows, calls
on_select, or opens a link. An
item with none of them only reports its key.
Implementations§
Source§impl MenuItem
impl MenuItem
Sourcepub fn new(key: impl Into<SharedString>, label: impl Into<SharedString>) -> Self
pub fn new(key: impl Into<SharedString>, label: impl Into<SharedString>) -> Self
An item with a stable key and the label it shows.
Sourcepub fn description(self, description: impl Into<SharedString>) -> Self
pub fn description(self, description: impl Into<SharedString>) -> Self
A line under the label, in the menu’s description color.
Sourcepub fn checked(self, checked: bool) -> Self
pub fn checked(self, checked: bool) -> Self
Makes the item a toggle: a check shows in the leading slot while
checked is true, in place of the icon.
Sourcepub fn radio(self, selected: bool) -> Self
pub fn radio(self, selected: bool) -> Self
Makes the item one of a group of radio items: a dot shows in the
leading slot while selected is true. The application keeps which
one of the group is on.
Sourcepub fn destructive(self) -> Self
pub fn destructive(self) -> Self
Paints the item in the destructive color, for a command that deletes or cannot be undone.
Sourcepub fn action(self, action: impl Action) -> Self
pub fn action(self, action: impl Action) -> Self
Dispatches action when the item is chosen, to the element the
menu acts on, and shows the action’s shortcut.
Sourcepub fn action_context(self, focus_handle: &FocusHandle) -> Self
pub fn action_context(self, focus_handle: &FocusHandle) -> Self
The element this item’s action goes to, and whose key bindings its shortcut shows, in place of the menu’s.
Sourcepub fn on_select(
self,
handler: impl Fn(&mut Window, &mut App) + 'static,
) -> Self
pub fn on_select( self, handler: impl Fn(&mut Window, &mut App) + 'static, ) -> Self
Calls handler when the item is chosen, once the menu has closed.
Sourcepub fn link(self, url: impl Into<SharedString>) -> Self
pub fn link(self, url: impl Into<SharedString>) -> Self
Opens url in the system’s browser or mail client when chosen. The
row shows an external-link icon after the label.
Sourcepub fn external_link_icon(self, visible: bool) -> Self
pub fn external_link_icon(self, visible: bool) -> Self
Whether a link item shows its external-link icon. On by default.
Sourcepub fn render<E: IntoElement>(
self,
render: impl Fn(MenuRowState, &mut Window, &mut App) -> E + 'static,
) -> Self
pub fn render<E: IntoElement>( self, render: impl Fn(MenuRowState, &mut Window, &mut App) -> E + 'static, ) -> Self
Draws the inside of the row: render gets the row’s state and
returns what goes between the row’s padding, in place of the
indicator, icon, label, description, and shortcut. The row itself
(its height, highlight, hover, and click) stays the menu’s.
Sourcepub fn key(&self) -> &SharedString
pub fn key(&self) -> &SharedString
The item’s key.
Sourcepub fn label(&self) -> &SharedString
pub fn label(&self) -> &SharedString
The text the item shows.
Sourcepub fn description_text(&self) -> Option<&SharedString>
pub fn description_text(&self) -> Option<&SharedString>
The line under the label.
Sourcepub fn is_disabled(&self) -> bool
pub fn is_disabled(&self) -> bool
Whether the item ignores input.
Sourcepub fn is_checked(&self) -> bool
pub fn is_checked(&self) -> bool
Whether the item is a toggle or a radio item that is on.
Sourcepub fn is_destructive(&self) -> bool
pub fn is_destructive(&self) -> bool
Whether the item is painted as destructive.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for MenuItem
impl !Send for MenuItem
impl !Sync for MenuItem
impl !UnwindSafe for MenuItem
impl Freeze 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.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