Skip to main content

StandardMenu

Struct StandardMenu 

Source
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

Source

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.

Source

pub fn window() -> Self

The Window menu (Minimize / Zoom + the live window list).

Source

pub fn help() -> Self

The Help menu.

Source

pub fn for_role(role: StandardMenuRole) -> Self

Default standard menu for a role.

Source

pub fn role(&self) -> StandardMenuRole

This menu’s role.

Source

pub fn title(self, title: impl Into<LocalizedString>) -> Self

Submenu title (the app name for App; the menu label for Window / Help).

Source

pub fn about(self, label: impl Into<LocalizedString>) -> Self

“About …” label (App).

Source

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.

Source

pub fn hide(self, label: impl Into<LocalizedString>) -> Self

“Hide …” label (App).

Source

pub fn quit(self, label: impl Into<LocalizedString>) -> Self

“Quit …” label (App).

Source

pub fn minimize(self, label: impl Into<LocalizedString>) -> Self

“Minimize” label (Window).

Source

pub fn zoom(self, label: impl Into<LocalizedString>) -> Self

“Zoom” label (Window).

Source

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 ▸ Quit
Source

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.

Source

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")
Source

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.

Source

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.

Source

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.

Source

pub fn quit_shortcut_id(&self) -> Option<&'static str>

The shortcut id named for the Quit row, if any.

Source

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

Source§

fn clone(&self) -> StandardMenu

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

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

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

Convert &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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

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

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more