Skip to content

Toast

Toasts live in the window layer stack rather than the application layout tree. Obtain the window-scoped handle and show a message:

auto toast = UseToast();
Button("Save").OnClick([toast] {
toast.Show("Changes saved");
})

ToastHandle::Show accepts StringVariant and ToastOptions; the default duration is two seconds. It returns a LayerId that can be dismissed early with Dismiss.

The captured environment determines theme and localized resources. ToastStyle controls placement, viewport padding, surface, typography, shadow, width, and optional motion. Toasts announce transient status through live-region semantics without taking focus.

  • UseToast() returns ToastHandle for the current window.
  • Show(StringVariant, ToastOptions = {}) -> LayerId.
  • Dismiss(LayerId) -> bool.
  • ToastOptions::duration is measured in seconds.
  • ToastStyle and VerticalPlacement define theme presentation.

See Presentation for layer lifetime and theming.

Each Show creates an independent toast; it does not replace the previous message. Save the returned LayerId only if an event needs to dismiss that specific toast early. Dismiss(id) returns false for a stale identifier. Duration must be finite and nonnegative; zero is an immediate-expiry request, not persistent feedback.

The handle captures the Environment when UseToast() runs. Capture the handle by value in an event and call it on the UI thread. Do not invoke Show directly during composition, where recomposition could emit duplicate notifications.

background, text_style, padding, shadow, and corner_radii describe the message surface. minimum_height and maximum_width bound its geometry; viewport_padding leaves space at safe edges. placement is Top, Center, or Bottom. motion is optional PresentationMotion, with std::nullopt disabling transitions.

Use SnackBar for an action or replacement-style feedback. Do not put essential errors only in an expiring toast; retain them near the affected form or operation as well.