animate/legacy/animatable.rs
1use crate::Interval;
2use glib::{object::IsA, translate::*};
3use std::fmt;
4
5glib_wrapper! {
6 pub struct Animatable(Interface<ffi::ClutterAnimatable>);
7
8 match fn {
9 get_type => || ffi::clutter_animatable_get_type(),
10 }
11}
12
13/// Trait containing all `Animatable` methods.
14///
15/// # Implementors
16///
17/// [`Actor`](struct.Actor.html), [`Animatable`](struct.Animatable.html), [`Box`](struct.Box.html), [`Clone`](struct.Clone.html), [`Group`](struct.Group.html), [`Rectangle`](struct.Rectangle.html), [`ScrollActor`](struct.ScrollActor.html), [`Stage`](struct.Stage.html), [`Text`](struct.Text.html), [`Texture`](struct.Texture.html)
18pub trait AnimatableExt: 'static {
19 /// Finds the `gobject::ParamSpec` for `property_name`
20 /// ## `property_name`
21 /// the name of the animatable property to find
22 ///
23 /// # Returns
24 ///
25 /// The `gobject::ParamSpec` for the given property
26 /// or `None`
27 fn find_property(&self, property_name: &str) -> Option<glib::ParamSpec>;
28
29 /// Retrieves the current state of `property_name` and sets `value` with it
30 /// ## `property_name`
31 /// the name of the animatable property to retrieve
32 /// ## `value`
33 /// a `gobject::Value` initialized to the type of the property to retrieve
34 fn get_initial_state(&self, property_name: &str, value: &mut glib::Value);
35
36 /// Asks a `Animatable` implementation to interpolate a
37 /// a named property between the initial and final values of
38 /// a `Interval`, using `progress` as the interpolation
39 /// value, and store the result inside `value`.
40 ///
41 /// This function should be used for every property animation
42 /// involving `Animatable`<!-- -->s.
43 ///
44 /// This function replaces `Animatable::animate_property`.
45 /// ## `property_name`
46 /// the name of the property to interpolate
47 /// ## `interval`
48 /// a `Interval` with the animation range
49 /// ## `progress`
50 /// the progress to use to interpolate between the
51 /// initial and final values of the `interval`
52 /// ## `value`
53 /// return location for an initialized `gobject::Value`
54 /// using the same type of the `interval`
55 ///
56 /// # Returns
57 ///
58 /// `true` if the interpolation was successful,
59 /// and `false` otherwise
60 fn interpolate_value<P: IsA<Interval>>(
61 &self,
62 property_name: &str,
63 interval: &P,
64 progress: f64,
65 ) -> Option<glib::Value>;
66
67 /// Sets the current state of `property_name` to `value`
68 /// ## `property_name`
69 /// the name of the animatable property to set
70 /// ## `value`
71 /// the value of the animatable property to set
72 fn set_final_state(&self, property_name: &str, value: &glib::Value);
73}
74
75impl<O: IsA<Animatable>> AnimatableExt for O {
76 fn find_property(&self, property_name: &str) -> Option<glib::ParamSpec> {
77 unsafe {
78 from_glib_none(ffi::clutter_animatable_find_property(
79 self.as_ref().to_glib_none().0,
80 property_name.to_glib_none().0,
81 ))
82 }
83 }
84
85 fn get_initial_state(&self, property_name: &str, value: &mut glib::Value) {
86 unsafe {
87 ffi::clutter_animatable_get_initial_state(
88 self.as_ref().to_glib_none().0,
89 property_name.to_glib_none().0,
90 value.to_glib_none_mut().0,
91 );
92 }
93 }
94
95 fn interpolate_value<P: IsA<Interval>>(
96 &self,
97 property_name: &str,
98 interval: &P,
99 progress: f64,
100 ) -> Option<glib::Value> {
101 unsafe {
102 let mut value = glib::Value::uninitialized();
103 let ret = from_glib(ffi::clutter_animatable_interpolate_value(
104 self.as_ref().to_glib_none().0,
105 property_name.to_glib_none().0,
106 interval.as_ref().to_glib_none().0,
107 progress,
108 value.to_glib_none_mut().0,
109 ));
110 if ret {
111 Some(value)
112 } else {
113 None
114 }
115 }
116 }
117
118 fn set_final_state(&self, property_name: &str, value: &glib::Value) {
119 unsafe {
120 ffi::clutter_animatable_set_final_state(
121 self.as_ref().to_glib_none().0,
122 property_name.to_glib_none().0,
123 value.to_glib_none().0,
124 );
125 }
126 }
127}
128
129impl fmt::Display for Animatable {
130 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
131 write!(f, "Animatable")
132 }
133}