Skip to main content

euv_ui/hook/transition/
struct.rs

1use super::*;
2
3/// Configuration for a `TransitionState`.
4///
5/// Both fields are reactive (the underlying state holds a
6/// `Signal<TransitionConfig>`), so consumers can adjust
7/// the durations at runtime via `change_config` and any
8/// pending timers driven by the old config will continue
9/// using the old values until they next read the config
10/// signal.
11#[derive(Clone, Copy, Data, Debug, Eq, PartialEq)]
12pub struct TransitionConfig {
13    /// The duration of the enter animation, in
14    /// milliseconds.
15    #[get(type(copy))]
16    pub enter_ms: u32,
17    /// The duration of the exit animation, in
18    /// milliseconds.
19    #[get(type(copy))]
20    pub exit_ms: u32,
21}
22
23/// The aggregate transition state.
24///
25/// Constructed once per animated element via
26/// `App::use_transition(...)`. Cheap to `Clone` (each
27/// internal signal is `Copy`-by-pointer). Drives the
28/// state machine forward via `tick(elapsed_ms)` and
29/// exposes the current phase / progress as reactive
30/// signals so the consuming component's render closure
31/// re-runs whenever either changes.
32#[derive(Clone, Data, New)]
33pub struct TransitionState {
34    /// The current lifecycle phase.
35    pub(crate) phase: Signal<TransitionPhase>,
36    /// The current progress, in `[0.0, 1.0]`. Pinned to
37    /// `1.0` for `Entered`, `0.0` for `Exited`, and
38    /// intermediate for `Entering` / `Exiting`.
39    pub(crate) progress: Signal<f64>,
40    /// The duration config (see `TransitionConfig`).
41    pub(crate) config: Signal<TransitionConfig>,
42}