Skip to main content

Module menu

Module menu 

Source
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.
MenuSpec
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).
NativeMenuBar
No native menu bar on this platform: every call reports Unsupported (draw the spec in the window instead).
Submenu

Enums§

MenuNode
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).
SubmenuRole
What a submenu is to the OS.
Update
What NativeMenuBar::update did.

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_acceleratorDeprecated
Deprecated: use ashlar_command::menu::menu_chord.
menu_chord
The menu key equivalent of portable shortcut text: None when 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§

AcceleratorDeprecated
Deprecated: accelerators are Chords (Chord::parse, Chord::is_menu_safe, Chord::portable).
ModifiersDeprecated
Deprecated: modifiers are Mods (command is Mod).
Path
Where a node sits: indices from the top-level menu down.