limn
    ↑↓ ChooseEnter OpenEsc Close
    GitHub

    Components/Overlays

    Toast

    A brief card in the bottom right corner of the window that announces something that happened: a save, a copy, a failure.

    Native componentGuide source

    Preview

    CodeSource
    fn view(state: &State, palette: ComponentPalette) -> Element {
        let root = window_content(state, palette);
        let toasts = state
            .saved
            .then(|| Toast::new("Changes saved", palette).description("notes.md").render())
            .into_iter()
            .collect();
        Toast::layer(root, toasts, 16.0)
    }

    Toast

    A brief card in the bottom right corner of the window that announces something that happened: a save, a copy, a failure.

    Import

    use limn::{AlertTone, Component, Toast};

    Usage

    Toasts are laid over the window’s root element with Toast::layer, built last, around everything else. A toast has no timer: the host decides when it appears and leaves it out of the list when it should go.

    fn view(state: &State, palette: ComponentPalette) -> Element {
        let root = window_content(state, palette);
        let toasts = state
            .saved
            .then(|| Toast::new("Changes saved", palette).description("notes.md").render())
            .into_iter()
            .collect();
        Toast::layer(root, toasts, 16.0)
    }

    Toast::layer(base, toasts, bottom_inset) stacks the cards upward from the bottom right corner, bottom_inset above the window’s lower edge. Everything outside the cards stays interactive, and with no toasts it returns the base alone. A card never takes keyboard focus.

    Description and tone

    Toast::new("Offline", palette)
        .description("Retrying in a few seconds.")
        .tone(AlertTone::Error)
        .render()

    The description is a muted second line. The tone colors the title: Neutral unless set, or Info, Success, Warning, Error. The surface stays neutral. Long copy wraps and the card grows; it is never cut.

    Dismiss and action

    Toast::new("Turn finished", palette)
        .action("turn:open")
        .dismissible("turn:dismiss")
        .render()

    dismissible(id) adds a close button and action(id) makes the card’s copy one click target. Both only report: the host removes the toast.

    Width

    width is 360 unless set and never under 120.

    Motion

    A card fades in and settles when it appears, and fades out where it was once the host drops it; see Animation. With reduced motion it appears and goes at once. A card is known between frames by its title, so two cards shown together with the same title need an ID each to appear and leave apart:

    Toast::new("Saved", palette).id("saved:notes.md").render()

    Actions

    ActionWhen
    UiAction::Clicked { id } with the action IDThe card’s copy is clicked.
    UiAction::Clicked { id } with the dismissible IDThe close button is activated.

    Accessibility

    The platform is told of an alert named by the card’s title and described by its description, known by the card’s id, or by toast: and its title without one. Copy with an action is a button named by that copy, and the close button is named by labels().dismiss_notice.

    API reference

    The guide covers composition, options and actions. Generate the complete Rust type and builder reference from the checkout:

    cargo doc -p limn --open

    Component API overview · State and actions

    The example is drawn by crates/limn-gallery/src/pages/overlays.rs.