Skip to main content

Module menu_bar

Module menu_bar 

Source
Expand description

MenuBar — a horizontal application menu bar with keyboard-driven dropdowns.

MenuBar renders a row of labelled trigger buttons; activating one opens a dropdown MenuList as an overlay. Menus can be added via the fluent .menu(label, factory) API or built from a declarative MenuModel (the single source of truth shared with the native macOS menu bar via from_model + native_on_macos). Leading and trailing slots accept arbitrary widget content (an app icon or a search field, for example).

Keyboard. F10 and bare-Alt-tap focus the first trigger without opening a menu; Alt+letter opens the menu whose label carries a matching mnemonic marker (&File → Alt+F). On macOS the Alt+letter branch is suppressed because the OS rewrites Option+letter for accented character composition — F10 and bare-Alt-tap continue to work. Once a dropdown is open, ArrowLeft and ArrowRight cycle between top-level menus, and Escape closes the active one and returns focus to the trigger.

Hamburger / collapsible mode. Call .collapsible() to let the bar collapse to a single hamburger IconButton when its intrinsic width exceeds the allotted space (CollapsePolicy::Responsive). .collapse_policy(Always) forces the hamburger regardless of width.

§Accessibility

The bar carries Role::MenuBar; each trigger is Role::MenuItem with set_has_popup(Menu) and set_expanded tracking the open dropdown. Mnemonic letters are announced via set_access_key for Windows Narrator.

let _w = MenuBar::new()
    .menu(lit!("File"), || Box::new(
        MenuList::new()
            .item(MenuItem::new(lit!("New")).on_activate_fn(|ctx| ctx.send_intent(Intent::new("app.new"))))
            .separator()
            .item(MenuItem::new(lit!("Quit")).on_activate_fn(|ctx| ctx.send_intent(Intent::new("app.quit"))))
    ))
    .menu(lit!("Edit"), || Box::new(
        MenuList::new()
            .item(MenuItem::new(lit!("Cut")).on_activate_fn(|ctx| ctx.send_intent(Intent::new("app.cut"))))
    ));

Structs§

MenuBar
A horizontal application menu bar with labelled trigger buttons and dropdown menus.

Enums§

CollapsePolicy
Controls when a collapsible MenuBar switches from the full inline bar to the hamburger IconButton representation.