ferroui_base/animation/animators/
relative_point_animator.rs1use crate::animation::animators::PointAnimator;
2use crate::RelativePoint;
3use crate::animation::animators::{Animator, AnimatorBase};
4
5#[derive(Default)]
7pub struct RelativePointAnimator {
8 base: AnimatorBase,
9}
10
11impl RelativePointAnimator {
12 pub fn new() -> Self {
13 Self::default()
14 }
15
16 pub fn interpolate_core(progress: f64, old_value: &RelativePoint, new_value: &RelativePoint) -> RelativePoint {
18 if old_value.unit != new_value.unit {
19 return if progress >= 0.5 { *new_value } else { *old_value };
20 }
21
22 RelativePoint::from_point(PointAnimator::interpolate_core(progress, &old_value.point, &new_value.point), old_value.unit)
23 }
24}
25
26impl Animator for RelativePointAnimator {
27 type Value = RelativePoint;
28
29 fn base(&self) -> &AnimatorBase {
30 &self.base
31 }
32
33 #[inline]
34 fn interpolate(&self, progress: f64, old_value: &RelativePoint, new_value: &RelativePoint) -> RelativePoint {
35 Self::interpolate_core(progress, old_value, new_value)
36 }
37}