anim/core/animation/
scale.rs1use super::{Animation, BaseAnimation};
8use crate::core::DURATION_ZERO;
9use std::time::Duration;
10#[derive(Debug, Clone)]
12pub struct Scale<T: Animation> {
13 src: T,
14 scale: f32,
15}
16
17impl<T: Animation> Scale<T> {
18 #[inline]
19 pub(super) fn new(src: T, scale: f32) -> Self {
20 assert!(scale >= 0.0);
21 Self { src, scale }
22 }
23}
24
25impl<T: Animation> BaseAnimation for Scale<T> {
26 type Item = T::Item;
27 #[inline]
28 fn duration(&self) -> Option<Duration> {
29 self.src.duration().map(|duration| {
30 if duration == DURATION_ZERO || self.scale == 0.0 {
31 return DURATION_ZERO;
32 }
33 duration.div_f32(self.scale)
34 })
35 }
36
37 #[inline]
38 fn animate(&self, elapsed: Duration) -> Self::Item {
39 if self.scale == 0.0 {
40 return self.src.animate(DURATION_ZERO);
41 }
42 let elapsed = elapsed.div_f32(self.scale);
43 self.src.animate(elapsed)
44 }
45}