Enum MenuItem
pub enum MenuItem {
Action {
label: String,
action: Rc<dyn Fn()>,
icon: Option<Icon>,
checked: Option<bool>,
destructive: bool,
enabled: bool,
shortcut: Option<Shortcut>,
submenu: Option<Vec<MenuItem>>,
},
Separator,
}Expand description
Separators are purely visual and ignored by ContextMenu::click_item.
Variants§
Action
Fields
icon: Option<Icon>Optional leading icon for command recognition. Icons are visual
reinforcement only; label remains the accessible name.
checked: Option<bool>Some reserves the leading selection gutter and publishes a
semantic checked state. None is an ordinary command row.
destructive: boolDestructive rows are styled as danger actions and are never the implicit keyboard target when a menu opens.
shortcut: Option<Shortcut>The keyboard shortcut that runs the same command, shown at the row’s trailing edge in the platform’s spelling.
Some makes the row open a nested menu (with a chevron) instead
of running action.
Separator
Implementations§
§impl MenuItem
impl MenuItem
pub fn action<F>(label: impl Into<String>, action: F) -> MenuItemwhere
F: Fn() + 'static,
pub fn icon_action<F>(
icon: Icon,
label: impl Into<String>,
action: F,
) -> MenuItemwhere
F: Fn() + 'static,
pub fn icon_action<F>(
icon: Icon,
label: impl Into<String>,
action: F,
) -> MenuItemwhere
F: Fn() + 'static,
A command row with a themed leading icon. Menus containing icon rows reserve the same gutter for every command so labels stay aligned.
pub fn selection(label: impl Into<String>) -> MenuItem
pub fn destructive_action<F>(label: impl Into<String>, action: F) -> MenuItemwhere
F: Fn() + 'static,
pub fn destructive_selection(label: impl Into<String>) -> MenuItem
A row that opens a nested menu of items beside it: on hover, a
click, Enter or the arrow towards it. Its chevron says so.
pub fn with_icon(self, icon: Icon) -> MenuItem
pub fn with_shortcut(self, shortcut: impl Into<Shortcut>) -> MenuItem
pub fn with_shortcut(self, shortcut: impl Into<Shortcut>) -> MenuItem
Show the keyboard shortcut that runs the same command at the row’s
trailing edge (Shortcut::command("S"), Shortcut::key("Delete")).
pub fn with_enabled(self, enabled: bool) -> MenuItem
pub fn with_enabled(self, enabled: bool) -> MenuItem
Set whether this command can currently be invoked.
pub fn with_checked(self, checked: bool) -> MenuItem
pub fn with_checked(self, checked: bool) -> MenuItem
Make this a state row (“Copy on select”, a sort order): a check mark
when checked, and a semantic checked state either way. Checked and
unchecked peers share the same leading gutter, so labels never jump
as state changes.
pub fn separator() -> MenuItem
pub fn label(&self) -> Option<&str>
pub fn checked(&self) -> Option<bool>
pub fn checked(&self) -> Option<bool>
Semantic checked state for choice/toggle rows. None means this is a
regular command, rather than an unchecked choice.
The nested menu’s rows, for a row that opens one.
pub fn is_enabled(&self) -> bool
Trait Implementations§
Auto Trait Implementations§
impl Freeze for MenuItem
impl !RefUnwindSafe for MenuItem
impl !Send for MenuItem
impl !Sync for MenuItem
impl Unpin for MenuItem
impl UnsafeUnpin for MenuItem
impl !UnwindSafe 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§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.§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.§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.§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.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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