Components / overlay
Menu view
A list of commands, opened from a trigger.
A view survives a frame. Hold it in an Entity with cx.new(..) and reach it with .update(..).
use gpui_kit::overlay::Menu;
Reviewed in menu.
Construct
new(ident: impl Into<Ident>, _window: &mut Window, cx: &mut Context<Self>) -> Self
Options
Chain onto the value.
trigger(label: impl Into<SharedString>) -> Self
trigger_icon(glyph: Icon) -> Self
trigger_name(name: impl Into<SharedString>) -> Self
trigger_variant(variant: ButtonVariant) -> Self
trigger_join(join: ButtonJoin) -> Self
items(items: impl IntoIterator<Item = MenuItem>) -> Self
placement(placement: Placement) -> Self
hang(hang: Hang) -> Self
Commands
Need a Context, so they need a view.
set_trigger_name(name: impl Into<SharedString>, cx: &mut Context<Self>)
set_trigger_style(variant: ButtonVariant, size: ControlSize, cx: &mut Context<Self>)
set_trigger(label: impl Into<SharedString>, cx: &mut Context<Self>)
set_trigger_icon(icon: Option<Icon>, cx: &mut Context<Self>)
set_trigger_join(join: ButtonJoin, cx: &mut Context<Self>)
set_placement(placement: Placement, cx: &mut Context<Self>)
set_hang(hang: Hang, cx: &mut Context<Self>)
set_items(items: Vec<MenuItem>, cx: &mut Context<Self>)
open(window: &mut Window, cx: &mut Context<Self>)
open_submenu(id: &str, window: &mut Window, cx: &mut Context<Self>) -> bool
close(window: &mut Window, cx: &mut Context<Self>)
dismiss(window: &mut Window, cx: &mut Context<Self>)
toggle(window: &mut Window, cx: &mut Context<Self>)
Queries
Only answer; they change nothing.
offered() -> &[MenuItem]
is_open() -> bool
Reports
The variants of the event it emits. It never applies the change itself.
- Opened
- Invoked
- Dismissed
- Closed
Example · menu
fn menu(window: &mut Window, cx: &mut App) -> AnyElement {
ensure_menus(window, cx);
let menus = cx.global::<SceneMenus>();
let menu = menus.menu.clone();
let theme = cx.theme().clone();
stack(&theme)
.w(px(560.0))
.h(px(320.0))
// An open surface is an overlay and takes no room in the flow, so the
// scene reserves the panel's review area explicitly.
.child(div().h(px(300.0)).child(menu))
.into_any_element()
}