Components / overlay
ToastLayer view
The stack of notifications for one window.
A view survives a frame. Hold it in an Entity with cx.new(..) and reach it with .update(..).
use gpui_kit::overlay::ToastLayer;
Reviewed in toast.
Construct
new(window: &Window, cx: &mut Context<Self>) -> Self
Options
Chain onto the value.
corner(corner: ToastCorner) -> Self
capacity(capacity: usize) -> Self
reserved_edges(edges: impl Into<Edges<Pixels>>) -> Self
Commands
Need a Context, so they need a view.
set_corner(corner: ToastCorner, cx: &mut Context<Self>)
set_capacity(capacity: usize, cx: &mut Context<Self>)
set_reserved_edges(edges: impl Into<Edges<Pixels>>, cx: &mut Context<Self>)
push(toast: Toast, cx: &mut Context<Self>)
dismiss(ident: &str, cx: &mut Context<Self>) -> bool
clear(cx: &mut Context<Self>)
Queries
Only answer; they change nothing.
len() -> usize
is_empty() -> bool
phase(ident: &str) -> Option<Phase>
Example · toast
fn toast(window: &mut Window, cx: &mut App) -> AnyElement {
if !cx.has_global::<SceneToasts>() {
let layer = cx.new(|cx| ToastLayer::new(window, cx).capacity(4));
cx.set_global(SceneToasts { layer });
toast_push(
window,
cx,
Toast::new("scene.toast.saved", "Theme exported to disk").tone(Tone::Success),
);
toast_push(
window,
cx,
Toast::new("scene.toast.stale", "Refreshing the model catalog failed")
.tone(Tone::Warning)
.detail("The last verified catalog is still shown."),
);
toast_push(
window,
cx,
// A refusal, so the offer is the thing that could change the
// answer. Retrying an unapproved call only gets refused again.
Toast::new(
"scene.toast.refused",
"The host refused to publish this run",
)
.tone(Tone::Warning)
.detail("Approval is required for this workspace.")
.action("Request approval", |_, _| {}),
);
// The failure beside the refusal, so the two tones are on screen
// together and the difference between them is a picture rather than a
// claim.
toast_push(
window,
cx,
Toast::new("scene.toast.failed", "Publishing this run failed")
.tone(Tone::Danger)
.detail("The publish service did not respond.")
.action("Try again", |_, _| {}),
);
}
let layer = cx.global::<SceneToasts>().layer.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 notifications",
))
// A failure keeps its report on screen; only the success times out.
.child(crate::foundation::text(
&theme,
TypeScale::Body,
"A danger or warning toast stays until it is dismissed.",
))
.child(layer)
.into_any_element()
}