Alert
Layer: molecule · Path:
src/molecules/alert.rs· Exports:alert::{Alert, AlertVariant}
A status callout — an inline banner that surfaces a build result, validation outcome, or notice. The variant drives both the leading glyph and an accent color pulled from the active [Theme]. Analogous to the shadcn Alert / Unity Help Box.
Design
-
Purpose / when to use — Communicate a contextual status (info / success / warning / error) inline in a panel. Not a toast; it stays in the layout flow.
-
Anatomy —
Surfacecontainer, paddedSPACE_3→ horizontal row of a statusIcon(accent-colored) + a vertical text stack of an optional accentTexttitle (body_strong) and the muted message body. -
Variants / states
Variant Glyph ( egui_phosphor::light)Theme color Info(default)INFOtheme.infoSuccessCHECK_CIRCLEtheme.successWarningWARNINGtheme.warningErrorWARNING_CIRCLEtheme.error -
Tokens / layout consumed —
core::SPACE_3(surface pad),SPACE_2(icon→text gap),SPACE_1(title→message gap); colors fromTheme. See tokens.
API
| Method | Effect |
|---|---|
Alert::new(message: impl Into<String>) -> Self | Construct with the body message; variant defaults to Info. |
.title(title: impl Into<String>) -> Self | Optional accent-colored title above the message. |
.variant(variant: AlertVariant) -> Self | Set the variant explicitly. |
.info() / .success() / .warning() / .error() -> Self | Sugar for .variant(...). |
.show(self, ui: &mut Ui) -> Response | Render; returns the surface’s Response. |
AlertVariant — Info (default), Success, Warning, Error.
Usage
#![allow(unused)]
fn main() {
use ouroboros_ui::molecules::Alert;
// minimal
Alert::new("Build finished in 2.3s.").show(ui);
}
#![allow(unused)]
fn main() {
use ouroboros_ui::molecules::{Alert, AlertVariant};
// realistic — titled error
Alert::new("Shader failed to compile.")
.title("Notice")
.variant(AlertVariant::Error)
.show(ui);
}
Composition
Composes Surface + Icon + Text only, laid out with ui.horizontal / ui.vertical. It never paints primitives — see the guards.
Notes
- The message is required; the title is optional and renders in the variant accent color.
- Color resolution happens at
showtime viaTheme::get(ui), so alerts re-theme automatically.