Skip to main content

Module native_menu

Module native_menu 

Source
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 dataNativeMenuSnapshot is a plain, already-resolved description of the whole tree (display strings, key equivalents, enabled / check state, stable MenuItemIds). It carries no widgets, signals, or localized strings — the widget layer resolves all of that before handing a snapshot down, so teksilo-platform never depends on teksilo-widgets.
  • Trait surfaceNativeMenuBackend is the swappable platform abstraction (macOS NSMenu; NoopNativeMenuBackend elsewhere).
  • HandleNativeMenuHandle is the per-app service registered in app-state. It owns the backend and, per window, the map from MenuItemId to 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§

MemoryNativeMenuBackend
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.
MenuItemDelta
A reactive change to a single already-installed native item, applied without rebuilding the whole menu. Each Some field replaces that property.
NativeKeyEquivalent
A platform-neutral key equivalent for a native menu item. Already resolved from the app’s ShortcutRegistry by the widget layer. key is the base character the OS menu expects (e.g. "s", "\r"); the booleans are the modifier flags. An item with an empty key displays no shortcut.
NativeMenuActivation
Rc), so the router can pull a copy out of the handle and run it.
NativeMenuEventPayload
Boxed inside AppEvent::External when the user picks a native menu item. teksilo-app downcasts to this and routes the MenuItemId back to the originating window’s tree.
NativeMenuHandle
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.
NativeMenuSnapshot
A complete, resolved description of one window’s menu tree.
NoopNativeMenuBackend
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 MenuBar remains the menu surface there.
StandardLabels
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.
StandardRoutedItem
A row inside a platform-standard menu that the app routes rather than the platform selects — Quit and Settings today.

Enums§

NativeCheck
On/off/mixed state for a checkable native menu item.
NativeMenuNode
One node of a native menu tree.
StandardMenuRole
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 MenuBar ignores these.

Traits§

NativeMenuBackend
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 NSMenu backend, every other target gets NoopNativeMenuBackend.

Type Aliases§

MenuActionFn
What to do when a native menu item is chosen. Cloneable (the action is an A menu item’s direct activation closure.