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