Skip to main content

aetna_core/state/
toast.rs

1//! Runtime toast queue helpers for [`UiState`](super::UiState).
2
3use web_time::Instant;
4
5use super::UiState;
6
7impl UiState {
8    /// Queue a toast for the next frame. Stamps an `id` (monotonic)
9    /// and computes the `expires_at` deadline from `now + spec.ttl`.
10    /// The runtime re-walks the queue each frame and drops expired
11    /// entries before synthesizing the toast layer.
12    pub fn push_toast(&mut self, spec: crate::toast::ToastSpec, now: Instant) {
13        let id = self.toast.next_id;
14        self.toast.next_id = self.toast.next_id.wrapping_add(1);
15        self.toast.queue.push(crate::toast::Toast {
16            id,
17            level: spec.level,
18            message: spec.message,
19            expires_at: now + spec.ttl,
20        });
21    }
22
23    /// Remove the toast with the given id. Used by the runtime when
24    /// the user clicks a `toast-dismiss-{id}` button; apps that want
25    /// to programmatically cancel a toast can call this directly via
26    /// the `Runner::dismiss_toast` host accessor.
27    pub fn dismiss_toast(&mut self, id: u64) {
28        self.toast.queue.retain(|t| t.id != id);
29    }
30
31    /// Read-only view of the current toast queue (post-expiry).
32    /// Used by hosts that want to drive cursor / accessibility state
33    /// from the visible stack.
34    pub fn toasts(&self) -> &[crate::toast::Toast] {
35        &self.toast.queue
36    }
37}