Skip to main content

ferroui_base/animation/
i_animation_setter.rs

1use crate::styling::{Setter, SetterValue};
2use crate::FerroProperty;
3
4/// A setter that can be used in the key frames of an animation.
5pub trait IAnimationSetter: 'static {
6    /// The property the setter targets.
7    fn property(&self) -> Option<&'static FerroProperty>;
8
9    fn set_property(&self, value: Option<&'static FerroProperty>);
10
11    /// The value of the setter: a plain value holding exactly the value type
12    /// of the property, or a source of such values.
13    fn value(&self) -> Option<SetterValue>;
14
15    fn set_value(&self, value: Option<SetterValue>);
16
17    /// The implementing value, for casting to its concrete type
18    /// (`as_any()?.downcast_ref::<T>()`): the equivalent of `is`/`as` on the
19    /// contract. `None` for an implementation that does not expose itself.
20    fn as_any(&self) -> Option<&dyn std::any::Any> {
21        None
22    }
23}
24
25impl IAnimationSetter for Setter {
26    fn property(&self) -> Option<&'static FerroProperty> {
27        Setter::property(self)
28    }
29
30    fn set_property(&self, value: Option<&'static FerroProperty>) {
31        Setter::set_property(self, value)
32    }
33
34    fn value(&self) -> Option<SetterValue> {
35        Setter::value(self)
36    }
37
38    fn set_value(&self, value: Option<SetterValue>) {
39        Setter::set_value(self, value)
40    }
41
42    fn as_any(&self) -> Option<&dyn std::any::Any> {
43        Some(self)
44    }
45}
46
47/// Handles compare by identity (reference equality), so that they can be
48/// held in property and untyped values.
49impl PartialEq for dyn IAnimationSetter {
50    #[inline]
51    fn eq(&self, other: &Self) -> bool {
52        std::ptr::addr_eq(self as *const Self, other as *const Self)
53    }
54}