GPUI Box GitHub

Components / overlay

Menubar view

A row of menus, at most one of them open.

A view survives a frame. Hold it in an Entity with cx.new(..) and reach it with .update(..).

use gpui_kit::overlay::Menubar;

Reviewed in menubar.

Construct
new(ident: impl Into<Ident>, menus: impl IntoIterator<Item = MenubarMenu>, window: &mut Window, cx: &mut Context<Self>) -> Self
Options

Chain onto the value.

control_size(size: ControlSize) -> Self
Commands

Need a Context, so they need a view.

set_menus(menus: Vec<MenubarMenu>, window: &mut Window, cx: &mut Context<Self>)
set_control_size(size: ControlSize, cx: &mut Context<Self>)
open(id: &str, window: &mut Window, cx: &mut Context<Self>)
close(window: &mut Window, cx: &mut Context<Self>)
Queries

Only answer; they change nothing.

open_menu() -> Option<&SharedString>
menus() -> &[MenubarMenu]
Reports

The variants of the event it emits. It never applies the change itself.

  • Opened
  • Invoked
  • Closed
Example · menubar
fn menubar(window: &mut Window, cx: &mut App) -> AnyElement {
    ensure_ordinary(window, cx);
    let bar = cx.global::<SceneOrdinary>().menubar.clone();
    let theme = cx.theme().clone();
    stack(&theme)
        .w(px(560.0))
        .h(px(360.0))
        .child(bar)
        .into_any_element()
}

Source: crates/gpui-kit/src/overlay/menubar.rs