Crates.io | egui-toast |
lib.rs | egui-toast |
version | 0.15.0 |
source | src |
created_at | 2022-05-17 12:19:43.790566 |
updated_at | 2024-10-05 09:27:59.641546 |
description | Toast notifications for the egui library |
homepage | https://github.com/urholaukkarinen/egui-toast |
repository | https://github.com/urholaukkarinen/egui-toast |
max_upload_size | |
id | 588303 |
size | 8,544,087 |
Toast notifications for the egui library.
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);
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(),
..Default::default()
});
}
toasts.show(ctx);