pub struct MenuItem {
pub label: String,
pub role: MenuRole,
pub enabled: bool,
pub id: Option<Value>,
pub checked: bool,
pub accel: Option<String>,
}Expand description
One row of a menu.
Fields§
§label: StringWhat the row reads. Empty takes the role’s default wording.
role: MenuRole§enabled: boolA disabled row is drawn dimmed, is not focusable, and cannot be chosen — Paste with an empty clipboard, Copy with no selection. Present rather than absent on purpose: a menu whose rows move depending on what is possible is a menu nobody builds muscle memory for.
id: Option<Value>Posted as the event payload when the row is chosen. A Custom
item without one posts its label.
checked: boolDrawn with a checkmark, and the platform’s own check state where a host renders the menu itself. A setting the row is rather than a command it runs — View ▸ Show Sidebar — and inert for every other row, which is why it is a flag beside the label and not a role.
accel: Option<String>Drawn right-aligned and dimmed; the core binds nothing to it. The
keyboard shortcut is the app’s or the platform’s, and an
accelerator here only says which one it is. A standard row that
declares none takes its role’s (MenuRole::default_accel), the
way an empty label takes the role’s wording.
Implementations§
Source§impl MenuItem
impl MenuItem
Sourcepub const KEYS: [&'static str; 6]
pub const KEYS: [&'static str; 6]
The keys a row map may carry — everything Self::from_value
reads. A binding that drops the rest of a map on the floor checks
against this first and raises crate::diag::unknown_menu_item_key
for what it dropped, so {label, disabled: true} is not silently a
row that is enabled.
Sourcepub const NAME: &'static str = "menuItem"
pub const NAME: &'static str = "menuItem"
The name a binding reports a row’s dropped keys under
(diag::unknown_prop routes it to diag::unknown_menu_item_key):
a row is not an element, so it is not in schema::ELEMENTS, and
the spelling is the type’s in JSX (MenuItemInput).
Sourcepub fn from_value(v: &Value) -> Result<Self, String>
pub fn from_value(v: &Value) -> Result<Self, String>
A row from plain data: a map with label, role (a wire name;
absent is custom), enabled (default true), checked (default
false), id and accel. A custom row needs a label, since the
label is what it posts when it has no id. Every binding funnels
its rows through here — openMenu’s list and a menu bar’s alike —
so a row can never mean two things.
Sourcepub fn list_from_value(v: &Value) -> Result<Vec<Self>, String>
pub fn list_from_value(v: &Value) -> Result<Vec<Self>, String>
A menu’s rows from plain data: a list of Self::from_value maps.
Sourcepub fn options_from_value(v: &Value) -> Result<Vec<Self>, String>
pub fn options_from_value(v: &Value) -> Result<Vec<Self>, String>
A select’s options from plain data (widgets::select_items in the
bindings): a list whose entries are strings — an option by its
label, posting it — or Self::from_value maps, for an option
that posts an id of its own or is disabled. An empty list is
refused: a select with nothing to choose from is a field that opens
a menu of no rows, which only Escape leaves.
pub fn separator() -> Self
pub fn enabled(self, on: bool) -> Self
Sourcepub fn checked(self, on: bool) -> Self
pub fn checked(self, on: bool) -> Self
Draws a checkmark beside the row (and sets the platform’s check state where a host renders the menu).
pub fn id(self, id: impl Into<Value>) -> Self
pub fn accel(self, a: impl Into<String>) -> Self
Sourcepub fn accel_text(&self) -> Option<&str>
pub fn accel_text(&self) -> Option<&str>
What the row draws on its right: its own accelerator, or the
role’s. None is a row with neither, which is every Custom one
the app did not spell a shortcut for.
Sourcepub fn selectable(&self) -> bool
pub fn selectable(&self) -> bool
Whether the row takes focus and can be chosen.