Toast
Shows a short message at an edge of the window for a few seconds: the bottom right, or where set_toast_position puts it.
ui.toastBasic
if ui.button("Show toast").outline().clicked() { ui.toast("Saved").success();}Tone and description
if ui.button("Show error").outline().clicked() { ui.toast("Upload failed") .description("Check your connection and try again.") .danger();}Several at once
// Each has a key of its own, so a new one joins the stack. Point at the stack to open it.if ui.button("Add toast").outline().clicked() { self.toasts += 1; let toast = ui.toast(format_args!("Message {}", self.toasts)); toast.description("Point at the stack to open it.").key(self.toasts);}With an action
if ui.button("Delete note").outline().clicked() { ui.toast("Note deleted").action("Undo", Command::Undo);}// True once, in the frame the toast's button is pressed.if ui.action(Command::Undo) { ui.toast("Note restored").success();}Position
ui.grid_cols(3).gap(8).children(|ui| { for (name, position) in [ ("Top left", ToastPosition::TopLeft), ("Top center", ToastPosition::TopCenter), ("Top right", ToastPosition::TopRight), ("Bottom left", ToastPosition::BottomLeft), ("Bottom center", ToastPosition::BottomCenter), ("Bottom right", ToastPosition::BottomRight), ] { if ui.button(name).outline().w_fill().clicked() { // For this toast and the ones after it. ui.set_toast_position(position); ui.toast(name); } }});Stays until closed
ui.row().gap(8).children(|ui| { if ui.button("Start").outline().clicked() { // The key names the toast, to update or close it later. ui.toast("Exporting…").key("export").persistent(); } if ui.button("Finish").outline().clicked() { ui.close_toast("export"); }});API reference
| Setting | Description |
|---|---|
.description(text: impl Display) | A second line in smaller muted text. |
.tone(tone: Tone) | Sets the tone: the icon's color, and the icon itself unless one is set. |
.primary() | The accent color. |
.success() | The success color. |
.warning() | The warning color. |
.danger() | The danger color. Screen readers announce the toast at once. |
.icon(icon: IconName) | The icon before the text. |
.action(label: impl Display, action: A) | Adds a button, such as Undo, that triggers action and closes the toast. |
.key(key: impl Hash) | Identifies the toast by key instead of its text. |
.duration(duration: Duration) | How long the toast shows: 4 seconds by default, 8 with an action. |
.persistent() | Keeps the toast until its close button or Ui::close_toast closes it. |