GPUI Box GitHub

Components / overlay

HoverCard view

A preview surface that opens on hover and can be pointed at.

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

use gpui_kit::overlay::HoverCard;

Reviewed in hover-card.

Construct
new(ident: impl Into<Ident>, _window: &mut Window, cx: &mut Context<Self>) -> Self
Options

Chain onto the value.

trigger(trigger: impl Fn(&mut Window, &mut App) -> AnyElement + 'static) -> Self
name(name: impl Into<SharedString>) -> Self
content(content: impl Fn(&mut Window, &mut App) -> AnyElement + 'static) -> Self
placement(placement: Placement) -> Self
hang(hang: Hang) -> Self
open_delay(delay: Duration) -> Self
grace(grace: Duration) -> Self
Commands

Need a Context, so they need a view.

set_name(name: Option<SharedString>, cx: &mut Context<Self>)
set_trigger(trigger: Option<Content>, 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_open_delay(delay: Duration, cx: &mut Context<Self>)
set_grace(grace: Duration, cx: &mut Context<Self>)
open(cx: &mut Context<Self>)
close(cx: &mut Context<Self>)
dismiss(window: &mut Window, cx: &mut Context<Self>)
Queries

Only answer; they change nothing.

is_open() -> bool
is_leaving() -> bool
grace_period() -> Duration
Reports

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

  • Opened
  • Closed
Example · hover-card
fn hover_card(window: &mut Window, cx: &mut App) -> AnyElement {
    ensure_ordinary(window, cx);
    let card = cx.global::<SceneOrdinary>().hover_card.clone();
    let theme = cx.theme().clone();
    stack(&theme)
        .w(px(460.0))
        .h(px(300.0))
        .child(caption(&theme, "A preview the pointer can travel into"))
        .child(
            row(&theme)
                .child(crate::foundation::text(
                    &theme,
                    TypeScale::Label,
                    "Reported by",
                ))
                .child(card),
        )
        .into_any_element()
}

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