GPUI Box GitHub

Components / overlay

Popover view

A surface anchored to a trigger, holding whatever the caller puts in it.

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

use gpui_kit::overlay::Popover;

Reviewed in popover.

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(icon: Icon) -> Self
content(content: impl Fn(&mut Window, &mut App) -> AnyElement + 'static) -> Self
placement(placement: Placement) -> Self
hang(hang: Hang) -> Self
dismissable(dismissable: bool) -> Self
Commands

Need a Context, so they need a view.

set_trigger(label: impl Into<SharedString>, cx: &mut Context<Self>)
set_trigger_icon(icon: Option<Icon>, cx: &mut Context<Self>)
set_content(content: Option<Content>, cx: &mut Context<Self>)
set_placement(placement: Placement, cx: &mut Context<Self>)
set_hang(hang: Hang, cx: &mut Context<Self>)
set_dismissable(dismissable: bool, cx: &mut Context<Self>)
open(window: &mut Window, cx: &mut Context<Self>)
close(window: &mut Window, cx: &mut Context<Self>)
toggle(window: &mut Window, cx: &mut Context<Self>)
dismiss(window: &mut Window, cx: &mut Context<Self>)
Queries

Only answer; they change nothing.

is_open() -> bool
is_dismissable() -> bool
Reports

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

  • Opened
  • Dismissed
  • Closed
Example · popover
fn popover(window: &mut Window, cx: &mut App) -> AnyElement {
    ensure_menus(window, cx);
    let popover = cx.global::<SceneMenus>().popover.clone();
    let theme = cx.theme().clone();
    stack(&theme)
        .w(px(520.0))
        .h(px(320.0))
        // The trigger keeps its place while the surface is open, because the
        // surface is anchored to it rather than laid out beside it.
        .child(crate::foundation::text(
            &theme,
            TypeScale::Body,
            "The trigger owns whether the surface is open.",
        ))
        .child(popover)
        .into_any_element()
}

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