Skip to main content

Module menubar

Module menubar 

Source
Expand description

Menubar — the in-window bar: a strip of titles that drop menus.

Not the native one. On macOS that is cx.set_menus and four lines in an app’s main, which is where it belongs; this is the bar an app with a custom titlebar draws for itself, and the one every other platform expects to see inside the window.

An entity, on the line crate::date::Calendar drew: it owns which menu is down and where the keyboard is inside it — state the app has no opinion about — and reports the one thing the app wants, through MenubarEvent. The menus are data the app hands over, shaped like gpui’s own Menu and MenuItem so an app drawing both bars writes them the same way. It does not take those types: they carry a boxed action, and reporting an index leaves dispatch with the app, the way crate::combobox and crate::palette already do.

What makes it a menubar rather than a row of dropdowns is that one menu being open changes what the others do: sliding the pointer onto a sibling title switches to it with no click, and left/right cross between menus without leaving the keyboard.

ui::menubar::init(cx);   // once, at startup
let bar = cx.new(|cx| Menubar::new(vec![
    Menu::new("File", vec![
        Item::action("New Window").with_shortcut(&NewWindow, window),
        Item::submenu("Open Recent", vec![Item::action("bezel.md")]),
        Item::Separator,
        Item::action("Close").with_keystroke(keys::printed("secondary-w")).disabled(),
    ]),
], cx));
cx.subscribe(&bar, |_, bar, event, cx| match event {
    MenubarEvent::Selected { menu, path } => { /* dispatch */ }
})
.detach();

Structs§

Confirm
Dismiss
Menu
One menu on the bar.
Menubar
NextItem
NextMenu
PrevItem
PrevMenu

Enums§

MenubarEvent
What the bar reports: an item chosen, by its place in the menus it was given.

Constants§

KEY_CONTEXT
The key context the bar claims, closed as well as open — enter on a focused-but-closed bar drops its first menu.

Functions§

bindings
The bar’s keymap, as data, so an app can have it without having to take it — see crate::keys for layering over it or taking a chord away.
init
Install the bindings — bindings, bound. Call once, alongside crate::input::init.
menubar
The strip the titles sit on.
menubar_title
One title on the strip. Lit while its own menu is down.