pub struct MenuSpec {
pub menus: Vec<Submenu>,
}Expand description
The whole menu bar: top-level menus in order. On macOS the first is the application menu (its title is replaced by the app name by the OS).
Fields§
Implementations§
Source§impl MenuSpec
impl MenuSpec
pub fn new(menus: Vec<Submenu>) -> MenuSpec
Sourcepub fn from_commands(commands: &[CommandInfo], order: &[&str]) -> MenuSpec
pub fn from_commands(commands: &[CommandInfo], order: &[&str]) -> MenuSpec
A menu bar mirrored from a command list: each command with a non-empty menu path goes
into the submenu that path names (["File", "Export"] = File ▸ Export), in list order,
with its label, shortcut (normalized when it parses), enabled state and disabled reason.
Top-level menus follow order; menus not in it come after, in first-seen order. Paths
deeper than MAX_DEPTH are cut there. Separators, check marks and roles are the app’s to
add (Self::separator_before, Self::set_checked).
Sourcepub fn from_items<P>(
entries: impl IntoIterator<Item = (P, Item)>,
order: &[&str],
) -> MenuSpec
pub fn from_items<P>( entries: impl IntoIterator<Item = (P, Item)>, order: &[&str], ) -> MenuSpec
A menu bar from items with their menu paths, for apps whose menu entries carry more than a
CommandInfo (check marks, translated titles): each (path, item) goes into the submenu
path names (["File", "Export"] = File ▸ Export), in order, each submenu created where
its first item appears. Entries with an empty path are skipped; paths deeper than
MAX_DEPTH are cut there. Top-level menus follow order; menus not in it come after, in
first-seen order.
Sourcepub fn find(&self, id: &str) -> Option<&Item>
pub fn find(&self, id: &str) -> Option<&Item>
The item with id (for items built from commands, the command id).
Sourcepub fn walk<'a>(&'a self, f: &mut dyn FnMut(&[usize], &'a MenuNode))
pub fn walk<'a>(&'a self, f: &mut dyn FnMut(&[usize], &'a MenuNode))
Visit every node with its path, depth first, at most MAX_DEPTH deep.
Sourcepub fn separator_before(&mut self, id: &str) -> bool
pub fn separator_before(&mut self, id: &str) -> bool
Insert a separator before the item id, unless it is first in its menu or already follows
one. Returns whether the item was found.
Sourcepub fn set_checked(&mut self, id: &str, checked: Option<bool>) -> bool
pub fn set_checked(&mut self, id: &str, checked: Option<bool>) -> bool
Set the check mark of the item id (None: a plain item again). Returns whether it was
found.
Sourcepub fn structure_hash(&self) -> u64
pub fn structure_hash(&self) -> u64
Fingerprint of everything that needs a native rebuild when it changes: the tree’s shape, item ids, check-item-ness, roles and menu key equivalents. Labels, enabled and checked state are patched in place instead.
Sourcepub fn state_hash(&self) -> u64
pub fn state_hash(&self) -> u64
Fingerprint of what is patched in place: labels, enabled and checked state, disabled reasons.