Skip to main content

Module menu

Module menu 

Source
Expand description

The menu bar as plain, serializable data: one model for every renderer.

An app builds a MenuSpec from its commands (MenuSpec::from_commands), adds what commands do not say (separators, check marks, OS roles), and hands it to a renderer: ashlar-native turns it into the OS menu bar (macOS, Windows), ashlar-ui draws it in the window (web, Linux, or by choice). Activating an item delivers its id, the command id for items built from commands, which the app runs through its one execute chokepoint.

Renderers that keep live OS menus rebuild them only when MenuSpec::structure_hash changes (items added or removed, menu key equivalents changed) and otherwise patch labels, enabled and checked state in place when MenuSpec::state_hash changes.

The model has no OS or UI types and is bounded: MAX_DEPTH, MAX_NODES, MAX_TEXT (MenuSpec::validate); walks stop at the depth limit instead of recursing without end.

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

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

Path
Where a node sits: indices from the top-level menu down.