Components / overlay
ContextMenu view
The same menu, opened at the pointer over a region rather than 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::ContextMenu;
Reviewed in context-menu.
Construct
new(ident: impl Into<Ident>, window: &mut Window, cx: &mut Context<Self>) -> Self
Options
Chain onto the value.
menu(items: impl IntoIterator<Item = MenuItem>) -> Self
presentation(presentation: ContextMenuPresentation) -> Self
name(name: impl Into<SharedString>) -> Self
target(target: impl Into<SharedString>) -> Self
content(content: impl Fn(&mut Window, &mut App) -> AnyElement + 'static) -> Self
Commands
Need a Context, so they need a view.
set_name(name: impl Into<SharedString>, window: &mut Window, cx: &mut Context<Self>) -> Result<(), NativeMenuError>
set_presentation(presentation: ContextMenuPresentation, window: &mut Window, cx: &mut Context<Self>) -> Result<(), NativeMenuError>
set_target(target: Option<SharedString>, window: &mut Window, cx: &mut Context<Self>) -> Result<(), NativeMenuError>
set_content(content: Option<Content>, window: &mut Window, cx: &mut Context<Self>) -> Result<(), NativeMenuError>
set_items(items: Vec<MenuItem>, window: &mut Window, cx: &mut Context<Self>) -> Result<(), NativeMenuError>
open_at(position: Point<Pixels>, window: &mut Window, cx: &mut Context<Self>) -> Result<(), NativeMenuError>
close(window: &mut Window, cx: &mut Context<Self>) -> Result<(), NativeMenuError>
dismiss(window: &mut Window, cx: &mut Context<Self>) -> Result<(), NativeMenuError>
Queries
Only answer; they change nothing.
is_open() -> bool
position() -> Point<Pixels>
Reports
The variants of the event it emits. It never applies the change itself.
- Opened
- Invoked
- Dismissed
- Closed
- Unavailable
Example · context-menu
fn context_menu(window: &mut Window, cx: &mut App) -> AnyElement {
ensure_menus(window, cx);
let context = cx.global::<SceneMenus>().context.clone();
let theme = cx.theme().clone();
stack(&theme)
.w(px(560.0))
.h(px(400.0))
// Opening a context menu reports the row that was pointed at; what is
// selected stays the host's answer.
.child(crate::foundation::text(
&theme,
TypeScale::Body,
"The right-click reports the row. Nothing is selected by it.",
))
.child(context)
.into_any_element()
}