Skip to main content

aura_anim_iced/state/
transition.rs

1use std::sync::Arc;
2
3use crate::Timeline;
4
5/// Animation timeline for moving between two application states.
6#[derive(Debug, Clone, PartialEq)]
7pub struct StateTransition<S>
8where
9    S: Copy + Eq,
10{
11    from: S,
12    to: S,
13    timeline: Arc<Timeline>,
14}
15
16impl<S> StateTransition<S>
17where
18    S: Copy + Eq,
19{
20    /// Creates a state transition backed by a timeline.
21    #[must_use]
22    pub fn new(from: S, to: S, timeline: Timeline) -> Self {
23        Self {
24            from,
25            to,
26            timeline: Arc::new(timeline),
27        }
28    }
29
30    /// Returns the state this transition starts from.
31    #[must_use]
32    pub const fn from(&self) -> S {
33        self.from
34    }
35
36    /// Returns the state this transition ends at.
37    #[must_use]
38    pub const fn to(&self) -> S {
39        self.to
40    }
41
42    /// Returns the timeline registered when this transition starts.
43    #[must_use]
44    pub fn timeline(&self) -> &Timeline {
45        &self.timeline
46    }
47
48    pub(crate) fn timeline_arc(&self) -> Arc<Timeline> {
49        Arc::clone(&self.timeline)
50    }
51}