Components / overlay
Dialog view
A composed modal: scrim, focus trap, title, body, and up to two actions.
A view survives a frame. Hold it in an Entity with cx.new(..) and reach it with .update(..).
use gpui_kit::overlay::Dialog;
Reviewed in dialog.
Construct
new(ident: impl Into<Ident>, _window: &mut Window, cx: &mut Context<Self>) -> Self
Options
Chain onto the value.
title(title: impl Into<SharedString>) -> Self
description(description: impl Into<SharedString>) -> Self
content(body: impl Fn(&mut Window, &mut App) -> AnyElement + 'static) -> Self
dismissable(dismissable: bool) -> Self
destructive(destructive: bool) -> Self
confirm_label(label: impl Into<SharedString>) -> Self
cancel_label(label: impl Into<SharedString>) -> Self
Commands
Need a Context, so they need a view.
set_title(title: impl Into<SharedString>, cx: &mut Context<Self>)
set_description(description: Option<SharedString>, cx: &mut Context<Self>)
set_content(content: Option<Body>, cx: &mut Context<Self>)
set_confirm_label(label: Option<SharedString>, cx: &mut Context<Self>)
set_cancel_label(label: Option<SharedString>, cx: &mut Context<Self>)
set_dismissable(dismissable: bool, cx: &mut Context<Self>)
set_destructive(destructive: bool, cx: &mut Context<Self>)
open(window: &mut Window, cx: &mut Context<Self>)
close(window: &mut Window, cx: &mut Context<Self>)
confirm(window: &mut Window, cx: &mut Context<Self>)
cancel(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
- Confirmed
- Cancelled
- Dismissed
- Closed
Example · dialog
fn dialog(window: &mut Window, cx: &mut App) -> AnyElement {
if !cx.has_global::<SceneDialog>() {
let replace = cx.new(|cx| {
Dialog::new("scene.dialog.replace", window, cx)
.title("Replace the existing theme?")
.description(
"The application owns this decision. The dialog presents it and reports what \
was chosen.",
)
.cancel_label("Cancel")
.confirm_label("Replace")
});
replace.update(cx, |dialog, cx| dialog.open(window, cx));
cx.set_global(SceneDialog { replace });
}
let replace = cx.global::<SceneDialog>().replace.clone();
let theme = cx.theme().clone();
stack(&theme)
.w(px(560.0))
.h(px(360.0))
.child(crate::foundation::text(
&theme,
TypeScale::Body,
"Content behind the dialog",
))
.child(replace)
.into_any_element()
}