17 releases (breaking)

0.13.0 Apr 5, 2024
0.12.1 Feb 13, 2024
0.11.0 Jan 16, 2024
0.10.1 Dec 12, 2023
0.2.0 May 18, 2022

#90 in GUI

Download history 828/week @ 2024-01-22 451/week @ 2024-01-29 575/week @ 2024-02-05 363/week @ 2024-02-12 634/week @ 2024-02-19 481/week @ 2024-02-26 381/week @ 2024-03-04 719/week @ 2024-03-11 702/week @ 2024-03-18 438/week @ 2024-03-25 958/week @ 2024-04-01 333/week @ 2024-04-08 275/week @ 2024-04-15 395/week @ 2024-04-22 259/week @ 2024-04-29 128/week @ 2024-05-06

1,069 downloads per month
Used in 4 crates (2 directly)

MIT license

2.5MB
273 lines

egui-toast

Latest version Documentation MIT

Toast notifications for the egui library.

Try it out in a web demo

Toast types

Quick start

cargo run -p egui-toast-demo
# or in wasm
cd demo && trunk serve
let mut toasts = Toasts::new()
    .anchor(Align2::RIGHT_BOTTOM, (-10.0, -10.0)) // 10 units from the bottom right corner
    .direction(egui::Direction::BottomUp);

if ui.button("Add toast").clicked() {
    toasts.add(Toast {
        text: "Hello, World!".into(),
        kind: ToastKind::Error,
        options: ToastOptions::default()
            .duration_in_seconds(5.0)
            .show_progress(true)
    });
}

// Show and update all toasts
toasts.show(ctx);

Customization

Look of the notifications can be fully customized.

const MY_CUSTOM_TOAST: u32 = 0;

fn my_custom_toast_contents(ui: &mut Ui, toast: &mut Toast) -> Response {
    egui::Frame::default()
        .fill(Color32::from_rgb(33, 150, 243))
        .inner_margin(Margin::same(12.0))
        .rounding(4.0)
        .show(ui, |ui| {
            ui.label(toast.text.clone().color(Color32::WHITE));

            if ui.button("Close me").clicked() {
                toast.close();
            }
        }).response
}

let mut toasts = Toasts::new()
    .custom_contents(MY_CUSTOM_TOAST, my_custom_toast_contents);

if ui.button("Add toast").clicked() {
    toasts.add(Toast {
        text: "Hello, World!".into(),
        kind: ToastKind::Custom(MY_CUSTOM_TOAST),
        options: ToastOptions::default()
    });
}

toasts.show(ctx);

Dependencies

~4.5–9.5MB
~80K SLoC