animate/legacy/
transition.rs

1// Scriptable
2use super::{Animatable, Interval, Timeline};
3use glib::{
4    object::{Cast, IsA},
5    signal::{connect_raw, SignalHandlerId},
6    translate::*,
7};
8use std::boxed::Box as Box_;
9use std::{fmt, mem::transmute};
10
11// TODO: @implements Scriptable
12glib_wrapper! {
13    pub struct Transition(Object<ffi::ClutterTransition, ffi::ClutterTransitionClass, TransitionClass>) @extends Timeline;
14
15    match fn {
16        get_type => || ffi::clutter_transition_get_type(),
17    }
18}
19
20/// Trait containing all `Transition` methods.
21///
22/// # Implementors
23///
24/// [`PropertyTransition`](struct.PropertyTransition.html), [`TransitionGroup`](struct.TransitionGroup.html), [`Transition`](struct.Transition.html)
25pub trait TransitionExt: 'static {
26    /// Retrieves the `Animatable` set using `TransitionExt::set_animatable`.
27    ///
28    /// # Returns
29    ///
30    /// a `Animatable`, or `None`; the returned
31    ///  animatable is owned by the `Transition`, and it should not be freed
32    ///  directly.
33    fn get_animatable(&self) -> Option<Animatable>;
34
35    /// Retrieves the interval set using `TransitionExt::set_interval`
36    ///
37    /// # Returns
38    ///
39    /// a `Interval`, or `None`; the returned
40    ///  interval is owned by the `Transition` and it should not be freed
41    ///  directly
42    fn get_interval(&self) -> Option<Interval>;
43
44    /// Retrieves the value of the `Transition:remove-on-complete` property.
45    ///
46    /// # Returns
47    ///
48    /// `true` if the `self` should be detached when complete,
49    ///  and `false` otherwise
50    fn get_remove_on_complete(&self) -> bool;
51
52    /// Sets the `Transition:animatable` property.
53    ///
54    /// The `self` will acquire a reference to the `animatable` instance,
55    /// and will call the `TransitionClass.attached`() virtual function.
56    ///
57    /// If an existing `Animatable` is attached to `self`, the
58    /// reference will be released, and the `TransitionClass.detached`()
59    /// virtual function will be called.
60    /// ## `animatable`
61    /// a `Animatable`, or `None`
62    fn set_animatable<P: IsA<Animatable>>(&self, animatable: Option<&P>);
63
64    //fn set_from(&self, value_type: glib::types::Type, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs);
65
66    /// Sets the initial value of the transition.
67    ///
68    /// This is a convenience function that will either create the
69    /// `Interval` used by `self`, or will update it if
70    /// the `Transition:interval` is already set.
71    ///
72    /// This function will copy the contents of `value`, so it is
73    /// safe to call `gobject::Value::unset` after it returns.
74    ///
75    /// If `self` already has a `Transition:interval` set,
76    /// then `value` must hold the same type, or a transformable type,
77    /// as the interval's `Interval:value-type` property.
78    ///
79    /// This function is meant to be used by language bindings.
80    /// ## `value`
81    /// a `gobject::Value` with the initial value of the transition
82    fn set_from_value(&self, value: &glib::Value);
83
84    /// Sets the `Transition:interval` property using `interval`.
85    ///
86    /// The `self` will acquire a reference on the `interval`, sinking
87    /// the floating flag on it if necessary.
88    /// ## `interval`
89    /// a `Interval`, or `None`
90    fn set_interval<P: IsA<Interval>>(&self, interval: Option<&P>);
91
92    /// Sets whether `self` should be detached from the `Animatable`
93    /// set using `TransitionExt::set_animatable` when the
94    /// `Timeline::completed` signal is emitted.
95    /// ## `remove_complete`
96    /// whether to detach `self` when complete
97    fn set_remove_on_complete(&self, remove_complete: bool);
98
99    //fn set_to(&self, value_type: glib::types::Type, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs);
100
101    /// Sets the final value of the transition.
102    ///
103    /// This is a convenience function that will either create the
104    /// `Interval` used by `self`, or will update it if
105    /// the `Transition:interval` is already set.
106    ///
107    /// This function will copy the contents of `value`, so it is
108    /// safe to call `gobject::Value::unset` after it returns.
109    ///
110    /// If `self` already has a `Transition:interval` set,
111    /// then `value` must hold the same type, or a transformable type,
112    /// as the interval's `Interval:value-type` property.
113    ///
114    /// This function is meant to be used by language bindings.
115    /// ## `value`
116    /// a `gobject::Value` with the final value of the transition
117    fn set_to_value(&self, value: &glib::Value);
118
119    fn connect_property_animatable_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
120
121    fn connect_property_interval_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
122
123    fn connect_property_remove_on_complete_notify<F: Fn(&Self) + 'static>(
124        &self,
125        f: F,
126    ) -> SignalHandlerId;
127}
128
129impl<O: IsA<Transition>> TransitionExt for O {
130    fn get_animatable(&self) -> Option<Animatable> {
131        unsafe {
132            from_glib_none(ffi::clutter_transition_get_animatable(
133                self.as_ref().to_glib_none().0,
134            ))
135        }
136    }
137
138    fn get_interval(&self) -> Option<Interval> {
139        unsafe {
140            from_glib_none(ffi::clutter_transition_get_interval(
141                self.as_ref().to_glib_none().0,
142            ))
143        }
144    }
145
146    fn get_remove_on_complete(&self) -> bool {
147        unsafe {
148            from_glib(ffi::clutter_transition_get_remove_on_complete(
149                self.as_ref().to_glib_none().0,
150            ))
151        }
152    }
153
154    fn set_animatable<P: IsA<Animatable>>(&self, animatable: Option<&P>) {
155        unsafe {
156            ffi::clutter_transition_set_animatable(
157                self.as_ref().to_glib_none().0,
158                animatable.map(|p| p.as_ref()).to_glib_none().0,
159            );
160        }
161    }
162
163    //fn set_from(&self, value_type: glib::types::Type, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) {
164    //    unsafe { TODO: call clutter_sys:clutter_transition_set_from() }
165    //}
166
167    fn set_from_value(&self, value: &glib::Value) {
168        unsafe {
169            ffi::clutter_transition_set_from_value(
170                self.as_ref().to_glib_none().0,
171                value.to_glib_none().0,
172            );
173        }
174    }
175
176    fn set_interval<P: IsA<Interval>>(&self, interval: Option<&P>) {
177        unsafe {
178            ffi::clutter_transition_set_interval(
179                self.as_ref().to_glib_none().0,
180                interval.map(|p| p.as_ref()).to_glib_none().0,
181            );
182        }
183    }
184
185    fn set_remove_on_complete(&self, remove_complete: bool) {
186        unsafe {
187            ffi::clutter_transition_set_remove_on_complete(
188                self.as_ref().to_glib_none().0,
189                remove_complete.to_glib(),
190            );
191        }
192    }
193
194    //fn set_to(&self, value_type: glib::types::Type, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) {
195    //    unsafe { TODO: call clutter_sys:clutter_transition_set_to() }
196    //}
197
198    fn set_to_value(&self, value: &glib::Value) {
199        unsafe {
200            ffi::clutter_transition_set_to_value(
201                self.as_ref().to_glib_none().0,
202                value.to_glib_none().0,
203            );
204        }
205    }
206
207    fn connect_property_animatable_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
208        unsafe extern "C" fn notify_animatable_trampoline<P, F: Fn(&P) + 'static>(
209            this: *mut ffi::ClutterTransition,
210            _param_spec: glib_sys::gpointer,
211            f: glib_sys::gpointer,
212        ) where
213            P: IsA<Transition>,
214        {
215            let f: &F = &*(f as *const F);
216            f(&Transition::from_glib_borrow(this).unsafe_cast_ref())
217        }
218        unsafe {
219            let f: Box_<F> = Box_::new(f);
220            connect_raw(
221                self.as_ptr() as *mut _,
222                b"notify::animatable\0".as_ptr() as *const _,
223                Some(transmute::<_, unsafe extern "C" fn()>(
224                    notify_animatable_trampoline::<Self, F> as *const (),
225                )),
226                Box_::into_raw(f),
227            )
228        }
229    }
230
231    fn connect_property_interval_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
232        unsafe extern "C" fn notify_interval_trampoline<P, F: Fn(&P) + 'static>(
233            this: *mut ffi::ClutterTransition,
234            _param_spec: glib_sys::gpointer,
235            f: glib_sys::gpointer,
236        ) where
237            P: IsA<Transition>,
238        {
239            let f: &F = &*(f as *const F);
240            f(&Transition::from_glib_borrow(this).unsafe_cast_ref())
241        }
242        unsafe {
243            let f: Box_<F> = Box_::new(f);
244            connect_raw(
245                self.as_ptr() as *mut _,
246                b"notify::interval\0".as_ptr() as *const _,
247                Some(transmute::<_, unsafe extern "C" fn()>(
248                    notify_interval_trampoline::<Self, F> as *const (),
249                )),
250                Box_::into_raw(f),
251            )
252        }
253    }
254
255    fn connect_property_remove_on_complete_notify<F: Fn(&Self) + 'static>(
256        &self,
257        f: F,
258    ) -> SignalHandlerId {
259        unsafe extern "C" fn notify_remove_on_complete_trampoline<P, F: Fn(&P) + 'static>(
260            this: *mut ffi::ClutterTransition,
261            _param_spec: glib_sys::gpointer,
262            f: glib_sys::gpointer,
263        ) where
264            P: IsA<Transition>,
265        {
266            let f: &F = &*(f as *const F);
267            f(&Transition::from_glib_borrow(this).unsafe_cast_ref())
268        }
269        unsafe {
270            let f: Box_<F> = Box_::new(f);
271            connect_raw(
272                self.as_ptr() as *mut _,
273                b"notify::remove-on-complete\0".as_ptr() as *const _,
274                Some(transmute::<_, unsafe extern "C" fn()>(
275                    notify_remove_on_complete_trampoline::<Self, F> as *const (),
276                )),
277                Box_::into_raw(f),
278            )
279        }
280    }
281}
282
283impl fmt::Display for Transition {
284    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
285        write!(f, "Transition")
286    }
287}