18 个版本 (重大变更)

0.14.0 2024 年 7 月 14 日
0.12.1 2024 年 2 月 13 日
0.10.1 2023 年 12 月 12 日
0.10.0 2023 年 11 月 25 日
0.2.0 2022 年 5 月 18 日

#84 in GUI

Download history 142/week @ 2024-05-04 163/week @ 2024-05-11 477/week @ 2024-05-18 349/week @ 2024-05-25 514/week @ 2024-06-01 552/week @ 2024-06-08 369/week @ 2024-06-15 475/week @ 2024-06-22 367/week @ 2024-06-29 371/week @ 2024-07-06 340/week @ 2024-07-13 293/week @ 2024-07-20 525/week @ 2024-07-27 476/week @ 2024-08-03 846/week @ 2024-08-10 409/week @ 2024-08-17

2,324 每月下载量
用于 6 个 crate (2 直接)

MIT 许可证

2.5MB
307

egui-toast

Latest version Documentation MIT

egui 库提供的 Toast 通知。

在网页演示中尝试

Toast types

快速开始

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),
        ..Default::default()
    });
}

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

自定义

通知的外观可以完全自定义。

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(),
        ..Default::default()
    });
}

toasts.show(ctx);

依赖

~4.5–9.5MB
~82K SLoC