Skip to main content

ferroui_base/animation/
animator_driven_transition.rs

1use crate::animation::animators::Animator;
2use crate::animation::easings::Easing;
3use crate::animation::AnimatorTransitionObservable;
4use crate::reactive::IObservable;
5use std::rc::Rc;
6
7/// Creates the observable of a transition whose values are interpolated by
8/// the animator `A`.
9pub struct AnimatorDrivenTransition;
10
11impl AnimatorDrivenTransition {
12    pub fn transition<A: Animator + Default>(
13        easing: Easing,
14        progress: Rc<dyn IObservable<f64>>,
15        old_value: A::Value,
16        new_value: A::Value,
17    ) -> Rc<dyn IObservable<A::Value>> {
18        let animator = A::default();
19        AnimatorTransitionObservable::create(
20            move |progress, old_value, new_value| animator.interpolate(progress, old_value, new_value),
21            progress,
22            easing,
23            old_value,
24            new_value,
25        )
26    }
27}