Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/urholaukkarinen/egui-toast
Toast notifications for the egui library
https://github.com/urholaukkarinen/egui-toast
Last synced: 7 days ago
JSON representation
Toast notifications for the egui library
- Host: GitHub
- URL: https://github.com/urholaukkarinen/egui-toast
- Owner: urholaukkarinen
- License: mit
- Created: 2022-05-17T08:26:33.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-05T09:27:23.000Z (3 months ago)
- Last Synced: 2024-10-10T20:11:33.477Z (2 months ago)
- Language: Rust
- Homepage: https://urholaukkarinen.github.io/egui-toast/
- Size: 3.82 MB
- Stars: 81
- Watchers: 1
- Forks: 25
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE-MIT
Awesome Lists containing this project
- awesome-egui - egui-toast
README
# egui-toast
[![Latest version](https://img.shields.io/crates/v/egui-toast.svg)](https://crates.io/crates/egui-toast)
[![Documentation](https://docs.rs/egui-toast/badge.svg)](https://docs.rs/egui-toast)
![MIT](https://img.shields.io/badge/license-MIT-blue.svg)Toast notifications for the [egui](https://github.com/emilk/egui) library.
[Try it out in a web demo](https://urholaukkarinen.github.io/egui-toast/)
![Toast types](toasts.png)
## Quick start
```shell
cargo run -p egui-toast-demo
# or in wasm
cd demo && trunk serve
``````rust
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);
```## Customization
Look of the notifications can be fully customized.
```rust
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);
```