1use crate::{FlowOrientation, LayoutManager};
2use glib::{
3 object as gobject,
4 object::{Cast, IsA},
5 signal::{connect_raw, SignalHandlerId},
6 translate::*,
7 StaticType, Value,
8};
9use std::boxed::Box as Box_;
10use std::{fmt, mem, mem::transmute};
11
12glib_wrapper! {
13 pub struct FlowLayout(Object<ffi::ClutterFlowLayout, ffi::ClutterFlowLayoutClass, FlowLayoutClass>) @extends LayoutManager, gobject::InitiallyUnowned;
14
15 match fn {
16 get_type => || ffi::clutter_flow_layout_get_type(),
17 }
18}
19
20impl FlowLayout {
21 pub fn new(orientation: FlowOrientation) -> FlowLayout {
29 unsafe {
30 LayoutManager::from_glib_none(ffi::clutter_flow_layout_new(orientation.to_glib()))
31 .unsafe_cast()
32 }
33 }
34}
35
36pub trait FlowLayoutExt: 'static {
42 fn get_column_spacing(&self) -> f32;
49
50 fn get_column_width(&self) -> (f32, f32);
56
57 fn get_homogeneous(&self) -> bool;
63
64 fn get_orientation(&self) -> FlowOrientation;
70
71 fn get_row_height(&self) -> (f32, f32);
77
78 fn get_row_spacing(&self) -> f32;
85
86 fn get_snap_to_grid(&self) -> bool;
92
93 fn set_column_spacing(&self, spacing: f32);
97
98 fn set_column_width(&self, min_width: f32, max_width: f32);
104
105 fn set_homogeneous(&self, homogeneous: bool);
110
111 fn set_orientation(&self, orientation: FlowOrientation);
119
120 fn set_row_height(&self, min_height: f32, max_height: f32);
126
127 fn set_row_spacing(&self, spacing: f32);
131
132 fn set_snap_to_grid(&self, snap_to_grid: bool);
136
137 fn get_property_max_column_width(&self) -> f32;
140
141 fn set_property_max_column_width(&self, max_column_width: f32);
144
145 fn get_property_max_row_height(&self) -> f32;
148
149 fn set_property_max_row_height(&self, max_row_height: f32);
152
153 fn get_property_min_column_width(&self) -> f32;
155
156 fn set_property_min_column_width(&self, min_column_width: f32);
158
159 fn get_property_min_row_height(&self) -> f32;
161
162 fn set_property_min_row_height(&self, min_row_height: f32);
164
165 fn connect_property_column_spacing_notify<F: Fn(&Self) + 'static>(
166 &self,
167 f: F,
168 ) -> SignalHandlerId;
169
170 fn connect_property_homogeneous_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
171
172 fn connect_property_max_column_width_notify<F: Fn(&Self) + 'static>(
173 &self,
174 f: F,
175 ) -> SignalHandlerId;
176
177 fn connect_property_max_row_height_notify<F: Fn(&Self) + 'static>(
178 &self,
179 f: F,
180 ) -> SignalHandlerId;
181
182 fn connect_property_min_column_width_notify<F: Fn(&Self) + 'static>(
183 &self,
184 f: F,
185 ) -> SignalHandlerId;
186
187 fn connect_property_min_row_height_notify<F: Fn(&Self) + 'static>(
188 &self,
189 f: F,
190 ) -> SignalHandlerId;
191
192 fn connect_property_orientation_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
193
194 fn connect_property_row_spacing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
195
196 fn connect_property_snap_to_grid_notify<F: Fn(&Self) + 'static>(&self, f: F)
197 -> SignalHandlerId;
198}
199
200impl<O: IsA<FlowLayout>> FlowLayoutExt for O {
201 fn get_column_spacing(&self) -> f32 {
202 unsafe { ffi::clutter_flow_layout_get_column_spacing(self.as_ref().to_glib_none().0) }
203 }
204
205 fn get_column_width(&self) -> (f32, f32) {
206 unsafe {
207 let mut min_width = mem::MaybeUninit::uninit();
208 let mut max_width = mem::MaybeUninit::uninit();
209 ffi::clutter_flow_layout_get_column_width(
210 self.as_ref().to_glib_none().0,
211 min_width.as_mut_ptr(),
212 max_width.as_mut_ptr(),
213 );
214 let min_width = min_width.assume_init();
215 let max_width = max_width.assume_init();
216 (min_width, max_width)
217 }
218 }
219
220 fn get_homogeneous(&self) -> bool {
221 unsafe {
222 from_glib(ffi::clutter_flow_layout_get_homogeneous(
223 self.as_ref().to_glib_none().0,
224 ))
225 }
226 }
227
228 fn get_orientation(&self) -> FlowOrientation {
229 unsafe {
230 from_glib(ffi::clutter_flow_layout_get_orientation(
231 self.as_ref().to_glib_none().0,
232 ))
233 }
234 }
235
236 fn get_row_height(&self) -> (f32, f32) {
237 unsafe {
238 let mut min_height = mem::MaybeUninit::uninit();
239 let mut max_height = mem::MaybeUninit::uninit();
240 ffi::clutter_flow_layout_get_row_height(
241 self.as_ref().to_glib_none().0,
242 min_height.as_mut_ptr(),
243 max_height.as_mut_ptr(),
244 );
245 let min_height = min_height.assume_init();
246 let max_height = max_height.assume_init();
247 (min_height, max_height)
248 }
249 }
250
251 fn get_row_spacing(&self) -> f32 {
252 unsafe { ffi::clutter_flow_layout_get_row_spacing(self.as_ref().to_glib_none().0) }
253 }
254
255 fn get_snap_to_grid(&self) -> bool {
256 unsafe {
257 from_glib(ffi::clutter_flow_layout_get_snap_to_grid(
258 self.as_ref().to_glib_none().0,
259 ))
260 }
261 }
262
263 fn set_column_spacing(&self, spacing: f32) {
264 unsafe {
265 ffi::clutter_flow_layout_set_column_spacing(self.as_ref().to_glib_none().0, spacing);
266 }
267 }
268
269 fn set_column_width(&self, min_width: f32, max_width: f32) {
270 unsafe {
271 ffi::clutter_flow_layout_set_column_width(
272 self.as_ref().to_glib_none().0,
273 min_width,
274 max_width,
275 );
276 }
277 }
278
279 fn set_homogeneous(&self, homogeneous: bool) {
280 unsafe {
281 ffi::clutter_flow_layout_set_homogeneous(
282 self.as_ref().to_glib_none().0,
283 homogeneous.to_glib(),
284 );
285 }
286 }
287
288 fn set_orientation(&self, orientation: FlowOrientation) {
289 unsafe {
290 ffi::clutter_flow_layout_set_orientation(
291 self.as_ref().to_glib_none().0,
292 orientation.to_glib(),
293 );
294 }
295 }
296
297 fn set_row_height(&self, min_height: f32, max_height: f32) {
298 unsafe {
299 ffi::clutter_flow_layout_set_row_height(
300 self.as_ref().to_glib_none().0,
301 min_height,
302 max_height,
303 );
304 }
305 }
306
307 fn set_row_spacing(&self, spacing: f32) {
308 unsafe {
309 ffi::clutter_flow_layout_set_row_spacing(self.as_ref().to_glib_none().0, spacing);
310 }
311 }
312
313 fn set_snap_to_grid(&self, snap_to_grid: bool) {
314 unsafe {
315 ffi::clutter_flow_layout_set_snap_to_grid(
316 self.as_ref().to_glib_none().0,
317 snap_to_grid.to_glib(),
318 );
319 }
320 }
321
322 fn get_property_max_column_width(&self) -> f32 {
323 unsafe {
324 let mut value = Value::from_type(<f32 as StaticType>::static_type());
325 gobject_sys::g_object_get_property(
326 self.to_glib_none().0 as *mut gobject_sys::GObject,
327 b"max-column-width\0".as_ptr() as *const _,
328 value.to_glib_none_mut().0,
329 );
330 value
331 .get()
332 .expect("Return Value for property `max-column-width` getter")
333 .unwrap()
334 }
335 }
336
337 fn set_property_max_column_width(&self, max_column_width: f32) {
338 unsafe {
339 gobject_sys::g_object_set_property(
340 self.to_glib_none().0 as *mut gobject_sys::GObject,
341 b"max-column-width\0".as_ptr() as *const _,
342 Value::from(&max_column_width).to_glib_none().0,
343 );
344 }
345 }
346
347 fn get_property_max_row_height(&self) -> f32 {
348 unsafe {
349 let mut value = Value::from_type(<f32 as StaticType>::static_type());
350 gobject_sys::g_object_get_property(
351 self.to_glib_none().0 as *mut gobject_sys::GObject,
352 b"max-row-height\0".as_ptr() as *const _,
353 value.to_glib_none_mut().0,
354 );
355 value
356 .get()
357 .expect("Return Value for property `max-row-height` getter")
358 .unwrap()
359 }
360 }
361
362 fn set_property_max_row_height(&self, max_row_height: f32) {
363 unsafe {
364 gobject_sys::g_object_set_property(
365 self.to_glib_none().0 as *mut gobject_sys::GObject,
366 b"max-row-height\0".as_ptr() as *const _,
367 Value::from(&max_row_height).to_glib_none().0,
368 );
369 }
370 }
371
372 fn get_property_min_column_width(&self) -> f32 {
373 unsafe {
374 let mut value = Value::from_type(<f32 as StaticType>::static_type());
375 gobject_sys::g_object_get_property(
376 self.to_glib_none().0 as *mut gobject_sys::GObject,
377 b"min-column-width\0".as_ptr() as *const _,
378 value.to_glib_none_mut().0,
379 );
380 value
381 .get()
382 .expect("Return Value for property `min-column-width` getter")
383 .unwrap()
384 }
385 }
386
387 fn set_property_min_column_width(&self, min_column_width: f32) {
388 unsafe {
389 gobject_sys::g_object_set_property(
390 self.to_glib_none().0 as *mut gobject_sys::GObject,
391 b"min-column-width\0".as_ptr() as *const _,
392 Value::from(&min_column_width).to_glib_none().0,
393 );
394 }
395 }
396
397 fn get_property_min_row_height(&self) -> f32 {
398 unsafe {
399 let mut value = Value::from_type(<f32 as StaticType>::static_type());
400 gobject_sys::g_object_get_property(
401 self.to_glib_none().0 as *mut gobject_sys::GObject,
402 b"min-row-height\0".as_ptr() as *const _,
403 value.to_glib_none_mut().0,
404 );
405 value
406 .get()
407 .expect("Return Value for property `min-row-height` getter")
408 .unwrap()
409 }
410 }
411
412 fn set_property_min_row_height(&self, min_row_height: f32) {
413 unsafe {
414 gobject_sys::g_object_set_property(
415 self.to_glib_none().0 as *mut gobject_sys::GObject,
416 b"min-row-height\0".as_ptr() as *const _,
417 Value::from(&min_row_height).to_glib_none().0,
418 );
419 }
420 }
421
422 fn connect_property_column_spacing_notify<F: Fn(&Self) + 'static>(
423 &self,
424 f: F,
425 ) -> SignalHandlerId {
426 unsafe extern "C" fn notify_column_spacing_trampoline<P, F: Fn(&P) + 'static>(
427 this: *mut ffi::ClutterFlowLayout,
428 _param_spec: glib_sys::gpointer,
429 f: glib_sys::gpointer,
430 ) where
431 P: IsA<FlowLayout>,
432 {
433 let f: &F = &*(f as *const F);
434 f(&FlowLayout::from_glib_borrow(this).unsafe_cast_ref())
435 }
436 unsafe {
437 let f: Box_<F> = Box_::new(f);
438 connect_raw(
439 self.as_ptr() as *mut _,
440 b"notify::column-spacing\0".as_ptr() as *const _,
441 Some(transmute::<_, unsafe extern "C" fn()>(
442 notify_column_spacing_trampoline::<Self, F> as *const (),
443 )),
444 Box_::into_raw(f),
445 )
446 }
447 }
448
449 fn connect_property_homogeneous_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
450 unsafe extern "C" fn notify_homogeneous_trampoline<P, F: Fn(&P) + 'static>(
451 this: *mut ffi::ClutterFlowLayout,
452 _param_spec: glib_sys::gpointer,
453 f: glib_sys::gpointer,
454 ) where
455 P: IsA<FlowLayout>,
456 {
457 let f: &F = &*(f as *const F);
458 f(&FlowLayout::from_glib_borrow(this).unsafe_cast_ref())
459 }
460 unsafe {
461 let f: Box_<F> = Box_::new(f);
462 connect_raw(
463 self.as_ptr() as *mut _,
464 b"notify::homogeneous\0".as_ptr() as *const _,
465 Some(transmute::<_, unsafe extern "C" fn()>(
466 notify_homogeneous_trampoline::<Self, F> as *const (),
467 )),
468 Box_::into_raw(f),
469 )
470 }
471 }
472
473 fn connect_property_max_column_width_notify<F: Fn(&Self) + 'static>(
474 &self,
475 f: F,
476 ) -> SignalHandlerId {
477 unsafe extern "C" fn notify_max_column_width_trampoline<P, F: Fn(&P) + 'static>(
478 this: *mut ffi::ClutterFlowLayout,
479 _param_spec: glib_sys::gpointer,
480 f: glib_sys::gpointer,
481 ) where
482 P: IsA<FlowLayout>,
483 {
484 let f: &F = &*(f as *const F);
485 f(&FlowLayout::from_glib_borrow(this).unsafe_cast_ref())
486 }
487 unsafe {
488 let f: Box_<F> = Box_::new(f);
489 connect_raw(
490 self.as_ptr() as *mut _,
491 b"notify::max-column-width\0".as_ptr() as *const _,
492 Some(transmute::<_, unsafe extern "C" fn()>(
493 notify_max_column_width_trampoline::<Self, F> as *const (),
494 )),
495 Box_::into_raw(f),
496 )
497 }
498 }
499
500 fn connect_property_max_row_height_notify<F: Fn(&Self) + 'static>(
501 &self,
502 f: F,
503 ) -> SignalHandlerId {
504 unsafe extern "C" fn notify_max_row_height_trampoline<P, F: Fn(&P) + 'static>(
505 this: *mut ffi::ClutterFlowLayout,
506 _param_spec: glib_sys::gpointer,
507 f: glib_sys::gpointer,
508 ) where
509 P: IsA<FlowLayout>,
510 {
511 let f: &F = &*(f as *const F);
512 f(&FlowLayout::from_glib_borrow(this).unsafe_cast_ref())
513 }
514 unsafe {
515 let f: Box_<F> = Box_::new(f);
516 connect_raw(
517 self.as_ptr() as *mut _,
518 b"notify::max-row-height\0".as_ptr() as *const _,
519 Some(transmute::<_, unsafe extern "C" fn()>(
520 notify_max_row_height_trampoline::<Self, F> as *const (),
521 )),
522 Box_::into_raw(f),
523 )
524 }
525 }
526
527 fn connect_property_min_column_width_notify<F: Fn(&Self) + 'static>(
528 &self,
529 f: F,
530 ) -> SignalHandlerId {
531 unsafe extern "C" fn notify_min_column_width_trampoline<P, F: Fn(&P) + 'static>(
532 this: *mut ffi::ClutterFlowLayout,
533 _param_spec: glib_sys::gpointer,
534 f: glib_sys::gpointer,
535 ) where
536 P: IsA<FlowLayout>,
537 {
538 let f: &F = &*(f as *const F);
539 f(&FlowLayout::from_glib_borrow(this).unsafe_cast_ref())
540 }
541 unsafe {
542 let f: Box_<F> = Box_::new(f);
543 connect_raw(
544 self.as_ptr() as *mut _,
545 b"notify::min-column-width\0".as_ptr() as *const _,
546 Some(transmute::<_, unsafe extern "C" fn()>(
547 notify_min_column_width_trampoline::<Self, F> as *const (),
548 )),
549 Box_::into_raw(f),
550 )
551 }
552 }
553
554 fn connect_property_min_row_height_notify<F: Fn(&Self) + 'static>(
555 &self,
556 f: F,
557 ) -> SignalHandlerId {
558 unsafe extern "C" fn notify_min_row_height_trampoline<P, F: Fn(&P) + 'static>(
559 this: *mut ffi::ClutterFlowLayout,
560 _param_spec: glib_sys::gpointer,
561 f: glib_sys::gpointer,
562 ) where
563 P: IsA<FlowLayout>,
564 {
565 let f: &F = &*(f as *const F);
566 f(&FlowLayout::from_glib_borrow(this).unsafe_cast_ref())
567 }
568 unsafe {
569 let f: Box_<F> = Box_::new(f);
570 connect_raw(
571 self.as_ptr() as *mut _,
572 b"notify::min-row-height\0".as_ptr() as *const _,
573 Some(transmute::<_, unsafe extern "C" fn()>(
574 notify_min_row_height_trampoline::<Self, F> as *const (),
575 )),
576 Box_::into_raw(f),
577 )
578 }
579 }
580
581 fn connect_property_orientation_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
582 unsafe extern "C" fn notify_orientation_trampoline<P, F: Fn(&P) + 'static>(
583 this: *mut ffi::ClutterFlowLayout,
584 _param_spec: glib_sys::gpointer,
585 f: glib_sys::gpointer,
586 ) where
587 P: IsA<FlowLayout>,
588 {
589 let f: &F = &*(f as *const F);
590 f(&FlowLayout::from_glib_borrow(this).unsafe_cast_ref())
591 }
592 unsafe {
593 let f: Box_<F> = Box_::new(f);
594 connect_raw(
595 self.as_ptr() as *mut _,
596 b"notify::orientation\0".as_ptr() as *const _,
597 Some(transmute::<_, unsafe extern "C" fn()>(
598 notify_orientation_trampoline::<Self, F> as *const (),
599 )),
600 Box_::into_raw(f),
601 )
602 }
603 }
604
605 fn connect_property_row_spacing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
606 unsafe extern "C" fn notify_row_spacing_trampoline<P, F: Fn(&P) + 'static>(
607 this: *mut ffi::ClutterFlowLayout,
608 _param_spec: glib_sys::gpointer,
609 f: glib_sys::gpointer,
610 ) where
611 P: IsA<FlowLayout>,
612 {
613 let f: &F = &*(f as *const F);
614 f(&FlowLayout::from_glib_borrow(this).unsafe_cast_ref())
615 }
616 unsafe {
617 let f: Box_<F> = Box_::new(f);
618 connect_raw(
619 self.as_ptr() as *mut _,
620 b"notify::row-spacing\0".as_ptr() as *const _,
621 Some(transmute::<_, unsafe extern "C" fn()>(
622 notify_row_spacing_trampoline::<Self, F> as *const (),
623 )),
624 Box_::into_raw(f),
625 )
626 }
627 }
628
629 fn connect_property_snap_to_grid_notify<F: Fn(&Self) + 'static>(
630 &self,
631 f: F,
632 ) -> SignalHandlerId {
633 unsafe extern "C" fn notify_snap_to_grid_trampoline<P, F: Fn(&P) + 'static>(
634 this: *mut ffi::ClutterFlowLayout,
635 _param_spec: glib_sys::gpointer,
636 f: glib_sys::gpointer,
637 ) where
638 P: IsA<FlowLayout>,
639 {
640 let f: &F = &*(f as *const F);
641 f(&FlowLayout::from_glib_borrow(this).unsafe_cast_ref())
642 }
643 unsafe {
644 let f: Box_<F> = Box_::new(f);
645 connect_raw(
646 self.as_ptr() as *mut _,
647 b"notify::snap-to-grid\0".as_ptr() as *const _,
648 Some(transmute::<_, unsafe extern "C" fn()>(
649 notify_snap_to_grid_trampoline::<Self, F> as *const (),
650 )),
651 Box_::into_raw(f),
652 )
653 }
654 }
655}
656
657impl fmt::Display for FlowLayout {
658 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
659 write!(f, "FlowLayout")
660 }
661}