pub struct StandardMenu { /* private fields */ }Expand description
A platform-standard menu (macOS App / Window / Help) with localized
labels. The framework wires the system selectors (About / Hide / Quit,
Minimize / Zoom); you supply the strings — defaults are English lit!s, so
pass tr!-resolved [LocalizedString]s for a localized app menu. This keeps
the OS menu bar inside the i18n net like every other widget.
Implementations§
Source§impl StandardMenu
impl StandardMenu
Sourcepub fn app() -> Self
pub fn app() -> Self
The application menu (About / Hide / Quit). title is the bold app-name
submenu label — set it to your localized app name.
Sourcepub fn for_role(role: StandardMenuRole) -> Self
pub fn for_role(role: StandardMenuRole) -> Self
Default standard menu for a role.
Sourcepub fn role(&self) -> StandardMenuRole
pub fn role(&self) -> StandardMenuRole
This menu’s role.
Sourcepub fn title(self, title: impl Into<LocalizedString>) -> Self
pub fn title(self, title: impl Into<LocalizedString>) -> Self
Submenu title (the app name for App; the menu label for Window / Help).
Sourcepub fn settings(self, label: impl Into<LocalizedString>) -> Self
pub fn settings(self, label: impl Into<LocalizedString>) -> Self
“Settings…” label (App). macOS 13+ says “Settings…”; older releases said “Preferences…” — pass whichever your app targets, localized.
The label alone does not create the item: pair it with
settings_intent.
Sourcepub fn quit_intent(self, intent: &'static str) -> Self
pub fn quit_intent(self, intent: &'static str) -> Self
Route the App menu’s Quit through intent instead of the platform’s
terminate selector, keeping its ⌘Q key equivalent.
Set this whenever quitting has to pass through the app first — unsaved
work to confirm, a session to write out, a background job to stop. By
default the item is the platform’s own (terminate: on macOS), which
exits immediately: it never reaches winit’s exit path, so no
LoopExiting hook and nothing the app registered runs.
An in-app ⌘Q shortcut is not a substitute. AppKit dispatches main-menu key equivalents before the responder chain, so the App menu’s item wins and the app’s own shortcut never sees the keystroke — the app looks wired up and is not. Routing the item is the only place that decision can be taken.
Whatever intent resolves to now owns the exit — nothing terminates on
the app’s behalf once this is set.
StandardMenu::app()
.title(tr!(app_name()))
.quit(tr!(quit()))
.quit_intent("app.quit") // the guarded action, same as File ▸ QuitSourcepub fn quit_intent_name(&self) -> Option<&'static str>
pub fn quit_intent_name(&self) -> Option<&'static str>
The intent quit_intent installed, or None if
Quit is still the platform’s own terminate selector.
Public so an app can test that its Quit is guarded. Everything the routing does happens on macOS, where a downstream test suite generally does not run, so without a getter the difference between a guarded ⌘Q and an unguarded one is invisible from the app’s side — which is the same blind spot that let the unrouted default ship in the first place.
Sourcepub fn settings_intent(self, intent: &'static str) -> Self
pub fn settings_intent(self, intent: &'static str) -> Self
Put Settings… in the App menu, routed through intent, with the
platform’s own placement and key equivalent (⌘, on macOS).
macOS keeps app settings in the application menu, not in File or Edit,
and ⌘, is the only chord users try. Neither is reachable from a plain
MenuEntry: the App menu is filled in by the platform, so an entry the
model declares lands in some other menu instead.
Unlike quit_intent this is the only way to get
the item at all — no platform opens an app’s settings on its own, so
leaving it unset omits the row rather than falling back to a system
behaviour. Route it to the same intent your in-window “Settings” command
fires, and the two stay one command.
StandardMenu::app()
.title(tr!(app_name()))
.settings(tr!(settings()))
.settings_intent("app.settings")Sourcepub fn settings_intent_name(&self) -> Option<&'static str>
pub fn settings_intent_name(&self) -> Option<&'static str>
The intent settings_intent installed, or
None if the App menu carries no Settings item.
Public for the same reason as
quit_intent_name: the wiring only takes
effect on macOS, where an app’s test suite generally does not run, so
without a getter a missing route is invisible from the app’s side.
Sourcepub fn quit_shortcut(self, id: &'static str) -> Self
pub fn quit_shortcut(self, id: &'static str) -> Self
The intent + item id settings_intent
installed, if any.
Advertise the registered shortcut id on the routed Quit row,
instead of the platform’s conventional chord (⌘Q on macOS).
Worth naming whenever the app registers a quit shortcut of its own —
which is to say whenever quit_intent is set, since
the intent has to be reachable somehow. The chord then comes from the
ShortcutRegistry like every other menu row’s: it follows the
primary-accelerator convention, and it follows a user’s rebind. Left
unset, this row is the one place in the app advertising a chord nothing
registered — still live after the user moved the command elsewhere, and
shadowing the chord they moved it to, because the platform dispatches a
main-menu key equivalent before the responder chain.
Sourcepub fn settings_shortcut(self, id: &'static str) -> Self
pub fn settings_shortcut(self, id: &'static str) -> Self
Advertise the registered shortcut id on the routed Settings… row,
instead of the platform’s conventional chord (⌘, on macOS). Same
reasoning as quit_shortcut.
Sourcepub fn quit_shortcut_id(&self) -> Option<&'static str>
pub fn quit_shortcut_id(&self) -> Option<&'static str>
The shortcut id named for the Quit row, if any.
Sourcepub fn settings_shortcut_id(&self) -> Option<&'static str>
pub fn settings_shortcut_id(&self) -> Option<&'static str>
The shortcut id named for the Settings row, if any.
Trait Implementations§
Source§impl Clone for StandardMenu
impl Clone for StandardMenu
Source§fn clone(&self) -> StandardMenu
fn clone(&self) -> StandardMenu
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for StandardMenu
impl !Send for StandardMenu
impl !Sync for StandardMenu
impl !UnwindSafe for StandardMenu
impl Freeze for StandardMenu
impl Unpin for StandardMenu
impl UnsafeUnpin for StandardMenu
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,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§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.§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.§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.§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.impl<T> ErasedDestructor for Twhere
T: 'static,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more