Expand description
A native menu bar described by a plain, serializable MenuSpec.
The model lives in ashlar_command::menu (one model for every renderer; ashlar-ui draws
the same spec in the window). Its types are re-exported here so ashlar_native::menu::MenuSpec
keeps working; new code may use either path.
The app builds the spec from its state every frame (cheap: plain data), and
NativeMenuBar::update turns it into the OS menu: it rebuilds only when
MenuSpec::structure_hash changes (items added or removed, accelerators changed) and
otherwise pushes label / enabled / checked changes in place, only when
MenuSpec::state_hash changes. Activations arrive as item ids on a channel, with a
crate::Waker call so an idle app wakes up.
The spec has no OS or UI types, builds everywhere (the web uses an in-window menu bar drawn
from the same spec) and is tested without creating real menus. The native bar exists on macOS
(the app’s menu bar) and Windows (a window’s menu bar, see NativeMenuBar::attach_window);
elsewhere NativeMenuBar::install returns Unsupported.
Structs§
- Item
- A clickable item. Activating it delivers
id. - Menu
Spec - 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).
- Native
Menu Bar - No native menu bar on this platform: every call reports
Unsupported(draw the spec in the window instead). - Submenu
Enums§
- Menu
Node - One node of the menu tree.
- Role
- Items the OS performs itself (no command dispatch). Edit roles (
Undo…SelectAll) go to the OS’s focused native control (a web view, a native text field); apps that draw their own text fields use plain items for those instead. Renderers leave out roles their platform lacks (an in-window menu bar draws none). - Submenu
Role - What a submenu is to the OS.
- Update
- What
NativeMenuBar::updatedid.
Constants§
- MAX_
DEPTH - Deepest submenu nesting accepted (the top-level menu counts as 1).
- MAX_
NODES - Most nodes in one menu bar.
- MAX_
TEXT - Longest label or id.
Functions§
- menu_
accelerator Deprecated - Deprecated: use
ashlar_command::menu::menu_chord. - menu_
chord - The menu key equivalent of portable shortcut text:
Nonewhen it does not parse or is not menu-safe (Chord::is_menu_safe). Of alternatives (Mod+Y / Mod+Shift+Z) the first counts.
Type Aliases§
- Accelerator
Deprecated - Deprecated: accelerators are
Chords (Chord::parse,Chord::is_menu_safe,Chord::portable). - Modifiers
Deprecated - Deprecated: modifiers are
Mods(commandisMod). - Path
- Where a node sits: indices from the top-level menu down.