Enum MenuItem
pub enum MenuItem {
Action {Show 14 fields
label: String,
action: Rc<dyn Fn()>,
icon: Option<Icon>,
checked: Option<bool>,
destructive: bool,
enabled: bool,
shortcut: Option<Shortcut>,
detail: Option<String>,
description: Option<String>,
submenu: Option<Vec<MenuItem>>,
group: Option<String>,
asks_first: bool,
address: Option<ActionAddress>,
press: Press,
},
Separator,
Caption(String),
Emoji(EmojiRow),
}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.
detail: Option<String>A short fact at the row’s trailing edge in place of a shortcut: how many results share a filter’s value.
description: Option<String>What choosing the row does beyond its name (“Open apps close”), read by assistive technology and never painted.
Some makes the row open a nested menu (with a chevron) instead
of running action.
group: Option<String>The run of a resource’s actions this row stands in (group: "Due"),
as the app names it: consecutive rows of one run fold into one row
that opens the run’s commands (MenuItem::fold_groups).
asks_first: boolThe row’s choice is confirmed before it runs, except that Shift
skips the question for what Undo takes back
(MenuItem::asking_first).
address: Option<ActionAddress>The published action choosing the row runs, when it is one
(MenuItem::for_action).
Separator
Caption(String)
A line of secondary text about the rows around it (“Hosted by example.org”): read, never chosen. Keyboard and pointer pass over it.
Emoji(EmojiRow)
A row of emoji to pick one from (a message’s quick reactions), and a
last cell that opens the emoji picker for any other
(MenuItem::emoji_row).
Implementations§
§impl MenuItem
impl MenuItem
pub fn with_destructive(self, destructive: bool) -> MenuItem
pub fn with_destructive(self, destructive: bool) -> MenuItem
It takes something away: it is undone, not confirmed, and is drawn as such.
pub fn with_group(self, group: impl Into<String>) -> MenuItem
pub fn with_group(self, group: impl Into<String>) -> MenuItem
Name the run of commands this row stands in (group: "Due"): consecutive
rows of one run fold into a row of their own that opens them
(MenuItem::fold_groups).
pub fn fold_groups(items: Vec<MenuItem>) -> Vec<MenuItem>
pub fn fold_groups(items: Vec<MenuItem>) -> Vec<MenuItem>
The rows with each run of consecutive commands of one group (group: "Due")
folded into one row named for the group, which opens them: the first group
row keeps the run’s icon and shows a check when one of its commands is on.
A run of one command stays the command itself, since a menu that opens one
row says nothing its label does not. The commands keep their order and
their keys, and say why they cannot run now.
pub fn fold_numbered(
rows: Vec<(usize, MenuItem)>,
) -> (Vec<MenuItem>, Vec<MenuPick>)
pub fn fold_numbered( rows: Vec<(usize, MenuItem)>, ) -> (Vec<MenuItem>, Vec<MenuPick>)
Self::fold_groups, keeping what each folded row stands for: the command
whose index it was given, or the indices of the run a group row opens.
§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_detail(self, text: impl Into<String>) -> MenuItem
pub fn with_detail(self, text: impl Into<String>) -> MenuItem
Show text at the row’s trailing edge, where a shortcut would stand:
a short fact about the choice, such as how many results share it.
pub fn with_description(self, text: impl Into<String>) -> MenuItem
pub fn with_description(self, text: impl Into<String>) -> MenuItem
Say what choosing the row does beyond its name (“Open apps close”): assistive technology reads it with the row; it is not painted.
pub fn asking_first(self) -> MenuItem
pub fn asking_first(self) -> MenuItem
Say that choosing this row asks before it goes ahead (Delete in a message’s menu), which Shift skips for what Undo takes back. The row says so the way menus do: “Delete message…” while it will ask, and “Delete message” while Shift is held and it will not.
pub fn for_action(self, action_address: ActionAddress) -> MenuItem
pub fn for_action(self, action_address: ActionAddress) -> MenuItem
Say that choosing this row runs the published action address (a
row’s resource action, a bound command): the open menu publishes no
control of its own for the row and names the action as its binding,
so an agent finds the action itself rather than a menu row.
pub fn for_press(self, press: Press) -> MenuItem
pub fn for_press(self, press: Press) -> MenuItem
Say that choosing the row presses what the view bound to it (press): the row runs the
action itself, through the menu’s custody.
pub fn action_address(&self) -> Option<ActionAddress>
pub fn action_address(&self) -> Option<ActionAddress>
The published action choosing the row runs, if it is one: the action the view bound to
the row’s press, else the one it named (Self::for_action).
pub fn shown_label(&self) -> Option<Cow<'_, str>>
pub fn shown_label(&self) -> Option<Cow<'_, str>>
The row’s label as it reads now: with the ellipsis of a choice that
asks first, unless Shift is held (shift_held).
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 caption(text: impl Into<String>) -> MenuItem
pub fn caption(text: impl Into<String>) -> MenuItem
A line of secondary text, never a command; see MenuItem::Caption.
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
pub fn is_separator(&self) -> bool
pub fn is_separator(&self) -> bool
Whether it is a rule between groups.
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> 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>, which can then be
downcast into Box<dyn 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>, which 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