Skip to main content

ferroui_base/animation/easings/
i_easing.rs

1/// Defines the interface for easing classes.
2///
3/// The `Any` supertrait lets optional transition adapters recognize a physical easing
4/// and retain its parameters across interruptions, while ordinary easings keep the
5/// normalized-progress contract. Every existing `'static` easing also implements `Any`.
6pub trait IEasing: std::any::Any {
7    /// Returns the transformed value for a linear progress.
8    fn ease(&self, progress: f64) -> f64;
9
10    /// The easing as the render thread evaluates it: a key frame animation of
11    /// the compositor runs there. An easing without parameters returns
12    /// itself; one with parameters returns a copy with the parameters it has
13    /// now.
14    fn to_shared(&self) -> std::sync::Arc<SharedEasing>;
15
16    /// Whether the object is an easing class: upstream, a class deriving from
17    /// the `Easing` base class, which code tests for with a cast. True for
18    /// every easing of this module and by default, because implementing this
19    /// trait is how an easing class is written here; an object that stands
20    /// for a bare implementation of the contract (not an easing class)
21    /// answers false.
22    fn derives_from_easing(&self) -> bool {
23        true
24    }
25}
26
27/// Handles compare by identity (reference equality), so that they can be
28/// held in property and untyped values.
29impl PartialEq for dyn IEasing {
30    #[inline]
31    fn eq(&self, other: &Self) -> bool {
32        std::ptr::addr_eq(self as *const Self, other as *const Self)
33    }
34}
35
36/// An easing that can be evaluated on any thread; see [`IEasing::to_shared`].
37pub type SharedEasing = dyn IEasing + Send + Sync;