toast
Builds DescriptionList List Timeline ToastLayer


The code that drew it
A still frame holds a repeating animation at its first frame and a one-shot at its last, because a still of a moving thing is not reproducible. Run the gallery to review motion.
fn toast(_window: &mut Window, cx: &mut App) -> AnyElement {
if !cx.has_global::<SceneToasts>() {
let layer = cx.new(|cx| ToastLayer::new(cx).capacity(4));
cx.set_global(SceneToasts { layer });
toast_push(
cx,
Toast::new("scene.toast.saved", "Theme exported to disk").tone(Tone::Success),
);
toast_push(
cx,
Toast::new("scene.toast.stale", "Refreshing the model catalog failed")
.tone(Tone::Warning)
.detail("The last verified catalog is still shown."),
);
toast_push(
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(
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(div().child("Content behind the notifications"))
// A failure keeps its report on screen; only the success times out.
.child(div().child("A danger or warning toast stays until it is dismissed."))
.child(layer)
.into_any_element()
}