animate/legacy/
container.rs

1use crate::{Actor, ChildMeta};
2use glib::{
3    object::{Cast, IsA},
4    signal::{connect_raw, SignalHandlerId},
5    translate::*,
6};
7use std::boxed::Box as Box_;
8use std::{fmt, mem, mem::transmute};
9
10glib_wrapper! {
11    pub struct Container(Interface<ffi::ClutterContainer>);
12
13    match fn {
14        get_type => || ffi::clutter_container_get_type(),
15    }
16}
17
18impl Container {
19    // /// Looks up the `gobject::ParamSpec` for a child property of `klass`.
20    // /// ## `klass`
21    // /// a `gobject::ObjectClass` implementing the `Container` interface.
22    // /// ## `property_name`
23    // /// a property name.
24    // ///
25    // /// # Returns
26    // ///
27    // /// The `gobject::ParamSpec` for the property or `None`
28    // ///  if no such property exist.
29    // pub fn class_find_child_property(
30    //     klass: &mut glib::ObjectClass,
31    //     property_name: &str,
32    // ) -> Option<glib::ParamSpec> {
33    //     unsafe {
34    //         from_glib_none(ffi::clutter_container_class_find_child_property(
35    //             klass.to_glib_none_mut().0,
36    //             property_name.to_glib_none().0,
37    //         ))
38    //     }
39    // }
40
41    // /// Returns an array of `gobject::ParamSpec` for all child properties.
42    // /// ## `klass`
43    // /// a `gobject::ObjectClass` implementing the `Container` interface.
44    // /// ## `n_properties`
45    // /// return location for length of returned array.
46    // ///
47    // /// # Returns
48    // ///
49    // /// an array
50    // ///  of `gobject::ParamSpec`<!-- -->s which should be freed after use.
51    // pub fn class_list_child_properties(klass: &mut glib::ObjectClass) -> Vec<glib::ParamSpec> {
52    //     unsafe {
53    //         let mut n_properties = mem::MaybeUninit::uninit();
54    //         let ret = FromGlibContainer::from_glib_full_num(
55    //             ffi::clutter_container_class_list_child_properties(
56    //                 klass.to_glib_none_mut().0,
57    //                 n_properties.as_mut_ptr(),
58    //             ),
59    //             n_properties.assume_init() as usize,
60    //         );
61    //         ret
62    //     }
63    // }
64}
65
66/// Trait containing all `Container` methods.
67///
68/// # Implementors
69///
70/// [`Actor`](struct.Actor.html), [`Box`](struct.Box.html), [`Clone`](struct.Clone.html), [`Container`](struct.Container.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)
71pub trait ContainerExt: 'static {
72    //fn child_get<P: IsA<Actor>>(&self, actor: &P, first_prop: &str, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs);
73
74    /// Gets a container specific property of a child of `self`, In general,
75    /// a copy is made of the property contents and the caller is responsible for
76    /// freeing the memory by calling `gobject::Value::unset`.
77    ///
78    /// Note that `Container::child_set_property` is really intended for
79    /// language bindings, `Container::child_set` is much more convenient
80    /// for C programming.
81    /// ## `child`
82    /// a `Actor` that is a child of `self`.
83    /// ## `property`
84    /// the name of the property to set.
85    /// ## `value`
86    /// the value.
87    fn child_get_property<P: IsA<Actor>>(&self, child: &P, property: &str, value: &mut glib::Value);
88
89    /// Calls the `ContainerIface.child_notify`() virtual function
90    /// of `Container`. The default implementation will emit the
91    /// `Container::child-notify` signal.
92    /// ## `child`
93    /// a `Actor`
94    /// ## `pspec`
95    /// a `gobject::ParamSpec`
96    // fn child_notify<P: IsA<Actor>, Q: IsA<glib::ParamSpec>>(&self, child: &P, pspec: &Q);
97
98    //fn child_set<P: IsA<Actor>>(&self, actor: &P, first_prop: &str, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs);
99
100    /// Sets a container-specific property on a child of `self`.
101    /// ## `child`
102    /// a `Actor` that is a child of `self`.
103    /// ## `property`
104    /// the name of the property to set.
105    /// ## `value`
106    /// the value.
107    fn child_set_property<P: IsA<Actor>>(&self, child: &P, property: &str, value: &glib::Value);
108
109    /// Creates the `ChildMeta` wrapping `actor` inside the
110    /// `self`, if the `ContainerIface::child_meta_type`
111    /// class member is not set to `G_TYPE_INVALID`.
112    ///
113    /// This function is only useful when adding a `Actor` to
114    /// a `Container` implementation outside of the
115    /// `Container::add`() virtual function implementation.
116    ///
117    /// Applications should not call this function.
118    /// ## `actor`
119    /// a `Actor`
120    fn create_child_meta<P: IsA<Actor>>(&self, actor: &P);
121
122    /// Destroys the `ChildMeta` wrapping `actor` inside the
123    /// `self`, if any.
124    ///
125    /// This function is only useful when removing a `Actor` to
126    /// a `Container` implementation outside of the
127    /// `Container::add`() virtual function implementation.
128    ///
129    /// Applications should not call this function.
130    /// ## `actor`
131    /// a `Actor`
132    fn destroy_child_meta<P: IsA<Actor>>(&self, actor: &P);
133
134    /// Finds a child actor of a container by its name. Search recurses
135    /// into any child container.
136    /// ## `child_name`
137    /// the name of the requested child.
138    ///
139    /// # Returns
140    ///
141    /// The child actor with the requested name,
142    ///  or `None` if no actor with that name was found.
143    fn find_child_by_name(&self, child_name: &str) -> Option<Actor>;
144
145    /// Retrieves the `ChildMeta` which contains the data about the
146    /// `self` specific state for `actor`.
147    /// ## `actor`
148    /// a `Actor` that is a child of `self`.
149    ///
150    /// # Returns
151    ///
152    /// the `ChildMeta` for the `actor` child
153    ///  of `self` or `None` if the specifiec actor does not exist or the
154    ///  container is not configured to provide `ChildMeta`<!-- -->s
155    fn get_child_meta<P: IsA<Actor>>(&self, actor: &P) -> Option<ChildMeta>;
156
157    /// The ::actor-added signal is emitted each time an actor
158    /// has been added to `container`.
159    /// ## `actor`
160    /// the new child that has been added to `container`
161    fn connect_actor_added<F: Fn(&Self, &Actor) + 'static>(&self, f: F) -> SignalHandlerId;
162
163    /// The ::actor-removed signal is emitted each time an actor
164    /// is removed from `container`.
165    /// ## `actor`
166    /// the child that has been removed from `container`
167    fn connect_actor_removed<F: Fn(&Self, &Actor) + 'static>(&self, f: F) -> SignalHandlerId;
168
169    /// The ::child-notify signal is emitted each time a property is
170    /// being set through the `Container::child_set` and
171    /// `Container::child_set_property` calls.
172    /// ## `actor`
173    /// the child that has had a property set
174    /// ## `pspec`
175    /// the `gobject::ParamSpec` of the property set
176    fn connect_child_notify<F: Fn(&Self, &Actor, &glib::ParamSpec) + 'static>(
177        &self,
178        f: F,
179    ) -> SignalHandlerId;
180}
181
182impl<O: IsA<Container>> ContainerExt for O {
183    //fn child_get<P: IsA<Actor>>(&self, actor: &P, first_prop: &str, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) {
184    //    unsafe { TODO: call clutter_sys:clutter_container_child_get() }
185    //}
186
187    fn child_get_property<P: IsA<Actor>>(
188        &self,
189        child: &P,
190        property: &str,
191        value: &mut glib::Value,
192    ) {
193        unsafe {
194            ffi::clutter_container_child_get_property(
195                self.as_ref().to_glib_none().0,
196                child.as_ref().to_glib_none().0,
197                property.to_glib_none().0,
198                value.to_glib_none_mut().0,
199            );
200        }
201    }
202
203    // fn child_notify<P: IsA<Actor>, Q: IsA<glib::ParamSpec>>(&self, child: &P, pspec: &Q) {
204    //     unsafe {
205    //         ffi::clutter_container_child_notify(
206    //             self.as_ref().to_glib_none().0,
207    //             child.as_ref().to_glib_none().0,
208    //             pspec.as_ref().to_glib_none().0,
209    //         );
210    //     }
211    // }
212
213    //fn child_set<P: IsA<Actor>>(&self, actor: &P, first_prop: &str, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) {
214    //    unsafe { TODO: call clutter_sys:clutter_container_child_set() }
215    //}
216
217    fn child_set_property<P: IsA<Actor>>(&self, child: &P, property: &str, value: &glib::Value) {
218        unsafe {
219            ffi::clutter_container_child_set_property(
220                self.as_ref().to_glib_none().0,
221                child.as_ref().to_glib_none().0,
222                property.to_glib_none().0,
223                value.to_glib_none().0,
224            );
225        }
226    }
227
228    fn create_child_meta<P: IsA<Actor>>(&self, actor: &P) {
229        unsafe {
230            ffi::clutter_container_create_child_meta(
231                self.as_ref().to_glib_none().0,
232                actor.as_ref().to_glib_none().0,
233            );
234        }
235    }
236
237    fn destroy_child_meta<P: IsA<Actor>>(&self, actor: &P) {
238        unsafe {
239            ffi::clutter_container_destroy_child_meta(
240                self.as_ref().to_glib_none().0,
241                actor.as_ref().to_glib_none().0,
242            );
243        }
244    }
245
246    fn find_child_by_name(&self, child_name: &str) -> Option<Actor> {
247        unsafe {
248            from_glib_none(ffi::clutter_container_find_child_by_name(
249                self.as_ref().to_glib_none().0,
250                child_name.to_glib_none().0,
251            ))
252        }
253    }
254
255    fn get_child_meta<P: IsA<Actor>>(&self, actor: &P) -> Option<ChildMeta> {
256        unsafe {
257            from_glib_none(ffi::clutter_container_get_child_meta(
258                self.as_ref().to_glib_none().0,
259                actor.as_ref().to_glib_none().0,
260            ))
261        }
262    }
263
264    fn connect_actor_added<F: Fn(&Self, &Actor) + 'static>(&self, f: F) -> SignalHandlerId {
265        unsafe extern "C" fn actor_added_trampoline<P, F: Fn(&P, &Actor) + 'static>(
266            this: *mut ffi::ClutterContainer,
267            actor: *mut ffi::ClutterActor,
268            f: glib_sys::gpointer,
269        ) where
270            P: IsA<Container>,
271        {
272            let f: &F = &*(f as *const F);
273            f(
274                &Container::from_glib_borrow(this).unsafe_cast_ref(),
275                &from_glib_borrow(actor),
276            )
277        }
278        unsafe {
279            let f: Box_<F> = Box_::new(f);
280            connect_raw(
281                self.as_ptr() as *mut _,
282                b"actor-added\0".as_ptr() as *const _,
283                Some(transmute::<_, unsafe extern "C" fn()>(
284                    actor_added_trampoline::<Self, F> as *const (),
285                )),
286                Box_::into_raw(f),
287            )
288        }
289    }
290
291    fn connect_actor_removed<F: Fn(&Self, &Actor) + 'static>(&self, f: F) -> SignalHandlerId {
292        unsafe extern "C" fn actor_removed_trampoline<P, F: Fn(&P, &Actor) + 'static>(
293            this: *mut ffi::ClutterContainer,
294            actor: *mut ffi::ClutterActor,
295            f: glib_sys::gpointer,
296        ) where
297            P: IsA<Container>,
298        {
299            let f: &F = &*(f as *const F);
300            f(
301                &Container::from_glib_borrow(this).unsafe_cast_ref(),
302                &from_glib_borrow(actor),
303            )
304        }
305        unsafe {
306            let f: Box_<F> = Box_::new(f);
307            connect_raw(
308                self.as_ptr() as *mut _,
309                b"actor-removed\0".as_ptr() as *const _,
310                Some(transmute::<_, unsafe extern "C" fn()>(
311                    actor_removed_trampoline::<Self, F> as *const (),
312                )),
313                Box_::into_raw(f),
314            )
315        }
316    }
317
318    fn connect_child_notify<F: Fn(&Self, &Actor, &glib::ParamSpec) + 'static>(
319        &self,
320        f: F,
321    ) -> SignalHandlerId {
322        unsafe extern "C" fn child_notify_trampoline<
323            P,
324            F: Fn(&P, &Actor, &glib::ParamSpec) + 'static,
325        >(
326            this: *mut ffi::ClutterContainer,
327            actor: *mut ffi::ClutterActor,
328            pspec: *mut gobject_sys::GParamSpec,
329            f: glib_sys::gpointer,
330        ) where
331            P: IsA<Container>,
332        {
333            let f: &F = &*(f as *const F);
334            f(
335                &Container::from_glib_borrow(this).unsafe_cast_ref(),
336                &from_glib_borrow(actor),
337                &from_glib_borrow(pspec),
338            )
339        }
340        unsafe {
341            let f: Box_<F> = Box_::new(f);
342            connect_raw(
343                self.as_ptr() as *mut _,
344                b"child-notify\0".as_ptr() as *const _,
345                Some(transmute::<_, unsafe extern "C" fn()>(
346                    child_notify_trampoline::<Self, F> as *const (),
347                )),
348                Box_::into_raw(f),
349            )
350        }
351    }
352}
353
354impl fmt::Display for Container {
355    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
356        write!(f, "Container")
357    }
358}