pub enum MenuItemSpec {
Item {
id: String,
label: String,
accelerator: Option<String>,
enabled: bool,
},
Role {
role: MenuRole,
label: Option<String>,
},
Separator,
Submenu {
label: String,
menu: MenuSpec,
},
}Expand description
One entry in a MenuSpec.
Deliberately not #[non_exhaustive]: a per-OS shell must match it
exhaustively, so a new variant is a compile error in every shell that would
otherwise silently drop the item from the menu it builds.
Variants§
Item
An app-defined item. Activating it pushes id
through frust_reactive::push_menu_event, which app code observes via
the facade’s menu_events().
Fields
accelerator: Option<String>An accelerator in the cross-platform "CmdOrCtrl+Shift+P" shorthand
(Cmd/Ctrl/Alt/Shift + a key, joined by +), or None for
no keyboard shortcut.
Kept a string rather than a parsed chord type because this crate binds no menu library: the per-OS shell parses it with whatever its menu backend already accepts, and is also where an unparseable accelerator is reported — validating it twice, in two vocabularies, would only let the two disagree.
Role
A platform-standard item (MenuRole) the host implements itself —
About/Hide/Quit and friends. No activation is reported for these: the
platform performs the action, so app code has nothing to handle.
Fields
Separator
A separator line.
A nested menu.
Implementations§
Source§impl MenuItemSpec
impl MenuItemSpec
Sourcepub fn item(id: impl Into<String>, label: impl Into<String>) -> Self
pub fn item(id: impl Into<String>, label: impl Into<String>) -> Self
An enabled, accelerator-free app item.
A nested menu under label.
Sourcepub fn with_accelerator(self, accelerator: impl Into<String>) -> Self
pub fn with_accelerator(self, accelerator: impl Into<String>) -> Self
Attach a keyboard accelerator (see
Item::accelerator).
Returns the item unchanged for every other variant: a role item’s shortcut is the platform’s own (⌘Q for Quit), and a separator/submenu has nothing to activate.
Sourcepub fn disabled(self) -> Self
pub fn disabled(self) -> Self
Mark the item greyed out. Returns the item unchanged for every variant
but MenuItemSpec::Item (see with_accelerator).
Sourcepub fn with_label(self, label: impl Into<String>) -> Self
pub fn with_label(self, label: impl Into<String>) -> Self
Override the label of a MenuItemSpec::Role item. Returns the item
unchanged for every other variant (their labels are set at
construction).
Trait Implementations§
Source§impl Clone for MenuItemSpec
impl Clone for MenuItemSpec
Source§impl Debug for MenuItemSpec
impl Debug for MenuItemSpec
impl Eq for MenuItemSpec
Source§impl PartialEq for MenuItemSpec
impl PartialEq for MenuItemSpec
impl StructuralPartialEq for MenuItemSpec
Auto Trait Implementations§
impl Freeze for MenuItemSpec
impl RefUnwindSafe for MenuItemSpec
impl Send for MenuItemSpec
impl Sync for MenuItemSpec
impl Unpin for MenuItemSpec
impl UnsafeUnpin for MenuItemSpec
impl UnwindSafe for MenuItemSpec
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.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.