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