animate/legacy/
flow_layout.rs

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    /// Creates a new `FlowLayout` with the given `orientation`
22    /// ## `orientation`
23    /// the orientation of the flow layout
24    ///
25    /// # Returns
26    ///
27    /// the newly created `FlowLayout`
28    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
36/// Trait containing all `FlowLayout` methods.
37///
38/// # Implementors
39///
40/// [`FlowLayout`](struct.FlowLayout.html)
41pub trait FlowLayoutExt: 'static {
42    /// Retrieves the spacing between columns
43    ///
44    /// # Returns
45    ///
46    /// the spacing between columns of the `FlowLayout`,
47    ///  in pixels
48    fn get_column_spacing(&self) -> f32;
49
50    /// Retrieves the minimum and maximum column widths
51    /// ## `min_width`
52    /// return location for the minimum column width, or `None`
53    /// ## `max_width`
54    /// return location for the maximum column width, or `None`
55    fn get_column_width(&self) -> (f32, f32);
56
57    /// Retrieves whether the `self` is homogeneous
58    ///
59    /// # Returns
60    ///
61    /// `true` if the `FlowLayout` is homogeneous
62    fn get_homogeneous(&self) -> bool;
63
64    /// Retrieves the orientation of the `self`
65    ///
66    /// # Returns
67    ///
68    /// the orientation of the `FlowLayout`
69    fn get_orientation(&self) -> FlowOrientation;
70
71    /// Retrieves the minimum and maximum row heights
72    /// ## `min_height`
73    /// return location for the minimum row height, or `None`
74    /// ## `max_height`
75    /// return location for the maximum row height, or `None`
76    fn get_row_height(&self) -> (f32, f32);
77
78    /// Retrieves the spacing between rows
79    ///
80    /// # Returns
81    ///
82    /// the spacing between rows of the `FlowLayout`,
83    ///  in pixels
84    fn get_row_spacing(&self) -> f32;
85
86    /// Retrieves the value of `FlowLayout:snap-to-grid` property
87    ///
88    /// # Returns
89    ///
90    /// `true` if the `self` is placing its children on a grid
91    fn get_snap_to_grid(&self) -> bool;
92
93    /// Sets the space between columns, in pixels
94    /// ## `spacing`
95    /// the space between columns
96    fn set_column_spacing(&self, spacing: f32);
97
98    /// Sets the minimum and maximum widths that a column can have
99    /// ## `min_width`
100    /// minimum width of a column
101    /// ## `max_width`
102    /// maximum width of a column
103    fn set_column_width(&self, min_width: f32, max_width: f32);
104
105    /// Sets whether the `self` should allocate the same space for
106    /// each child
107    /// ## `homogeneous`
108    /// whether the layout should be homogeneous or not
109    fn set_homogeneous(&self, homogeneous: bool);
110
111    /// Sets the orientation of the flow layout
112    ///
113    /// The orientation controls the direction used to allocate
114    /// the children: either horizontally or vertically. The
115    /// orientation also controls the direction of the overflowing
116    /// ## `orientation`
117    /// the orientation of the layout
118    fn set_orientation(&self, orientation: FlowOrientation);
119
120    /// Sets the minimum and maximum heights that a row can have
121    /// ## `min_height`
122    /// the minimum height of a row
123    /// ## `max_height`
124    /// the maximum height of a row
125    fn set_row_height(&self, min_height: f32, max_height: f32);
126
127    /// Sets the spacing between rows, in pixels
128    /// ## `spacing`
129    /// the space between rows
130    fn set_row_spacing(&self, spacing: f32);
131
132    /// Whether the `self` should place its children on a grid.
133    /// ## `snap_to_grid`
134    /// `true` if `self` should place its children on a grid
135    fn set_snap_to_grid(&self, snap_to_grid: bool);
136
137    /// Maximum width for each column in the layout, in pixels. If
138    /// set to -1 the width will be the maximum child width
139    fn get_property_max_column_width(&self) -> f32;
140
141    /// Maximum width for each column in the layout, in pixels. If
142    /// set to -1 the width will be the maximum child width
143    fn set_property_max_column_width(&self, max_column_width: f32);
144
145    /// Maximum height for each row in the layout, in pixels. If
146    /// set to -1 the width will be the maximum child height
147    fn get_property_max_row_height(&self) -> f32;
148
149    /// Maximum height for each row in the layout, in pixels. If
150    /// set to -1 the width will be the maximum child height
151    fn set_property_max_row_height(&self, max_row_height: f32);
152
153    /// Minimum width for each column in the layout, in pixels
154    fn get_property_min_column_width(&self) -> f32;
155
156    /// Minimum width for each column in the layout, in pixels
157    fn set_property_min_column_width(&self, min_column_width: f32);
158
159    /// Minimum height for each row in the layout, in pixels
160    fn get_property_min_row_height(&self) -> f32;
161
162    /// Minimum height for each row in the layout, in pixels
163    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}