Skip to main content

MenuSpec

Struct MenuSpec 

Source
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§

§menus: Vec<Submenu>

Implementations§

Source§

impl MenuSpec

Source

pub fn new(menus: Vec<Submenu>) -> Self

Source

pub fn from_commands(commands: &[CommandInfo], order: &[&str]) -> Self

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).

Source

pub fn from_items<P: AsRef<[String]>>( entries: impl IntoIterator<Item = (P, Item)>, order: &[&str], ) -> Self

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.

Source

pub fn items(&self) -> Vec<&Item>

Every item, depth first.

Source

pub fn find(&self, id: &str) -> Option<&Item>

The item with id (for items built from commands, the command id).

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn state_hash(&self) -> u64

Fingerprint of what is patched in place: labels, enabled and checked state, disabled reasons.

Source

pub fn validate(&self) -> Result<(), Vec<String>>

Check the spec: unique non-empty ids, bounded size, depth and text, parseable accelerators. Returns every problem found.

Source

pub fn node(&self, path: &[usize]) -> Option<&MenuNode>

The node at path, if any.

Trait Implementations§

Source§

impl Clone for MenuSpec

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MenuSpec

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for MenuSpec

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for MenuSpec

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for MenuSpec

Source§

impl Hash for MenuSpec

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for MenuSpec

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for MenuSpec

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for MenuSpec

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.