1mod duration;
4mod iteration;
5mod mode;
6mod utils;
7
8pub use duration::{Delay, Duration};
9pub use iteration::IterationCount;
10pub use mode::Direction;
11
12pub use lilt::Easing;
13
14#[derive(Debug, Clone, Copy, PartialEq)]
31pub struct Timing {
32 duration: Duration,
34 delay: Delay,
36 direction: Direction,
38 easing: Easing,
40 iterations: IterationCount,
42}
43
44impl Timing {
45 #[must_use]
47 pub fn new(duration_ms: f64) -> Self {
48 Self {
49 duration: Duration::from_millis(duration_ms),
50 ..Self::default()
51 }
52 }
53
54 #[must_use]
56 pub const fn duration(&self) -> Duration {
57 self.duration
58 }
59
60 #[must_use]
62 pub const fn delay(&self) -> Delay {
63 self.delay
64 }
65
66 #[must_use]
68 pub const fn direction(&self) -> Direction {
69 self.direction
70 }
71
72 #[must_use]
74 pub const fn easing(&self) -> Easing {
75 self.easing
76 }
77
78 #[must_use]
80 pub const fn iterations(&self) -> IterationCount {
81 self.iterations
82 }
83
84 #[must_use]
86 pub const fn with_delay(mut self, delay: Delay) -> Self {
87 self.delay = delay;
88 self
89 }
90
91 #[must_use]
93 pub const fn with_direction(mut self, direction: Direction) -> Self {
94 self.direction = direction;
95 self
96 }
97
98 #[must_use]
100 pub const fn with_easing(mut self, easing: Easing) -> Self {
101 self.easing = easing;
102 self
103 }
104
105 #[must_use]
107 pub fn with_iterations(mut self, iterations: impl Into<IterationCount>) -> Self {
108 self.iterations = iterations.into();
109 self
110 }
111
112 #[must_use]
114 pub fn active_duration(self) -> Option<Duration> {
115 let count = self.iterations.finite_count()?;
116
117 self.duration.checked_mul(count)
118 }
119
120 #[must_use]
122 pub fn total_duration(self) -> Option<Duration> {
123 let active = self.active_duration()?;
124
125 active.checked_add_delay(self.delay)
126 }
127
128 pub(crate) fn with_duration(mut self, duration: Duration) -> Self {
129 self.duration = duration;
130 self
131 }
132}
133
134impl Default for Timing {
135 fn default() -> Self {
136 Self {
137 duration: Duration::ZERO,
138 delay: Delay::ZERO,
139 direction: Direction::default(),
140 easing: Easing::Linear,
141 iterations: IterationCount::default(),
142 }
143 }
144}