pub struct MenuItem {
pub label: String,
pub role: MenuRole,
pub enabled: bool,
pub id: Option<Value>,
pub checked: bool,
pub accel: Option<String>,
pub submenu: Vec<MenuItem>,
}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.
The rows of the menu this row opens: empty for an ordinary row. A
row with a submenu is drawn with a chevron and is never chosen
itself — hovering it, clicking it, Enter or the Right arrow opens
its menu beside it, and Left or Escape closes it again — and what
a chosen row inside posts is that row’s own menu event, on the
node the outermost menu is about (backlog F128). Nests to any
depth. MenuItem::submenu(label, items) builds one.
Implementations§
Source§impl MenuItem
impl MenuItem
Sourcepub const KEYS: [&'static str; 7]
pub const KEYS: [&'static str; 7]
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, accel and items (a submenu’s rows, the same maps).
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.
A row that opens a menu of items beside it: “Move to ▸”, “Sort
by ▸”. It is chosen through, never itself — see the submenu
field — so it needs no id, and an accel on it is not drawn (the
chevron is where it would go). A submenu with no rows is an ordinary
row (Self::has_submenu).
use kui_core::MenuItem;
let sort = MenuItem::submenu("Sort by", vec![
MenuItem::new("Name").id("sort.name").checked(true),
MenuItem::new("Date modified").id("sort.date"),
]);
assert!(sort.has_submenu());Whether the row opens a menu rather than being chosen (the
submenu field). A row declared with an empty submenu is an
ordinary row.
Sourcepub fn at_path<'a>(
items: &'a [MenuItem],
path: &[usize],
) -> Option<&'a MenuItem>
pub fn at_path<'a>( items: &'a [MenuItem], path: &[usize], ) -> Option<&'a MenuItem>
The row at path in items: [2] is the third row, [2, 0] the
first row of the third row’s submenu. None past the end of any
level, for an empty path, and through a row with no submenu.
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>
The accelerator the row declares: its own, or the role’s. None is
a row with neither, which is every Custom one the app did not
spell a shortcut for. As declared — Self::accel_label is what is
drawn.
Sourcepub fn accel_label(&self) -> Option<Cow<'_, str>>
pub fn accel_label(&self) -> Option<Cow<'_, str>>
What the row draws on its right: Self::accel_text in the
platform’s spelling when kui can parse it ("mod+shift+n" reads
⇧⌘N on a Mac and Ctrl+Shift+N elsewhere), and exactly as
written when it cannot ("gd", an app’s own hint). See
Accel::label.
Sourcepub fn selectable(&self) -> bool
pub fn selectable(&self) -> bool
Whether the row takes focus and can be chosen — or, for a row with a submenu, opened.
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.