Skip to content

Toast

toast · Overlays · interactive

Short-lived messages, stacked in a corner and gone on their own.

Import

cpp
#include "gbui/widgets/toast.hpp"

Example

Nothing is downloaded until you press it.

cpp
ToastResult toast(Ui& ui, const Interaction& input, ToastState& state, float delta, const ToastOptions& options = {});

Draws the stack and advances its timers. delta is the frame's own seconds. Called once per outlet, near the end of the frame — it draws on the overlay layer, so where it sits in the tree decides nothing about where it appears, but building it last keeps it above anything that shares that layer. It never takes the keyboard. A message that stole focus would interrupt whatever the reader was typing, and the live region is what delivers it instead; only the × and the action are Tab stops, and only while they exist.

API

ToastOptions

OptionTypeDefaultWhat it does
placementToastPlacement
TopLeft · TopCenter · TopRight · BottomLeft · BottomCenter · BottomRight · Anchored
ToastPlacement::TopRightWhich corner, edge or anchor the stack sits against. Which way it grows follows from it and is not a second decision.
groupstd::string_viewWhich entries this outlet shows. Empty shows the ungrouped ones.
anchorIdstd::string_viewThe tag ToastPlacement::Anchored measures against.
boundsRectThe rectangle the corners are measured from. Empty is the window. What lets a stack live inside a panel rather than over the whole screen — a docked tool reporting into its own pane rather than across the application it is embedded in.
progressbooltrueA bar draining across the foot of each toast, showing the time left. Drawn only where there is a time left: a toast with no duration has nothing to count down and gets none.
maxVisiblestd::size_t4How many are on screen at once. The rest wait their turn, which is better than a stack taller than the window.
widthfloat340.0f
gapfloat8.0fBetween two toasts in the stack.
marginfloat16.0fBetween the stack and the edge it is anchored to.
namestd::string_view"Notifications"What the region is called. A reader arriving at it out of context is otherwise told only that something changed.

Released under the LGPL-3.0-or-later licence.