Expand description
Toasts, as a plugin (ToastsPlugin, in DefaultPlugins): short
notices in a corner that never take the focus, each with a level, an
optional action (a command, run through the host) and a close button.
Information and success go after a few seconds, warnings after
longer, errors stay until closed; a thin bar empties as the time
runs, and stops while the pointer is over the toast. Screen readers
hear them through the live region (errors at once).
They show in a corner of the window, or the middle of its top or
bottom edge (the appearance.toast_corner setting, Corner;
AppBuilder::toast_corner gives its default), the newest the nearest
to the edge. They slide in from the corner’s side and out again in
motion.toast.slide (fade in the middle of an edge); under reduced
motion they appear and go at once, and the bar steps once a second.
They cast the shadow of what lies over the interface
(toast.shadow-*, aliases of shadow.popup.*).
They keep off what an interface asks them to (keep_clear): the
Settings app’s wizard footer, whose Finish sits in the default corner,
is never under a toast that would take its click.
Each application window has its own toasts (ADR 0025): a toast
belongs to the window it was raised from (the application window being
drawn, or the one whose command raised it, else the active one;
Toasts::notify_in names one), and each window stacks its own, up
to SHOWN at a time. In the main window’s group they show in the
window of it the user works in (AppHandle::active_window): a
detached panel’s window while it has the focus, the main window again
when that one closes. A closed application window’s toasts go to the
main window.
The queue is data: Toasts::shown and Toasts::history, the
debug bridge’s toasts collector (with dismiss), and a
toast.shown event in the journal.
Owned: egui-notify and egui-toast (both MIT) keep a queue of strings,
with no command actions and no state another plugin or an agent can
read; their stacking ideas are reused. From egui-notify (MIT,
https://github.com/ItsEthra/egui-notify) come the slide with its
appear, idle and disappear states and its eased value (toast.rs,
lib.rs), the time-left bar that stops under the pointer (lib.rs),
the choice of corner (anchor.rs), the newest nearest the edge (its
reverse, lib.rs) and a shadow under each toast (lib.rs); the
code is egui-pop’s own.
use egui_pop_api::toasts::{self, Toast};
use egui_pop_api::App;
use egui_pop_model::ids::CommandId;
let app = App::builder()
.plugin(toasts::ToastsPlugin)
.build(&egui::Context::default())
.unwrap();
let t = app.handle().service(&toasts::TOASTS).unwrap();
t.notify(Toast::success("Exported 3 images")
.action("Show", CommandId::from_static("files.reveal"), serde_json::json!({ "path": "out" })));
assert_eq!(t.shown().len(), 1);Structs§
- Shown
- A toast in the queue.
- Toast
- A notice.
- Toast
Action - A command offered with a toast.
- Toasts
- The queue of toasts.
- Toasts
Plugin - The plugin.
Enums§
- Corner
- Where the toasts show: a corner of the window, or the middle of its top or bottom edge. The newest is always the nearest to the edge: at the top under a top corner, at the bottom under a bottom one.
- Level
- How much a toast matters.
- Phase
- Where a toast is in its slide.
Constants§
- HISTORY
- How many past toasts are kept.
- SETTING_
CORNER - The setting: where the toasts show (
Corner’s choices). - SHOWN
- How many toasts show at once (the others wait).
- TOASTS
- The toasts, as a service.
Functions§
- corner
- Where the toasts show, as the setting says now.
- keep_
clear - Keeps the toasts off
rect(in the window’s points) for this frame: a row of buttons a toast would cover and take the clicks of, as a wizard’s footer. Toasts whose column meets it move past it: above it under a bottom corner, below it under a top one. Called each frame the rect is shown; it lapses the frame after it is not.