clutter/auto/
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
36pub const NONE_FLOW_LAYOUT: Option<&FlowLayout> = None;
37
38/// Trait containing all `FlowLayout` methods.
39///
40/// # Implementors
41///
42/// [`FlowLayout`](struct.FlowLayout.html)
43pub trait FlowLayoutExt: 'static {
44    /// Retrieves the spacing between columns
45    ///
46    /// # Returns
47    ///
48    /// the spacing between columns of the `FlowLayout`,
49    ///  in pixels
50    fn get_column_spacing(&self) -> f32;
51
52    /// Retrieves the minimum and maximum column widths
53    /// ## `min_width`
54    /// return location for the minimum column width, or `None`
55    /// ## `max_width`
56    /// return location for the maximum column width, or `None`
57    fn get_column_width(&self) -> (f32, f32);
58
59    /// Retrieves whether the `self` is homogeneous
60    ///
61    /// # Returns
62    ///
63    /// `true` if the `FlowLayout` is homogeneous
64    fn get_homogeneous(&self) -> bool;
65
66    /// Retrieves the orientation of the `self`
67    ///
68    /// # Returns
69    ///
70    /// the orientation of the `FlowLayout`
71    fn get_orientation(&self) -> FlowOrientation;
72
73    /// Retrieves the minimum and maximum row heights
74    /// ## `min_height`
75    /// return location for the minimum row height, or `None`
76    /// ## `max_height`
77    /// return location for the maximum row height, or `None`
78    fn get_row_height(&self) -> (f32, f32);
79
80    /// Retrieves the spacing between rows
81    ///
82    /// # Returns
83    ///
84    /// the spacing between rows of the `FlowLayout`,
85    ///  in pixels
86    fn get_row_spacing(&self) -> f32;
87
88    /// Retrieves the value of `FlowLayout:snap-to-grid` property
89    ///
90    /// # Returns
91    ///
92    /// `true` if the `self` is placing its children on a grid
93    fn get_snap_to_grid(&self) -> bool;
94
95    /// Sets the space between columns, in pixels
96    /// ## `spacing`
97    /// the space between columns
98    fn set_column_spacing(&self, spacing: f32);
99
100    /// Sets the minimum and maximum widths that a column can have
101    /// ## `min_width`
102    /// minimum width of a column
103    /// ## `max_width`
104    /// maximum width of a column
105    fn set_column_width(&self, min_width: f32, max_width: f32);
106
107    /// Sets whether the `self` should allocate the same space for
108    /// each child
109    /// ## `homogeneous`
110    /// whether the layout should be homogeneous or not
111    fn set_homogeneous(&self, homogeneous: bool);
112
113    /// Sets the orientation of the flow layout
114    ///
115    /// The orientation controls the direction used to allocate
116    /// the children: either horizontally or vertically. The
117    /// orientation also controls the direction of the overflowing
118    /// ## `orientation`
119    /// the orientation of the layout
120    fn set_orientation(&self, orientation: FlowOrientation);
121
122    /// Sets the minimum and maximum heights that a row can have
123    /// ## `min_height`
124    /// the minimum height of a row
125    /// ## `max_height`
126    /// the maximum height of a row
127    fn set_row_height(&self, min_height: f32, max_height: f32);
128
129    /// Sets the spacing between rows, in pixels
130    /// ## `spacing`
131    /// the space between rows
132    fn set_row_spacing(&self, spacing: f32);
133
134    /// Whether the `self` should place its children on a grid.
135    /// ## `snap_to_grid`
136    /// `true` if `self` should place its children on a grid
137    fn set_snap_to_grid(&self, snap_to_grid: bool);
138
139    /// Maximum width for each column in the layout, in pixels. If
140    /// set to -1 the width will be the maximum child width
141    fn get_property_max_column_width(&self) -> f32;
142
143    /// Maximum width for each column in the layout, in pixels. If
144    /// set to -1 the width will be the maximum child width
145    fn set_property_max_column_width(&self, max_column_width: f32);
146
147    /// Maximum height for each row in the layout, in pixels. If
148    /// set to -1 the width will be the maximum child height
149    fn get_property_max_row_height(&self) -> f32;
150
151    /// Maximum height for each row in the layout, in pixels. If
152    /// set to -1 the width will be the maximum child height
153    fn set_property_max_row_height(&self, max_row_height: f32);
154
155    /// Minimum width for each column in the layout, in pixels
156    fn get_property_min_column_width(&self) -> f32;
157
158    /// Minimum width for each column in the layout, in pixels
159    fn set_property_min_column_width(&self, min_column_width: f32);
160
161    /// Minimum height for each row in the layout, in pixels
162    fn get_property_min_row_height(&self) -> f32;
163
164    /// Minimum height for each row in the layout, in pixels
165    fn set_property_min_row_height(&self, min_row_height: f32);
166
167    fn connect_property_column_spacing_notify<F: Fn(&Self) + 'static>(
168        &self,
169        f: F,
170    ) -> SignalHandlerId;
171
172    fn connect_property_homogeneous_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
173
174    fn connect_property_max_column_width_notify<F: Fn(&Self) + 'static>(
175        &self,
176        f: F,
177    ) -> SignalHandlerId;
178
179    fn connect_property_max_row_height_notify<F: Fn(&Self) + 'static>(
180        &self,
181        f: F,
182    ) -> SignalHandlerId;
183
184    fn connect_property_min_column_width_notify<F: Fn(&Self) + 'static>(
185        &self,
186        f: F,
187    ) -> SignalHandlerId;
188
189    fn connect_property_min_row_height_notify<F: Fn(&Self) + 'static>(
190        &self,
191        f: F,
192    ) -> SignalHandlerId;
193
194    fn connect_property_orientation_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
195
196    fn connect_property_row_spacing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
197
198    fn connect_property_snap_to_grid_notify<F: Fn(&Self) + 'static>(&self, f: F)
199        -> SignalHandlerId;
200}
201
202impl<O: IsA<FlowLayout>> FlowLayoutExt for O {
203    fn get_column_spacing(&self) -> f32 {
204        unsafe { ffi::clutter_flow_layout_get_column_spacing(self.as_ref().to_glib_none().0) }
205    }
206
207    fn get_column_width(&self) -> (f32, f32) {
208        unsafe {
209            let mut min_width = mem::MaybeUninit::uninit();
210            let mut max_width = mem::MaybeUninit::uninit();
211            ffi::clutter_flow_layout_get_column_width(
212                self.as_ref().to_glib_none().0,
213                min_width.as_mut_ptr(),
214                max_width.as_mut_ptr(),
215            );
216            let min_width = min_width.assume_init();
217            let max_width = max_width.assume_init();
218            (min_width, max_width)
219        }
220    }
221
222    fn get_homogeneous(&self) -> bool {
223        unsafe {
224            from_glib(ffi::clutter_flow_layout_get_homogeneous(
225                self.as_ref().to_glib_none().0,
226            ))
227        }
228    }
229
230    fn get_orientation(&self) -> FlowOrientation {
231        unsafe {
232            from_glib(ffi::clutter_flow_layout_get_orientation(
233                self.as_ref().to_glib_none().0,
234            ))
235        }
236    }
237
238    fn get_row_height(&self) -> (f32, f32) {
239        unsafe {
240            let mut min_height = mem::MaybeUninit::uninit();
241            let mut max_height = mem::MaybeUninit::uninit();
242            ffi::clutter_flow_layout_get_row_height(
243                self.as_ref().to_glib_none().0,
244                min_height.as_mut_ptr(),
245                max_height.as_mut_ptr(),
246            );
247            let min_height = min_height.assume_init();
248            let max_height = max_height.assume_init();
249            (min_height, max_height)
250        }
251    }
252
253    fn get_row_spacing(&self) -> f32 {
254        unsafe { ffi::clutter_flow_layout_get_row_spacing(self.as_ref().to_glib_none().0) }
255    }
256
257    fn get_snap_to_grid(&self) -> bool {
258        unsafe {
259            from_glib(ffi::clutter_flow_layout_get_snap_to_grid(
260                self.as_ref().to_glib_none().0,
261            ))
262        }
263    }
264
265    fn set_column_spacing(&self, spacing: f32) {
266        unsafe {
267            ffi::clutter_flow_layout_set_column_spacing(self.as_ref().to_glib_none().0, spacing);
268        }
269    }
270
271    fn set_column_width(&self, min_width: f32, max_width: f32) {
272        unsafe {
273            ffi::clutter_flow_layout_set_column_width(
274                self.as_ref().to_glib_none().0,
275                min_width,
276                max_width,
277            );
278        }
279    }
280
281    fn set_homogeneous(&self, homogeneous: bool) {
282        unsafe {
283            ffi::clutter_flow_layout_set_homogeneous(
284                self.as_ref().to_glib_none().0,
285                homogeneous.to_glib(),
286            );
287        }
288    }
289
290    fn set_orientation(&self, orientation: FlowOrientation) {
291        unsafe {
292            ffi::clutter_flow_layout_set_orientation(
293                self.as_ref().to_glib_none().0,
294                orientation.to_glib(),
295            );
296        }
297    }
298
299    fn set_row_height(&self, min_height: f32, max_height: f32) {
300        unsafe {
301            ffi::clutter_flow_layout_set_row_height(
302                self.as_ref().to_glib_none().0,
303                min_height,
304                max_height,
305            );
306        }
307    }
308
309    fn set_row_spacing(&self, spacing: f32) {
310        unsafe {
311            ffi::clutter_flow_layout_set_row_spacing(self.as_ref().to_glib_none().0, spacing);
312        }
313    }
314
315    fn set_snap_to_grid(&self, snap_to_grid: bool) {
316        unsafe {
317            ffi::clutter_flow_layout_set_snap_to_grid(
318                self.as_ref().to_glib_none().0,
319                snap_to_grid.to_glib(),
320            );
321        }
322    }
323
324    fn get_property_max_column_width(&self) -> f32 {
325        unsafe {
326            let mut value = Value::from_type(<f32 as StaticType>::static_type());
327            gobject_sys::g_object_get_property(
328                self.to_glib_none().0 as *mut gobject_sys::GObject,
329                b"max-column-width\0".as_ptr() as *const _,
330                value.to_glib_none_mut().0,
331            );
332            value
333                .get()
334                .expect("Return Value for property `max-column-width` getter")
335                .unwrap()
336        }
337    }
338
339    fn set_property_max_column_width(&self, max_column_width: f32) {
340        unsafe {
341            gobject_sys::g_object_set_property(
342                self.to_glib_none().0 as *mut gobject_sys::GObject,
343                b"max-column-width\0".as_ptr() as *const _,
344                Value::from(&max_column_width).to_glib_none().0,
345            );
346        }
347    }
348
349    fn get_property_max_row_height(&self) -> f32 {
350        unsafe {
351            let mut value = Value::from_type(<f32 as StaticType>::static_type());
352            gobject_sys::g_object_get_property(
353                self.to_glib_none().0 as *mut gobject_sys::GObject,
354                b"max-row-height\0".as_ptr() as *const _,
355                value.to_glib_none_mut().0,
356            );
357            value
358                .get()
359                .expect("Return Value for property `max-row-height` getter")
360                .unwrap()
361        }
362    }
363
364    fn set_property_max_row_height(&self, max_row_height: f32) {
365        unsafe {
366            gobject_sys::g_object_set_property(
367                self.to_glib_none().0 as *mut gobject_sys::GObject,
368                b"max-row-height\0".as_ptr() as *const _,
369                Value::from(&max_row_height).to_glib_none().0,
370            );
371        }
372    }
373
374    fn get_property_min_column_width(&self) -> f32 {
375        unsafe {
376            let mut value = Value::from_type(<f32 as StaticType>::static_type());
377            gobject_sys::g_object_get_property(
378                self.to_glib_none().0 as *mut gobject_sys::GObject,
379                b"min-column-width\0".as_ptr() as *const _,
380                value.to_glib_none_mut().0,
381            );
382            value
383                .get()
384                .expect("Return Value for property `min-column-width` getter")
385                .unwrap()
386        }
387    }
388
389    fn set_property_min_column_width(&self, min_column_width: f32) {
390        unsafe {
391            gobject_sys::g_object_set_property(
392                self.to_glib_none().0 as *mut gobject_sys::GObject,
393                b"min-column-width\0".as_ptr() as *const _,
394                Value::from(&min_column_width).to_glib_none().0,
395            );
396        }
397    }
398
399    fn get_property_min_row_height(&self) -> f32 {
400        unsafe {
401            let mut value = Value::from_type(<f32 as StaticType>::static_type());
402            gobject_sys::g_object_get_property(
403                self.to_glib_none().0 as *mut gobject_sys::GObject,
404                b"min-row-height\0".as_ptr() as *const _,
405                value.to_glib_none_mut().0,
406            );
407            value
408                .get()
409                .expect("Return Value for property `min-row-height` getter")
410                .unwrap()
411        }
412    }
413
414    fn set_property_min_row_height(&self, min_row_height: f32) {
415        unsafe {
416            gobject_sys::g_object_set_property(
417                self.to_glib_none().0 as *mut gobject_sys::GObject,
418                b"min-row-height\0".as_ptr() as *const _,
419                Value::from(&min_row_height).to_glib_none().0,
420            );
421        }
422    }
423
424    fn connect_property_column_spacing_notify<F: Fn(&Self) + 'static>(
425        &self,
426        f: F,
427    ) -> SignalHandlerId {
428        unsafe extern "C" fn notify_column_spacing_trampoline<P, F: Fn(&P) + 'static>(
429            this: *mut ffi::ClutterFlowLayout,
430            _param_spec: glib_sys::gpointer,
431            f: glib_sys::gpointer,
432        ) where
433            P: IsA<FlowLayout>,
434        {
435            let f: &F = &*(f as *const F);
436            f(&FlowLayout::from_glib_borrow(this).unsafe_cast_ref())
437        }
438        unsafe {
439            let f: Box_<F> = Box_::new(f);
440            connect_raw(
441                self.as_ptr() as *mut _,
442                b"notify::column-spacing\0".as_ptr() as *const _,
443                Some(transmute::<_, unsafe extern "C" fn()>(
444                    notify_column_spacing_trampoline::<Self, F> as *const (),
445                )),
446                Box_::into_raw(f),
447            )
448        }
449    }
450
451    fn connect_property_homogeneous_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
452        unsafe extern "C" fn notify_homogeneous_trampoline<P, F: Fn(&P) + 'static>(
453            this: *mut ffi::ClutterFlowLayout,
454            _param_spec: glib_sys::gpointer,
455            f: glib_sys::gpointer,
456        ) where
457            P: IsA<FlowLayout>,
458        {
459            let f: &F = &*(f as *const F);
460            f(&FlowLayout::from_glib_borrow(this).unsafe_cast_ref())
461        }
462        unsafe {
463            let f: Box_<F> = Box_::new(f);
464            connect_raw(
465                self.as_ptr() as *mut _,
466                b"notify::homogeneous\0".as_ptr() as *const _,
467                Some(transmute::<_, unsafe extern "C" fn()>(
468                    notify_homogeneous_trampoline::<Self, F> as *const (),
469                )),
470                Box_::into_raw(f),
471            )
472        }
473    }
474
475    fn connect_property_max_column_width_notify<F: Fn(&Self) + 'static>(
476        &self,
477        f: F,
478    ) -> SignalHandlerId {
479        unsafe extern "C" fn notify_max_column_width_trampoline<P, F: Fn(&P) + 'static>(
480            this: *mut ffi::ClutterFlowLayout,
481            _param_spec: glib_sys::gpointer,
482            f: glib_sys::gpointer,
483        ) where
484            P: IsA<FlowLayout>,
485        {
486            let f: &F = &*(f as *const F);
487            f(&FlowLayout::from_glib_borrow(this).unsafe_cast_ref())
488        }
489        unsafe {
490            let f: Box_<F> = Box_::new(f);
491            connect_raw(
492                self.as_ptr() as *mut _,
493                b"notify::max-column-width\0".as_ptr() as *const _,
494                Some(transmute::<_, unsafe extern "C" fn()>(
495                    notify_max_column_width_trampoline::<Self, F> as *const (),
496                )),
497                Box_::into_raw(f),
498            )
499        }
500    }
501
502    fn connect_property_max_row_height_notify<F: Fn(&Self) + 'static>(
503        &self,
504        f: F,
505    ) -> SignalHandlerId {
506        unsafe extern "C" fn notify_max_row_height_trampoline<P, F: Fn(&P) + 'static>(
507            this: *mut ffi::ClutterFlowLayout,
508            _param_spec: glib_sys::gpointer,
509            f: glib_sys::gpointer,
510        ) where
511            P: IsA<FlowLayout>,
512        {
513            let f: &F = &*(f as *const F);
514            f(&FlowLayout::from_glib_borrow(this).unsafe_cast_ref())
515        }
516        unsafe {
517            let f: Box_<F> = Box_::new(f);
518            connect_raw(
519                self.as_ptr() as *mut _,
520                b"notify::max-row-height\0".as_ptr() as *const _,
521                Some(transmute::<_, unsafe extern "C" fn()>(
522                    notify_max_row_height_trampoline::<Self, F> as *const (),
523                )),
524                Box_::into_raw(f),
525            )
526        }
527    }
528
529    fn connect_property_min_column_width_notify<F: Fn(&Self) + 'static>(
530        &self,
531        f: F,
532    ) -> SignalHandlerId {
533        unsafe extern "C" fn notify_min_column_width_trampoline<P, F: Fn(&P) + 'static>(
534            this: *mut ffi::ClutterFlowLayout,
535            _param_spec: glib_sys::gpointer,
536            f: glib_sys::gpointer,
537        ) where
538            P: IsA<FlowLayout>,
539        {
540            let f: &F = &*(f as *const F);
541            f(&FlowLayout::from_glib_borrow(this).unsafe_cast_ref())
542        }
543        unsafe {
544            let f: Box_<F> = Box_::new(f);
545            connect_raw(
546                self.as_ptr() as *mut _,
547                b"notify::min-column-width\0".as_ptr() as *const _,
548                Some(transmute::<_, unsafe extern "C" fn()>(
549                    notify_min_column_width_trampoline::<Self, F> as *const (),
550                )),
551                Box_::into_raw(f),
552            )
553        }
554    }
555
556    fn connect_property_min_row_height_notify<F: Fn(&Self) + 'static>(
557        &self,
558        f: F,
559    ) -> SignalHandlerId {
560        unsafe extern "C" fn notify_min_row_height_trampoline<P, F: Fn(&P) + 'static>(
561            this: *mut ffi::ClutterFlowLayout,
562            _param_spec: glib_sys::gpointer,
563            f: glib_sys::gpointer,
564        ) where
565            P: IsA<FlowLayout>,
566        {
567            let f: &F = &*(f as *const F);
568            f(&FlowLayout::from_glib_borrow(this).unsafe_cast_ref())
569        }
570        unsafe {
571            let f: Box_<F> = Box_::new(f);
572            connect_raw(
573                self.as_ptr() as *mut _,
574                b"notify::min-row-height\0".as_ptr() as *const _,
575                Some(transmute::<_, unsafe extern "C" fn()>(
576                    notify_min_row_height_trampoline::<Self, F> as *const (),
577                )),
578                Box_::into_raw(f),
579            )
580        }
581    }
582
583    fn connect_property_orientation_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
584        unsafe extern "C" fn notify_orientation_trampoline<P, F: Fn(&P) + 'static>(
585            this: *mut ffi::ClutterFlowLayout,
586            _param_spec: glib_sys::gpointer,
587            f: glib_sys::gpointer,
588        ) where
589            P: IsA<FlowLayout>,
590        {
591            let f: &F = &*(f as *const F);
592            f(&FlowLayout::from_glib_borrow(this).unsafe_cast_ref())
593        }
594        unsafe {
595            let f: Box_<F> = Box_::new(f);
596            connect_raw(
597                self.as_ptr() as *mut _,
598                b"notify::orientation\0".as_ptr() as *const _,
599                Some(transmute::<_, unsafe extern "C" fn()>(
600                    notify_orientation_trampoline::<Self, F> as *const (),
601                )),
602                Box_::into_raw(f),
603            )
604        }
605    }
606
607    fn connect_property_row_spacing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
608        unsafe extern "C" fn notify_row_spacing_trampoline<P, F: Fn(&P) + 'static>(
609            this: *mut ffi::ClutterFlowLayout,
610            _param_spec: glib_sys::gpointer,
611            f: glib_sys::gpointer,
612        ) where
613            P: IsA<FlowLayout>,
614        {
615            let f: &F = &*(f as *const F);
616            f(&FlowLayout::from_glib_borrow(this).unsafe_cast_ref())
617        }
618        unsafe {
619            let f: Box_<F> = Box_::new(f);
620            connect_raw(
621                self.as_ptr() as *mut _,
622                b"notify::row-spacing\0".as_ptr() as *const _,
623                Some(transmute::<_, unsafe extern "C" fn()>(
624                    notify_row_spacing_trampoline::<Self, F> as *const (),
625                )),
626                Box_::into_raw(f),
627            )
628        }
629    }
630
631    fn connect_property_snap_to_grid_notify<F: Fn(&Self) + 'static>(
632        &self,
633        f: F,
634    ) -> SignalHandlerId {
635        unsafe extern "C" fn notify_snap_to_grid_trampoline<P, F: Fn(&P) + 'static>(
636            this: *mut ffi::ClutterFlowLayout,
637            _param_spec: glib_sys::gpointer,
638            f: glib_sys::gpointer,
639        ) where
640            P: IsA<FlowLayout>,
641        {
642            let f: &F = &*(f as *const F);
643            f(&FlowLayout::from_glib_borrow(this).unsafe_cast_ref())
644        }
645        unsafe {
646            let f: Box_<F> = Box_::new(f);
647            connect_raw(
648                self.as_ptr() as *mut _,
649                b"notify::snap-to-grid\0".as_ptr() as *const _,
650                Some(transmute::<_, unsafe extern "C" fn()>(
651                    notify_snap_to_grid_trampoline::<Self, F> as *const (),
652                )),
653                Box_::into_raw(f),
654            )
655        }
656    }
657}
658
659impl fmt::Display for FlowLayout {
660    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
661        write!(f, "FlowLayout")
662    }
663}