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<MenuItem, String>
pub fn from_value(v: &Value) -> Result<MenuItem, 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<MenuItem>, String>
pub fn list_from_value(v: &Value) -> Result<Vec<MenuItem>, String>
A menu’s rows from plain data: a list of Self::from_value maps.
Sourcepub fn options_from_value(v: &Value) -> Result<Vec<MenuItem>, String>
pub fn options_from_value(v: &Value) -> Result<Vec<MenuItem>, 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.
Sourcepub fn role(role: MenuRole) -> MenuItem
pub fn role(role: MenuRole) -> MenuItem
One of the standard items, with the role’s own wording.
pub fn separator() -> MenuItem
pub fn enabled(self, on: bool) -> MenuItem
Sourcepub fn checked(self, on: bool) -> MenuItem
pub fn checked(self, on: bool) -> MenuItem
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>) -> MenuItem
pub fn accel(self, a: impl Into<String>) -> MenuItem
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.
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§
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.