XU XUv0.13.1
中文

UI / WIDGETS / Feedback

ToastHost

Present transient notifications in one place

Run the Xu example

The example executes in the browser using the Xu/WASM runtime.

What to try

Show a notification and dismiss it.

Usage notes

Manage transient notices in one host. Do not expose important errors only through disappearing notifications; keep undo and dismiss actions accessible.

Create the notification queue

ToastHost is a notification queue owned and presented by the application.

#ui/widgets

fn notifications() widgets.ToastHost {
    $host := widgets.toast_host()
    value := widgets.notice(&"Workspace saved")
    host.enqueue(&value) or >>
    << host
}

toast_host

XuAPI
pub fn toast_host() ToastHost

Purpose

Toast host.

Parameters

No arguments are required.

Returns

ToastHost — a value of this type

Placement, state and events

The application owns the component. Screen.place positions nodes; Screen.set_enabled and Screen.set_visible control availability and visibility. Present again after state changes, handle or errors, and keep topology changes outside paint callbacks. ToastHost uses its own queue API.

Action · Styles · UI lifecycle and styling guide

Standalone control object API

struct ToastHost

XuAPI
pub struct ToastHost {

}

Purpose

Bounded, stable-priority queue. Expiry starts when a renderer displays a record, never while it is waiting. Keys replace pending copies in place.

Public fields

This type has no public fields.

(&ToastHost) pending_count

XuAPI
pub fn (host &ToastHost) pending_count() int

Purpose

Operation on &ToastHost: pending count.

Parameters

host &ToastHost
The ToastHost instance used by this call (borrow).

Returns

int — a value of this type

($&ToastHost) set_capacity

XuAPI
pub fn (host $&ToastHost) set_capacity(capacity int) int

Purpose

Operation on $&ToastHost: set capacity. Throws on failure; handle the error or propagate it to the caller.

Parameters

host $&ToastHost
The ToastHost instance used by this call (exclusive borrow).
capacity int
capacity (int)

Returns

int — a value of this type

($&ToastHost) enqueue

XuAPI
pub fn (host $&ToastHost) enqueue(value &Notice) int

Purpose

Execute enqueue on $&ToastHost. Throws on failure; handle the error or propagate it to the caller.

Parameters

host $&ToastHost
The ToastHost instance used by this call (exclusive borrow).
value &Notice
value (read-only borrow; caller keeps the original; type &Notice)

Returns

int — a value of this type

($&ToastHost) next_notice

XuAPI
pub fn (host $&ToastHost) next_notice() NoticeRecord

Purpose

Operation on $&ToastHost: next notice. Throws on failure; handle the error or propagate it to the caller.

Parameters

host $&ToastHost
The ToastHost instance used by this call (exclusive borrow).

Returns

NoticeRecord — a value of this type

Complete native example

Component Workshop · Back to Widgets