Expand description
Native (OS) menu service.
Mirrors a logical menu tree (the teksilo-widgets MenuModel) into the
platform’s native menu surface — the global menu bar at the top of the
screen on macOS (NSApplication.mainMenu), and, in the future, an HMENU
on Windows or a DBus app-menu on Linux. A serious desktop app is expected to
present its menus this way on macOS; an in-window menu strip alone reads as
non-native.
Three concerns are separated, mirroring crate::file_dialog and
crate::external_dnd:
- Boundary data —
NativeMenuSnapshotis a plain, already-resolved description of the whole tree (display strings, key equivalents, enabled / check state, stableMenuItemIds). It carries no widgets, signals, or localized strings — the widget layer resolves all of that before handing a snapshot down, soteksilo-platformnever depends onteksilo-widgets. - Trait surface —
NativeMenuBackendis the swappable platform abstraction (macOSNSMenu;NoopNativeMenuBackendelsewhere). - Handle —
NativeMenuHandleis the per-app service registered in app-state. It owns the backend and, per window, the map fromMenuItemIdto the action to run when that item is chosen.
§Activation routing
When the user picks a native menu item, the backend posts a
NativeMenuEventPayload through teksilo_core::AppEventPoster::post_external.
teksilo-app picks it up in its AppEvent::External arm, looks the
MenuItemId up in the NativeMenuHandle, and fires the item’s intent /
action inside the originating window’s EventContext — the same
Action/Intent pipeline an in-window MenuItem uses.
§Multi-window
On macOS there is exactly one global menu bar; it must reflect the focused
window. Each window registers its snapshot via NativeMenuHandle::set_window_menu;
teksilo-app calls NativeMenuHandle::activate_window on focus change so
the focused window’s menu becomes mainMenu. Single-window apps work with
set-on-build alone.
Structs§
- Memory
Native Menu Backend - Recording backend for headless tests. Captures the snapshot set per window,
which window is active, item deltas, and cleared windows. Cloneable; clones
share the recording so a test can keep a clone after handing one to
NativeMenuHandle::new. - Menu
Item Delta - A reactive change to a single already-installed native item, applied without
rebuilding the whole menu. Each
Somefield replaces that property. - Native
KeyEquivalent - A platform-neutral key equivalent for a native menu item. Already resolved
from the app’s
ShortcutRegistryby the widget layer.keyis the base character the OS menu expects (e.g."s","\r"); the booleans are the modifier flags. An item with an emptykeydisplays no shortcut. - Native
Menu Activation Rc), so the router can pull a copy out of the handle and run it.- Native
Menu Event Payload - Boxed inside
AppEvent::Externalwhen the user picks a native menu item.teksilo-appdowncasts to this and routes theMenuItemIdback to the originating window’s tree. - Native
Menu Handle - Per-app native-menu service. Registered in app-state by
TeksiloAppBuilder::install_native_menu(or.app_state(NativeMenuHandle::new(..))for a custom backend). Cloneable; clones share one backend + activation map. - Native
Menu Snapshot - A complete, resolved description of one window’s menu tree.
- Noop
Native Menu Backend - Backend that renders nothing. Used on platforms without a native-menu
implementation (everything except macOS today) so cross-platform code that
installs a native menu compiles and runs — the in-window
MenuBarremains the menu surface there. - Standard
Labels - Display strings for a
StandardMenuRole, already localized by the widget layer. The platform layer never hardcodes user-visible menu text — it applies whatever the snapshot carries — so a standard menu honours the app’s locale (e.g. “Quitter” / “Masquer” on a French system) instead of leaking English literals onto the most visible native surface. - Standard
Routed Item - A row inside a platform-standard menu that the app routes rather than the platform selects — Quit and Settings today.
Enums§
- Native
Check - On/off/mixed state for a checkable native menu item.
- Native
Menu Node - One node of a native menu tree.
- Standard
Menu Role - Standard, platform-defined menus with required placement/behaviour (the
macOS App / Window / Help menus, with their About / Hide / Quit /
window-management items wired to system selectors). The backend supplies the
native structure; the in-window
MenuBarignores these.
Traits§
- Native
Menu Backend - Swappable native-menu backend. One instance serves the whole app.
Functions§
- default_
backend - The default native-menu backend for the current target: macOS gets the real
NSMenubackend, every other target getsNoopNativeMenuBackend.
Type Aliases§
- Menu
Action Fn - What to do when a native menu item is chosen. Cloneable (the action is an A menu item’s direct activation closure.