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: u64The 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.
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.
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.
Separator
A visual separator.
Trait Implementations§
impl StructuralPartialEq for MenuItem
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§
§impl<T> AnyEq for T
impl<T> AnyEq for T
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> ErasedDestructor for Twhere
T: 'static,
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