Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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.

  • AnatomySurface container, padded SPACE_3 → horizontal row of a status Icon (accent-colored) + a vertical text stack of an optional accent Text title (body_strong) and the muted message body.

  • Variants / states

    VariantGlyph (egui_phosphor::light)Theme color
    Info (default)INFOtheme.info
    SuccessCHECK_CIRCLEtheme.success
    WarningWARNINGtheme.warning
    ErrorWARNING_CIRCLEtheme.error
  • Tokens / layout consumedcore::SPACE_3 (surface pad), SPACE_2 (icon→text gap), SPACE_1 (title→message gap); colors from Theme. See tokens.

API

MethodEffect
Alert::new(message: impl Into<String>) -> SelfConstruct with the body message; variant defaults to Info.
.title(title: impl Into<String>) -> SelfOptional accent-colored title above the message.
.variant(variant: AlertVariant) -> SelfSet the variant explicitly.
.info() / .success() / .warning() / .error() -> SelfSugar for .variant(...).
.show(self, ui: &mut Ui) -> ResponseRender; returns the surface’s Response.

AlertVariantInfo (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 show time via Theme::get(ui), so alerts re-theme automatically.