Skip to main content

MenuItem

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

§label: String
§action: Rc<dyn Fn()>
§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: bool

Destructive rows are styled as danger actions and are never the implicit keyboard target when a menu opens.

§enabled: bool

Disabled rows remain visible and announced but cannot be invoked.

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

§submenu: Option<Vec<MenuItem>>

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: bool

The 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).

§press: Press

What a press of the row does, when the view bound it: the action runs through the menu’s custody, as a control’s own press does.

§

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

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

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 group(&self) -> Option<&str>

The run of commands the row stands in, when it names one.

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>)

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

pub fn action<F>(label: impl Into<String>, action: F) -> MenuItem
where F: Fn() + 'static,

pub fn icon_action<F>( icon: Icon, label: impl Into<String>, action: F, ) -> MenuItem
where 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) -> MenuItem
where F: Fn() + 'static,

pub fn destructive_selection(label: impl Into<String>) -> MenuItem

pub fn submenu(label: impl Into<String>, items: Vec<MenuItem>) -> 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

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

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

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

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

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

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 press(&self) -> Option<&Press>

The press choosing the row does, when the view bound it.

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>>

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

Set whether this command can currently be invoked.

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

A line of secondary text, never a command; see MenuItem::Caption.

pub fn label(&self) -> Option<&str>

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.

pub fn shortcut(&self) -> Option<&Shortcut>

The shortcut shown on the row, if any.

pub fn submenu_items(&self) -> Option<&[MenuItem]>

The nested menu’s rows, for a row that opens one.

pub fn is_enabled(&self) -> bool

pub fn is_separator(&self) -> bool

Whether it is a rule between groups.

pub fn emoji_row( emoji: Vec<String>, pick: impl Fn(&str) + 'static, more: Option<Rc<dyn Fn()>>, ) -> MenuItem

A row of emoji to pick one from: pick runs with the one chosen, and more, when given, is a last cell that opens the emoji picker.

Trait Implementations§

§

impl Clone for MenuItem

§

fn clone(&self) -> MenuItem

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for MenuItem

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

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
§

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

§

fn as_any(&self) -> &(dyn Any + 'static)

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &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 T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

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

Converts 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)

Converts &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)

Converts &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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

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

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

§

fn simd_from(_simd: S, value: T) -> T

§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

§

fn simd_into(self, simd: S) -> T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

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