1use crate::{Actor, GridPosition, LayoutManager, Orientation};
2use glib::{
3 object as gobject,
4 object::{Cast, IsA},
5 signal::{connect_raw, SignalHandlerId},
6 translate::*,
7};
8use std::boxed::Box as Box_;
9use std::{fmt, mem::transmute};
10
11glib_wrapper! {
12 pub struct GridLayout(Object<ffi::ClutterGridLayout, ffi::ClutterGridLayoutClass, GridLayoutClass>) @extends LayoutManager, gobject::InitiallyUnowned;
13
14 match fn {
15 get_type => || ffi::clutter_grid_layout_get_type(),
16 }
17}
18
19impl GridLayout {
20 pub fn new() -> GridLayout {
26 unsafe { LayoutManager::from_glib_none(ffi::clutter_grid_layout_new()).unsafe_cast() }
27 }
28}
29
30impl Default for GridLayout {
31 fn default() -> Self {
32 Self::new()
33 }
34}
35
36pub trait GridLayoutExt: 'static {
42 fn attach<P: IsA<Actor>>(&self, child: &P, left: i32, top: i32, width: i32, height: i32);
58
59 fn attach_next_to<P: IsA<Actor>, Q: IsA<Actor>>(
80 &self,
81 child: &P,
82 sibling: Option<&Q>,
83 side: GridPosition,
84 width: i32,
85 height: i32,
86 );
87
88 fn get_child_at(&self, left: i32, top: i32) -> Option<Actor>;
99
100 fn get_column_homogeneous(&self) -> bool;
106
107 fn get_column_spacing(&self) -> u32;
113
114 fn get_orientation(&self) -> Orientation;
120
121 fn get_row_homogeneous(&self) -> bool;
127
128 fn get_row_spacing(&self) -> u32;
134
135 fn insert_column(&self, position: i32);
143
144 fn insert_next_to<P: IsA<Actor>>(&self, sibling: &P, side: GridPosition);
157
158 fn insert_row(&self, position: i32);
166
167 fn set_column_homogeneous(&self, homogeneous: bool);
171
172 fn set_column_spacing(&self, spacing: u32);
176
177 fn set_orientation(&self, orientation: Orientation);
186
187 fn set_row_homogeneous(&self, homogeneous: bool);
191
192 fn set_row_spacing(&self, spacing: u32);
196
197 fn connect_property_column_homogeneous_notify<F: Fn(&Self) + 'static>(
198 &self,
199 f: F,
200 ) -> SignalHandlerId;
201
202 fn connect_property_column_spacing_notify<F: Fn(&Self) + 'static>(
203 &self,
204 f: F,
205 ) -> SignalHandlerId;
206
207 fn connect_property_orientation_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
208
209 fn connect_property_row_homogeneous_notify<F: Fn(&Self) + 'static>(
210 &self,
211 f: F,
212 ) -> SignalHandlerId;
213
214 fn connect_property_row_spacing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
215}
216
217impl<O: IsA<GridLayout>> GridLayoutExt for O {
218 fn attach<P: IsA<Actor>>(&self, child: &P, left: i32, top: i32, width: i32, height: i32) {
219 unsafe {
220 ffi::clutter_grid_layout_attach(
221 self.as_ref().to_glib_none().0,
222 child.as_ref().to_glib_none().0,
223 left,
224 top,
225 width,
226 height,
227 );
228 }
229 }
230
231 fn attach_next_to<P: IsA<Actor>, Q: IsA<Actor>>(
232 &self,
233 child: &P,
234 sibling: Option<&Q>,
235 side: GridPosition,
236 width: i32,
237 height: i32,
238 ) {
239 unsafe {
240 ffi::clutter_grid_layout_attach_next_to(
241 self.as_ref().to_glib_none().0,
242 child.as_ref().to_glib_none().0,
243 sibling.map(|p| p.as_ref()).to_glib_none().0,
244 side.to_glib(),
245 width,
246 height,
247 );
248 }
249 }
250
251 fn get_child_at(&self, left: i32, top: i32) -> Option<Actor> {
252 unsafe {
253 from_glib_none(ffi::clutter_grid_layout_get_child_at(
254 self.as_ref().to_glib_none().0,
255 left,
256 top,
257 ))
258 }
259 }
260
261 fn get_column_homogeneous(&self) -> bool {
262 unsafe {
263 from_glib(ffi::clutter_grid_layout_get_column_homogeneous(
264 self.as_ref().to_glib_none().0,
265 ))
266 }
267 }
268
269 fn get_column_spacing(&self) -> u32 {
270 unsafe { ffi::clutter_grid_layout_get_column_spacing(self.as_ref().to_glib_none().0) }
271 }
272
273 fn get_orientation(&self) -> Orientation {
274 unsafe {
275 from_glib(ffi::clutter_grid_layout_get_orientation(
276 self.as_ref().to_glib_none().0,
277 ))
278 }
279 }
280
281 fn get_row_homogeneous(&self) -> bool {
282 unsafe {
283 from_glib(ffi::clutter_grid_layout_get_row_homogeneous(
284 self.as_ref().to_glib_none().0,
285 ))
286 }
287 }
288
289 fn get_row_spacing(&self) -> u32 {
290 unsafe { ffi::clutter_grid_layout_get_row_spacing(self.as_ref().to_glib_none().0) }
291 }
292
293 fn insert_column(&self, position: i32) {
294 unsafe {
295 ffi::clutter_grid_layout_insert_column(self.as_ref().to_glib_none().0, position);
296 }
297 }
298
299 fn insert_next_to<P: IsA<Actor>>(&self, sibling: &P, side: GridPosition) {
300 unsafe {
301 ffi::clutter_grid_layout_insert_next_to(
302 self.as_ref().to_glib_none().0,
303 sibling.as_ref().to_glib_none().0,
304 side.to_glib(),
305 );
306 }
307 }
308
309 fn insert_row(&self, position: i32) {
310 unsafe {
311 ffi::clutter_grid_layout_insert_row(self.as_ref().to_glib_none().0, position);
312 }
313 }
314
315 fn set_column_homogeneous(&self, homogeneous: bool) {
316 unsafe {
317 ffi::clutter_grid_layout_set_column_homogeneous(
318 self.as_ref().to_glib_none().0,
319 homogeneous.to_glib(),
320 );
321 }
322 }
323
324 fn set_column_spacing(&self, spacing: u32) {
325 unsafe {
326 ffi::clutter_grid_layout_set_column_spacing(self.as_ref().to_glib_none().0, spacing);
327 }
328 }
329
330 fn set_orientation(&self, orientation: Orientation) {
331 unsafe {
332 ffi::clutter_grid_layout_set_orientation(
333 self.as_ref().to_glib_none().0,
334 orientation.to_glib(),
335 );
336 }
337 }
338
339 fn set_row_homogeneous(&self, homogeneous: bool) {
340 unsafe {
341 ffi::clutter_grid_layout_set_row_homogeneous(
342 self.as_ref().to_glib_none().0,
343 homogeneous.to_glib(),
344 );
345 }
346 }
347
348 fn set_row_spacing(&self, spacing: u32) {
349 unsafe {
350 ffi::clutter_grid_layout_set_row_spacing(self.as_ref().to_glib_none().0, spacing);
351 }
352 }
353
354 fn connect_property_column_homogeneous_notify<F: Fn(&Self) + 'static>(
355 &self,
356 f: F,
357 ) -> SignalHandlerId {
358 unsafe extern "C" fn notify_column_homogeneous_trampoline<P, F: Fn(&P) + 'static>(
359 this: *mut ffi::ClutterGridLayout,
360 _param_spec: glib_sys::gpointer,
361 f: glib_sys::gpointer,
362 ) where
363 P: IsA<GridLayout>,
364 {
365 let f: &F = &*(f as *const F);
366 f(&GridLayout::from_glib_borrow(this).unsafe_cast_ref())
367 }
368 unsafe {
369 let f: Box_<F> = Box_::new(f);
370 connect_raw(
371 self.as_ptr() as *mut _,
372 b"notify::column-homogeneous\0".as_ptr() as *const _,
373 Some(transmute::<_, unsafe extern "C" fn()>(
374 notify_column_homogeneous_trampoline::<Self, F> as *const (),
375 )),
376 Box_::into_raw(f),
377 )
378 }
379 }
380
381 fn connect_property_column_spacing_notify<F: Fn(&Self) + 'static>(
382 &self,
383 f: F,
384 ) -> SignalHandlerId {
385 unsafe extern "C" fn notify_column_spacing_trampoline<P, F: Fn(&P) + 'static>(
386 this: *mut ffi::ClutterGridLayout,
387 _param_spec: glib_sys::gpointer,
388 f: glib_sys::gpointer,
389 ) where
390 P: IsA<GridLayout>,
391 {
392 let f: &F = &*(f as *const F);
393 f(&GridLayout::from_glib_borrow(this).unsafe_cast_ref())
394 }
395 unsafe {
396 let f: Box_<F> = Box_::new(f);
397 connect_raw(
398 self.as_ptr() as *mut _,
399 b"notify::column-spacing\0".as_ptr() as *const _,
400 Some(transmute::<_, unsafe extern "C" fn()>(
401 notify_column_spacing_trampoline::<Self, F> as *const (),
402 )),
403 Box_::into_raw(f),
404 )
405 }
406 }
407
408 fn connect_property_orientation_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
409 unsafe extern "C" fn notify_orientation_trampoline<P, F: Fn(&P) + 'static>(
410 this: *mut ffi::ClutterGridLayout,
411 _param_spec: glib_sys::gpointer,
412 f: glib_sys::gpointer,
413 ) where
414 P: IsA<GridLayout>,
415 {
416 let f: &F = &*(f as *const F);
417 f(&GridLayout::from_glib_borrow(this).unsafe_cast_ref())
418 }
419 unsafe {
420 let f: Box_<F> = Box_::new(f);
421 connect_raw(
422 self.as_ptr() as *mut _,
423 b"notify::orientation\0".as_ptr() as *const _,
424 Some(transmute::<_, unsafe extern "C" fn()>(
425 notify_orientation_trampoline::<Self, F> as *const (),
426 )),
427 Box_::into_raw(f),
428 )
429 }
430 }
431
432 fn connect_property_row_homogeneous_notify<F: Fn(&Self) + 'static>(
433 &self,
434 f: F,
435 ) -> SignalHandlerId {
436 unsafe extern "C" fn notify_row_homogeneous_trampoline<P, F: Fn(&P) + 'static>(
437 this: *mut ffi::ClutterGridLayout,
438 _param_spec: glib_sys::gpointer,
439 f: glib_sys::gpointer,
440 ) where
441 P: IsA<GridLayout>,
442 {
443 let f: &F = &*(f as *const F);
444 f(&GridLayout::from_glib_borrow(this).unsafe_cast_ref())
445 }
446 unsafe {
447 let f: Box_<F> = Box_::new(f);
448 connect_raw(
449 self.as_ptr() as *mut _,
450 b"notify::row-homogeneous\0".as_ptr() as *const _,
451 Some(transmute::<_, unsafe extern "C" fn()>(
452 notify_row_homogeneous_trampoline::<Self, F> as *const (),
453 )),
454 Box_::into_raw(f),
455 )
456 }
457 }
458
459 fn connect_property_row_spacing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
460 unsafe extern "C" fn notify_row_spacing_trampoline<P, F: Fn(&P) + 'static>(
461 this: *mut ffi::ClutterGridLayout,
462 _param_spec: glib_sys::gpointer,
463 f: glib_sys::gpointer,
464 ) where
465 P: IsA<GridLayout>,
466 {
467 let f: &F = &*(f as *const F);
468 f(&GridLayout::from_glib_borrow(this).unsafe_cast_ref())
469 }
470 unsafe {
471 let f: Box_<F> = Box_::new(f);
472 connect_raw(
473 self.as_ptr() as *mut _,
474 b"notify::row-spacing\0".as_ptr() as *const _,
475 Some(transmute::<_, unsafe extern "C" fn()>(
476 notify_row_spacing_trampoline::<Self, F> as *const (),
477 )),
478 Box_::into_raw(f),
479 )
480 }
481 }
482}
483
484impl fmt::Display for GridLayout {
485 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
486 write!(f, "GridLayout")
487 }
488}