clutter/auto/
interval.rs

1use glib::{
2    object as gobject,
3    object::{Cast, IsA},
4    signal::{connect_raw, SignalHandlerId},
5    translate::*,
6    StaticType, Value,
7};
8use std::boxed::Box as Box_;
9use std::{fmt, mem::transmute};
10// use Scriptable;
11
12// TODO: , @implements Scriptable
13glib_wrapper! {
14    pub struct Interval(Object<ffi::ClutterInterval, ffi::ClutterIntervalClass, IntervalClass>) @extends gobject::InitiallyUnowned;
15
16    match fn {
17        get_type => || ffi::clutter_interval_get_type(),
18    }
19}
20
21impl Interval {
22    //pub fn new(gtype: glib::types::Type, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) -> Interval {
23    //    unsafe { TODO: call clutter_sys:clutter_interval_new() }
24    //}
25
26    pub fn with_values(
27        gtype: glib::types::Type,
28        initial: Option<&glib::Value>,
29        final_: Option<&glib::Value>,
30    ) -> Interval {
31        unsafe {
32            from_glib_none(ffi::clutter_interval_new_with_values(
33                gtype.to_glib(),
34                initial.to_glib_none().0,
35                final_.to_glib_none().0,
36            ))
37        }
38    }
39
40    //pub fn register_progress_func<P: Fn(&glib::Value, &glib::Value, f64, &glib::Value) -> bool + 'static>(value_type: glib::types::Type, func: P) {
41    //    unsafe { TODO: call clutter_sys:clutter_interval_register_progress_func() }
42    //}
43}
44
45pub const NONE_INTERVAL: Option<&Interval> = None;
46
47/// Trait containing all `Interval` methods.
48///
49/// # Implementors
50///
51/// [`Interval`](struct.Interval.html)
52pub trait IntervalExt: 'static {
53    /// Creates a copy of `self`.
54    ///
55    /// # Returns
56    ///
57    /// the newly created `Interval`
58    fn clone(&self) -> Option<Interval>;
59
60    /// Computes the value between the `self` boundaries given the
61    /// progress `factor`
62    ///
63    /// Unlike `IntervalExt::compute_value`, this function will
64    /// return a const pointer to the computed value
65    ///
66    /// You should use this function if you immediately pass the computed
67    /// value to another function that makes a copy of it, like
68    /// `gobject::ObjectExt::set_property`
69    /// ## `factor`
70    /// the progress factor, between 0 and 1
71    ///
72    /// # Returns
73    ///
74    /// a pointer to the computed value,
75    ///  or `None` if the computation was not successfull
76    fn compute(&self, factor: f64) -> Option<glib::Value>;
77
78    /// Computes the value between the `self` boundaries given the
79    /// progress `factor` and copies it into `value`.
80    /// ## `factor`
81    /// the progress factor, between 0 and 1
82    /// ## `value`
83    /// return location for an initialized `gobject::Value`
84    ///
85    /// # Returns
86    ///
87    /// `true` if the operation was successful
88    fn compute_value(&self, factor: f64) -> Option<glib::Value>;
89
90    /// Retrieves the final value of `self` and copies
91    /// it into `value`.
92    ///
93    /// The passed `gobject::Value` must be initialized to the value held by
94    /// the `Interval`.
95    /// ## `value`
96    /// a `gobject::Value`
97    fn get_final_value(&self) -> glib::Value;
98
99    /// Retrieves the initial value of `self` and copies
100    /// it into `value`.
101    ///
102    /// The passed `gobject::Value` must be initialized to the value held by
103    /// the `Interval`.
104    /// ## `value`
105    /// a `gobject::Value`
106    fn get_initial_value(&self) -> glib::Value;
107
108    //fn get_interval(&self, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs);
109
110    /// Retrieves the `glib::Type` of the values inside `self`.
111    ///
112    /// # Returns
113    ///
114    /// the type of the value, or G_TYPE_INVALID
115    fn get_value_type(&self) -> glib::types::Type;
116
117    /// Checks if the `self` has a valid initial and final values.
118    ///
119    /// # Returns
120    ///
121    /// `true` if the `Interval` has an initial and
122    ///  final values, and `false` otherwise
123    fn is_valid(&self) -> bool;
124
125    /// Gets the pointer to the final value of `self`
126    ///
127    /// # Returns
128    ///
129    /// the final value of the interval.
130    ///  The value is owned by the `Interval` and it should not be
131    ///  modified or freed
132    fn peek_final_value(&self) -> Option<glib::Value>;
133
134    /// Gets the pointer to the initial value of `self`
135    ///
136    /// # Returns
137    ///
138    /// the initial value of the interval.
139    ///  The value is owned by the `Interval` and it should not be
140    ///  modified or freed
141    fn peek_initial_value(&self) -> Option<glib::Value>;
142
143    //fn set_final(&self, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs);
144
145    /// Sets the final value of `self` to `value`. The value is
146    /// copied inside the `Interval`.
147    /// ## `value`
148    /// a `gobject::Value`
149    fn set_final_value(&self, value: &glib::Value);
150
151    //fn set_initial(&self, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs);
152
153    /// Sets the initial value of `self` to `value`. The value is copied
154    /// inside the `Interval`.
155    /// ## `value`
156    /// a `gobject::Value`
157    fn set_initial_value(&self, value: &glib::Value);
158
159    //fn set_interval(&self, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs);
160
161    // /// Validates the initial and final values of `self` against
162    // /// a `gobject::ParamSpec`.
163    // /// ## `pspec`
164    // /// a `gobject::ParamSpec`
165    // ///
166    // /// # Returns
167    // ///
168    // /// `true` if the `Interval` is valid, `false` otherwise
169    // fn validate<P: IsA<glib::ParamSpec>>(&self, pspec: &P) -> bool;
170
171    // /// The final value of the interval.
172    // fn get_property_final(&self) -> Option<glib::Value>;
173
174    // /// The initial value of the interval.
175    // fn get_property_initial(&self) -> Option<glib::Value>;
176
177    fn connect_property_final_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
178
179    fn connect_property_initial_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
180}
181
182impl<O: IsA<Interval>> IntervalExt for O {
183    fn clone(&self) -> Option<Interval> {
184        unsafe { from_glib_full(ffi::clutter_interval_clone(self.as_ref().to_glib_none().0)) }
185    }
186
187    fn compute(&self, factor: f64) -> Option<glib::Value> {
188        unsafe {
189            from_glib_none(ffi::clutter_interval_compute(
190                self.as_ref().to_glib_none().0,
191                factor,
192            ))
193        }
194    }
195
196    fn compute_value(&self, factor: f64) -> Option<glib::Value> {
197        unsafe {
198            let mut value = glib::Value::uninitialized();
199            let ret = from_glib(ffi::clutter_interval_compute_value(
200                self.as_ref().to_glib_none().0,
201                factor,
202                value.to_glib_none_mut().0,
203            ));
204            if ret {
205                Some(value)
206            } else {
207                None
208            }
209        }
210    }
211
212    fn get_final_value(&self) -> glib::Value {
213        unsafe {
214            let mut value = glib::Value::uninitialized();
215            ffi::clutter_interval_get_final_value(
216                self.as_ref().to_glib_none().0,
217                value.to_glib_none_mut().0,
218            );
219            value
220        }
221    }
222
223    fn get_initial_value(&self) -> glib::Value {
224        unsafe {
225            let mut value = glib::Value::uninitialized();
226            ffi::clutter_interval_get_initial_value(
227                self.as_ref().to_glib_none().0,
228                value.to_glib_none_mut().0,
229            );
230            value
231        }
232    }
233
234    //fn get_interval(&self, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) {
235    //    unsafe { TODO: call clutter_sys:clutter_interval_get_interval() }
236    //}
237
238    fn get_value_type(&self) -> glib::types::Type {
239        unsafe {
240            from_glib(ffi::clutter_interval_get_value_type(
241                self.as_ref().to_glib_none().0,
242            ))
243        }
244    }
245
246    fn is_valid(&self) -> bool {
247        unsafe {
248            from_glib(ffi::clutter_interval_is_valid(
249                self.as_ref().to_glib_none().0,
250            ))
251        }
252    }
253
254    fn peek_final_value(&self) -> Option<glib::Value> {
255        unsafe {
256            from_glib_none(ffi::clutter_interval_peek_final_value(
257                self.as_ref().to_glib_none().0,
258            ))
259        }
260    }
261
262    fn peek_initial_value(&self) -> Option<glib::Value> {
263        unsafe {
264            from_glib_none(ffi::clutter_interval_peek_initial_value(
265                self.as_ref().to_glib_none().0,
266            ))
267        }
268    }
269
270    //fn set_final(&self, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) {
271    //    unsafe { TODO: call clutter_sys:clutter_interval_set_final() }
272    //}
273
274    fn set_final_value(&self, value: &glib::Value) {
275        unsafe {
276            ffi::clutter_interval_set_final_value(
277                self.as_ref().to_glib_none().0,
278                value.to_glib_none().0,
279            );
280        }
281    }
282
283    //fn set_initial(&self, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) {
284    //    unsafe { TODO: call clutter_sys:clutter_interval_set_initial() }
285    //}
286
287    fn set_initial_value(&self, value: &glib::Value) {
288        unsafe {
289            ffi::clutter_interval_set_initial_value(
290                self.as_ref().to_glib_none().0,
291                value.to_glib_none().0,
292            );
293        }
294    }
295
296    //fn set_interval(&self, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) {
297    //    unsafe { TODO: call clutter_sys:clutter_interval_set_interval() }
298    //}
299
300    // fn validate<P: IsA<glib::ParamSpec>>(&self, pspec: &P) -> bool {
301    //     unsafe {
302    //         from_glib(ffi::clutter_interval_validate(
303    //             self.as_ref().to_glib_none().0,
304    //             pspec.as_ref().to_glib_none().0,
305    //         ))
306    //     }
307    // }
308
309    // fn get_property_final(&self) -> Option<glib::Value> {
310    //     unsafe {
311    //         let mut value = Value::from_type(<glib::Value as StaticType>::static_type());
312    //         gobject_sys::g_object_get_property(
313    //             self.to_glib_none().0 as *mut gobject_sys::GObject,
314    //             b"final\0".as_ptr() as *const _,
315    //             value.to_glib_none_mut().0,
316    //         );
317    //         value
318    //             .get()
319    //             .expect("Return Value for property `final` getter")
320    //     }
321    // }
322
323    // fn get_property_initial(&self) -> Option<glib::Value> {
324    //     unsafe {
325    //         let mut value = Value::from_type(<glib::Value as StaticType>::static_type());
326    //         gobject_sys::g_object_get_property(
327    //             self.to_glib_none().0 as *mut gobject_sys::GObject,
328    //             b"initial\0".as_ptr() as *const _,
329    //             value.to_glib_none_mut().0,
330    //         );
331    //         value
332    //             .get()
333    //             .expect("Return Value for property `initial` getter")
334    //     }
335    // }
336
337    fn connect_property_final_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
338        unsafe extern "C" fn notify_final_trampoline<P, F: Fn(&P) + 'static>(
339            this: *mut ffi::ClutterInterval,
340            _param_spec: glib_sys::gpointer,
341            f: glib_sys::gpointer,
342        ) where
343            P: IsA<Interval>,
344        {
345            let f: &F = &*(f as *const F);
346            f(&Interval::from_glib_borrow(this).unsafe_cast_ref())
347        }
348        unsafe {
349            let f: Box_<F> = Box_::new(f);
350            connect_raw(
351                self.as_ptr() as *mut _,
352                b"notify::final\0".as_ptr() as *const _,
353                Some(transmute::<_, unsafe extern "C" fn()>(
354                    notify_final_trampoline::<Self, F> as *const (),
355                )),
356                Box_::into_raw(f),
357            )
358        }
359    }
360
361    fn connect_property_initial_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
362        unsafe extern "C" fn notify_initial_trampoline<P, F: Fn(&P) + 'static>(
363            this: *mut ffi::ClutterInterval,
364            _param_spec: glib_sys::gpointer,
365            f: glib_sys::gpointer,
366        ) where
367            P: IsA<Interval>,
368        {
369            let f: &F = &*(f as *const F);
370            f(&Interval::from_glib_borrow(this).unsafe_cast_ref())
371        }
372        unsafe {
373            let f: Box_<F> = Box_::new(f);
374            connect_raw(
375                self.as_ptr() as *mut _,
376                b"notify::initial\0".as_ptr() as *const _,
377                Some(transmute::<_, unsafe extern "C" fn()>(
378                    notify_initial_trampoline::<Self, F> as *const (),
379                )),
380                Box_::into_raw(f),
381            )
382        }
383    }
384}
385
386impl fmt::Display for Interval {
387    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
388        write!(f, "Interval")
389    }
390}