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
The desktop app’s identity and native-integration vocabulary, re-exported
from the desktop core so app code never names a shell crate:
DesktopConfig (the whole declaration — app name, reverse-DNS id, window
icon, menu bar, last-window-close policy — handed to App::desktop,
run_desktop_config or app!’s desktop = { .. } argument),
MenuSpec/MenuItemSpec/MenuRole (the platform-independent native
menu tree a per-OS shell translates into an NSApp menu bar or an HMENU),
DesktopIconData (decoded, tightly-packed RGBA8 — decoding a
PNG/ICO/ICNS is the caller’s job), and DEFAULT_APP_NAME (the window
title a config that names nothing still gets).
frust-shell-desktop‘s IconData is re-exported renamed: the facade
already carries frust-widgets’ IconData, an in-UI vector icon, and the
two are unrelated (one is a BezPath a widget paints, the other is the
window/taskbar bitmap the OS shows). The Desktop prefix matches
DesktopConfig, whose with_window_icon is its only consumer.
use frust::{DesktopConfig, MenuItemSpec, MenuRole, MenuSpec};
let file = MenuSpec::new()
.with_item(MenuItemSpec::item("file.open", "Open…").with_accelerator("CmdOrCtrl+O"))
.with_item(MenuItemSpec::separator())
.with_item(MenuItemSpec::role(MenuRole::Quit));
let config = DesktopConfig::new()
.with_app_name("Huddle")
.with_app_id("dev.frust.huddle")
.with_menu_spec(MenuSpec::new().with_item(MenuItemSpec::submenu("File", file)));Desktop-only, unlike the menu_events read side: these types are
defined in frust-shell-desktop, which is not in a mobile build’s or a
wasm32 build’s dependency graph at all (see this crate’s Cargo.toml).
Code shared with a mobile or wasm32 target keeps a DesktopConfig behind
its own
#[cfg(not(any(target_os = "android", target_os = "ios", target_arch = "wasm32")))]
— or, more simply, writes it inline in app!’s desktop = { .. }
argument, which the macro already emits only on the targets that have it.
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>) -> MenuItemSpec
pub fn item(id: impl Into<String>, label: impl Into<String>) -> MenuItemSpec
An enabled, accelerator-free app item.
Sourcepub fn role(role: MenuRole) -> MenuItemSpec
pub fn role(role: MenuRole) -> MenuItemSpec
A platform-standard item at the platform’s own label.
Sourcepub fn separator() -> MenuItemSpec
pub fn separator() -> MenuItemSpec
A separator line.
A nested menu under label.
Sourcepub fn with_accelerator(self, accelerator: impl Into<String>) -> MenuItemSpec
pub fn with_accelerator(self, accelerator: impl Into<String>) -> MenuItemSpec
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) -> MenuItemSpec
pub fn disabled(self) -> MenuItemSpec
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>) -> MenuItemSpec
pub fn with_label(self, label: impl Into<String>) -> MenuItemSpec
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§fn clone(&self) -> MenuItemSpec
fn clone(&self) -> MenuItemSpec
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§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§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.