Skip to main content

ferroui_base/animation/animators/
float_animator.rs

1use crate::animation::animators::{Animator, AnimatorBase};
2
3/// Animator that handles `f32` properties.
4#[derive(Default)]
5pub struct FloatAnimator {
6    base: AnimatorBase,
7}
8
9impl FloatAnimator {
10    pub fn new() -> Self {
11        Self::default()
12    }
13
14    /// Interpolates between two values using the specified progress.
15    #[inline]
16    pub fn interpolate_core(progress: f64, old_value: &f32, new_value: &f32) -> f32 {
17        (((*new_value - *old_value) as f64 * progress) + *old_value as f64) as f32
18    }
19}
20
21impl Animator for FloatAnimator {
22    type Value = f32;
23
24    fn base(&self) -> &AnimatorBase {
25        &self.base
26    }
27
28    #[inline]
29    fn interpolate(&self, progress: f64, old_value: &f32, new_value: &f32) -> f32 {
30        Self::interpolate_core(progress, old_value, new_value)
31    }
32}