Skip to main content

gpui_component/progress/
mod.rs

1mod progress;
2mod progress_circle;
3
4pub use progress::Progress;
5pub use progress_circle::ProgressCircle;
6
7use std::cell::Cell;
8
9/// Shared state for progress components.
10///
11/// Tracks the animation "from" value (`value`) and the latest target
12/// (`target`). `target` uses `Cell` so it can be updated immediately
13/// during render without triggering a re-render notification.
14pub(crate) struct ProgressState {
15    /// The "from" value for the current animation; updated by the async
16    /// timer once the animation completes.
17    pub(crate) value: f32,
18    /// The latest animation target, updated immediately via interior
19    /// mutability so stale timers always read the up-to-date target.
20    target: Cell<f32>,
21}
22
23impl ProgressState {
24    pub(crate) fn new(value: f32) -> Self {
25        Self {
26            value,
27            target: Cell::new(value),
28        }
29    }
30
31    pub(crate) fn target(&self) -> f32 {
32        self.target.get()
33    }
34
35    pub(crate) fn set_target(&self, value: f32) {
36        self.target.set(value);
37    }
38}