ferroui_base/animation/animators/
box_shadows_animator.rs1use crate::animation::animators::BoxShadowAnimator;
2use crate::media::BoxShadows;
3use crate::animation::animators::{Animator, AnimatorBase};
4
5#[derive(Default)]
7pub struct BoxShadowsAnimator {
8 base: AnimatorBase,
9}
10
11impl BoxShadowsAnimator {
12 pub fn new() -> Self {
13 Self::default()
14 }
15
16 pub fn interpolate_core(progress: f64, old_value: &BoxShadows, new_value: &BoxShadows) -> BoxShadows {
18 let cnt = if progress >= 1.0 { new_value.count() } else { old_value.count() };
19 if cnt == 0 {
20 return BoxShadows::default();
21 }
22
23 let first = if old_value.count() > 0 && new_value.count() > 0 {
24 BoxShadowAnimator::interpolate_core(progress, &old_value.get(0), &new_value.get(0))
25 } else if old_value.count() > 0 {
26 old_value.get(0)
27 } else {
28 new_value.get(0)
29 };
30
31 if cnt == 1 {
32 return BoxShadows::new(first);
33 }
34
35 let mut rest = Vec::with_capacity(cnt - 1);
36 for c in 0..cnt - 1 {
37 let idx = c + 1;
38 rest.push(if old_value.count() > idx && new_value.count() > idx {
39 BoxShadowAnimator::interpolate_core(progress, &old_value.get(idx), &new_value.get(idx))
40 } else if old_value.count() > idx {
41 old_value.get(idx)
42 } else {
43 new_value.get(idx)
44 });
45 }
46
47 BoxShadows::with_rest(first, &rest)
48 }
49}
50
51impl Animator for BoxShadowsAnimator {
52 type Value = BoxShadows;
53
54 fn base(&self) -> &AnimatorBase {
55 &self.base
56 }
57
58 #[inline]
59 fn interpolate(&self, progress: f64, old_value: &BoxShadows, new_value: &BoxShadows) -> BoxShadows {
60 Self::interpolate_core(progress, old_value, new_value)
61 }
62}