Skip to content

Feedback ​

Live demo
Every toast kind, an action with undo, positions, and a loading toast updated in place.Open in a tab ↗

Toasts is a sonner-style notification stack. Keep one in the application state, push toasts from anywhere, and call show once per frame after the panels.

rust
use egui_workbench::components::{Toast, ToastKind, ToastPosition, Toasts};

struct App {
    toasts: Toasts,
    icons: Icons,
}

impl App {
    fn new() -> Self {
        Self {
            // Clear the 24 pt status bar in the bottom-right corner.
            toasts: Toasts::new().offset(0.0, egui_workbench::metrics::STATUS_HEIGHT),
            icons: Icons::new(),
        }
    }
}

Kinds ​

KindIconColor
Info (default)infoLink token
Successcircle checkSuccess token
Warningtriangle alertWarning token
Errorcircle xDanger token
LoadingspinnerMuted text; no timeout until updated
rust
toasts.success("Saved");
toasts.warning("The file changed on disk");
toasts.error("Could not save");
let id = toasts.loading("Exporting…");

Actions and descriptions ​

rust
let id = toasts.add(
    Toast::new(ToastKind::Error, "Could not save")
        .description("Permission denied")
        .action("Retry")
        .duration(8.0),
);

A toast with an action has an Action button on the right. Clicking it reports ToastEvent::Action(id) and closes the toast.

Loading to success ​

loading returns a ToastId. Replace the toast in place; its timer restarts and it keeps its position in the stack:

rust
let id = toasts.loading("Exporting report…");
// ... later, on the worker result:
toasts.update(id, Toast::new(ToastKind::Success, "Exported").description("report.pdf"));

update returns false when the toast is already gone.

Rendering ​

rust
for event in toasts.show(ctx, &mut icons) {
    match event {
        ToastEvent::Action(id) => retry(id),
        ToastEvent::Closed(id) => {}
        ToastEvent::Expired(id) => {}
    }
}
APITypeDefaultDescription
Toasts::new()Toastsbottom-right, 356 pt, 4 visibleAn empty stack.
.position(p)ToastPositionBottomRightCorner or edge center.
.set_position(p)ToastPosition—Change the corner at run time.
.width(pt)f32356.0Minimum 200 pt; shrinks on narrow windows.
.max_visible(n)usize4Older toasts wait in the queue.
.offset(x, y)f32, f320, 0Clear the title bar or status bar.
.add(toast)Toast—Queue a toast and return its id.
.info/success/warning/error(title)&str—Shorthands for the four timed kinds.
.loading(title)&str—Persistent spinner until updated or dismissed.
.update(id, toast)ToastId, Toast—Replace in place; returns false when gone.
.dismiss(id)ToastId—Close with the exit animation.
.dismiss_all()——Close every toast.
.show(ctx, icons)Vec<ToastEvent>—Paint above every panel and report events.

Toast builder ​

MethodDefaultEffect
Toast::new(kind, title)4 s timeoutA notification; Loading has no timeout
.description(text)NoneSecond muted line that wraps
.action(label)NoneAction button
.duration(seconds)4.0Clamped to at least 0.5 s
.persistent()falseKeep until closed or updated
.closable(bool)trueShow or hide the ×

Behavior ​

  • Default timeout is 4 s. Hovering any toast pauses every timer.
  • Enter and exit animations follow reduced motion.
  • Nothing repaints while the stack is empty; while toasts are visible, the frame wakes only for the next timeout or animation step.
  • max_visible queues the rest; they appear as slots free up.
  • The stack never covers the title bar or status bar when .offset is set.

Released under MIT OR Apache-2.0. Icons: Lucide (ISC) and Material Icon Theme (MIT).