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.