Skip to main content

ferroui_base/animation/easings/
i_easing.rs

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