Skip to main content

MenuItem

Enum MenuItem 

Source
pub enum MenuItem {
    Action {
        id: Option<String>,
        action: u64,
        label: String,
        shortcut: Option<Shortcut>,
        enabled: bool,
        checked: Option<bool>,
        role: Option<MenuRole>,
        icon: Option<Icon>,
    },
    Submenu {
        label: String,
        items: Vec<MenuItem>,
        role: Option<MenuBarRole>,
    },
    Separator,
}
Expand description

One entry in a menu (recursive: a Submenu nests).

Variants§

§

Action

A command. action (nonzero) dispatches Event::MenuAction to the app; a role-only item uses the native standard command instead (action 0). label/shortcut override the role’s defaults. icon is the platform’s own glyph beside the title where menus carry one (macOS, Windows, GNOME, KDE, Android); a backend whose menus are text-only ignores it.

The id/action split is ToolbarItem’s: id names the item and action is what it runs. They are separate because a label cannot serve as a name (it is localized, and an item that shows its own state changes it), so anything addressing an item from outside (dayscript’s menu: { id: … }) needs something that does not move.

Fields

§id: Option<String>

The app’s own name for this item, where it gave one. Stable across locales and across a change of checked, and unique within the menu it is installed in.

§action: u64

The item’s command, as a dispatch id from the same registry Event::MenuAction uses (0 = no command), so a toolbar button and its menu twin can share one closure.

§label: String
§shortcut: Option<Shortcut>
§enabled: bool
§checked: Option<bool>

On/off state where the item stands for a setting or one of several choices, drawn with the platform’s own check mark. None is a plain command and reserves no mark; Some makes the item checkable and says which way it currently sits.

The item still runs its action when chosen; a backend never flips this on its own. The app owns the state, and re-installing the menu (app_menu, which re-lowers on change) is what moves the mark, so what the menu shows can never disagree with what the app thinks.

§icon: Option<Icon>
§

Submenu

A nested submenu. At the top level of an app menu a role claims one of the platform’s standard menu-bar slots: the backend then uses this menu instead of its stock one, and places it where the platform expects that menu to sit.

Fields

§label: String
§items: Vec<MenuItem>
§

Separator

A visual separator.

Trait Implementations§

Source§

impl Clone for MenuItem

Source§

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

impl Debug for MenuItem

Source§

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

Formats the value using the given formatter. Read more
Source§

impl PartialEq for MenuItem

Source§

fn eq(&self, other: &MenuItem) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for MenuItem

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> AnyEq for T
where T: Any + PartialEq,

§

fn equals(&self, other: &(dyn Any + 'static)) -> bool

§

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> 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, 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> IntoReactive<T, StaticMark> for T
where T: Clone + 'static,

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.
Day API ↩ Guides· daybrite.dev