From c61ce09591188284a0845dfbafef2fa9d8fb2133 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Wed, 18 Nov 2026 03:54:13 -0500 Subject: [PATCH] pdf-chrome-w4: net change of 1 commits - pdf-chrome-w4: written from its sheet --- crates/ui-contract/src/runtime/toast.rs | 60 ++++++++++++++++------ crates/ui-shell/tests/it/notices.rs | 43 ++++++++++++++++ crates/ui-widgets/src/notices/center.rs | 63 +++++++++++++++++------- crates/ui-widgets/src/notices/notice.rs | 34 +++++++------ crates/ui-widgets/src/notices/stories.rs | 44 ++++++++++++++++- crates/ui-widgets/src/notices/toasts.rs | 15 +++++- 6 files changed, 209 insertions(+), 50 deletions(-) diff --git a/crates/ui-contract/src/runtime/toast.rs b/crates/ui-contract/src/runtime/toast.rs index 20c86f108..d648f4276 100644 --- a/crates/ui-contract/src/runtime/toast.rs +++ b/crates/ui-contract/src/runtime/toast.rs @@ -3,8 +3,8 @@ //! The window's shell shows its queue through `ToastHost`, at the end-bottom corner of its body, and tells it which //! cards the pointer or focus holds; an embedded shell shows its own queue inside its own body. A card's timer runs only //! while nothing holds it, and starts over with its whole timeout when the hold ends. Each new toast is announced once, -//! when it is first shown. At most `MAX_CARDS` cards are queued per window; a toast's end (an action taken, a -//! dismissal, the timer, a drop by the cap) is read once with `end`. +//! when it is first shown. At most `MAX_CARDS` cards are queued per window unless progress cards fill it; a toast's end +//! (an action taken, a dismissal, the timer, a drop by the cap) is read once with `end`. use crate::runtime::access::{self, Politeness}; use crate::runtime::egui::{pass, repaint}; @@ -17,7 +17,9 @@ use egui::{Context, ViewportId}; pub const TIMEOUT: f32 = 6.0; /// Most cards queued at once per window. Posting past it keeps the new card and drops the oldest earlier card that -/// would leave by itself (no action, a timeout), else the oldest earlier card; `end` reports the drop as `Dropped`. +/// would leave by itself (no action, a timeout), else the oldest earlier card without progress; `end` reports the drop +/// as `Dropped`. A progress card is never dropped: when only progress cards are earlier, the new card is queued past +/// the cap. pub const MAX_CARDS: usize = 3; /// Ended toasts whose end nobody has read yet; the oldest report goes first. @@ -84,7 +86,7 @@ impl Toast { title: None, lines: Vec::new(), actions: Vec::new(), - progress: Default::default(), + progress: None, } } @@ -124,17 +126,42 @@ impl Toast { self } - /// Sets the fraction done, clamped to `0..=1`. - pub fn progress(self, fraction: f32) -> Self { - let _ = fraction; - todo!("CH-C14") + /// Sets the fraction done, clamped to `0..=1`; the card then has no timer. + pub fn progress(mut self, fraction: f32) -> Self { + self.progress = Some(clamp_fraction(fraction)); + self.timeout = None; + self } } -/// Sets the fraction done of the toast `id` and, when given, its message. +/// `fraction` clamped to `0..=1`, and 0 when it is not a number. +fn clamp_fraction(fraction: f32) -> f32 { + if fraction.is_nan() { 0.0 } else { fraction.clamp(0.0, 1.0) } +} + +/// Sets the fraction done of the toast `id` and, when given, its message, in whichever viewport holds it; the card +/// keeps no timer from then on. A toast that is gone is left alone, and a measuring run changes nothing. pub fn set_progress(ctx: &Context, id: ToastId, fraction: f32, message: Option