Skip to main content

gtk4/auto/
grid_layout.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{BaselinePosition, LayoutManager, ffi};
6use glib::{
7    prelude::*,
8    signal::{SignalHandlerId, connect_raw},
9    translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14    /// Arranges child widgets in rows and columns.
15    ///
16    /// Children have an "attach point" defined by the horizontal and vertical
17    /// index of the cell they occupy; children can span multiple rows or columns.
18    /// The layout properties for setting the attach points and spans are set
19    /// using the [`GridLayoutChild`][crate::GridLayoutChild] associated to each child widget.
20    ///
21    /// The behaviour of [`GridLayout`][crate::GridLayout] when several children occupy the same
22    /// grid cell is undefined.
23    ///
24    /// [`GridLayout`][crate::GridLayout] can be used like a [`BoxLayout`][crate::BoxLayout] if all children are
25    /// attached to the same row or column; however, if you only ever need a
26    /// single row or column, you should consider using [`BoxLayout`][crate::BoxLayout].
27    ///
28    /// ## Properties
29    ///
30    ///
31    /// #### `baseline-row`
32    ///  The row to align to the baseline, when `GtkWidget:valign` is set
33    /// to [`Align::Baseline`][crate::Align::Baseline].
34    ///
35    /// Readable | Writeable
36    ///
37    ///
38    /// #### `column-homogeneous`
39    ///  Whether all the columns in the grid have the same width.
40    ///
41    /// Readable | Writeable
42    ///
43    ///
44    /// #### `column-spacing`
45    ///  The amount of space between to consecutive columns.
46    ///
47    /// Readable | Writeable
48    ///
49    ///
50    /// #### `row-homogeneous`
51    ///  Whether all the rows in the grid have the same height.
52    ///
53    /// Readable | Writeable
54    ///
55    ///
56    /// #### `row-spacing`
57    ///  The amount of space between to consecutive rows.
58    ///
59    /// Readable | Writeable
60    ///
61    /// # Implements
62    ///
63    /// [`LayoutManagerExt`][trait@crate::prelude::LayoutManagerExt], [`trait@glib::ObjectExt`]
64    #[doc(alias = "GtkGridLayout")]
65    pub struct GridLayout(Object<ffi::GtkGridLayout, ffi::GtkGridLayoutClass>) @extends LayoutManager;
66
67    match fn {
68        type_ => || ffi::gtk_grid_layout_get_type(),
69    }
70}
71
72impl GridLayout {
73    /// Creates a new [`GridLayout`][crate::GridLayout].
74    ///
75    /// # Returns
76    ///
77    /// the newly created [`GridLayout`][crate::GridLayout]
78    #[doc(alias = "gtk_grid_layout_new")]
79    pub fn new() -> GridLayout {
80        assert_initialized_main_thread!();
81        unsafe { LayoutManager::from_glib_full(ffi::gtk_grid_layout_new()).unsafe_cast() }
82    }
83
84    // rustdoc-stripper-ignore-next
85    /// Creates a new builder-pattern struct instance to construct [`GridLayout`] objects.
86    ///
87    /// This method returns an instance of [`GridLayoutBuilder`](crate::builders::GridLayoutBuilder) which can be used to create [`GridLayout`] objects.
88    pub fn builder() -> GridLayoutBuilder {
89        GridLayoutBuilder::new()
90    }
91
92    /// Retrieves the row set with gtk_grid_layout_set_baseline_row().
93    ///
94    /// # Returns
95    ///
96    /// the global baseline row
97    #[doc(alias = "gtk_grid_layout_get_baseline_row")]
98    #[doc(alias = "get_baseline_row")]
99    #[doc(alias = "baseline-row")]
100    pub fn baseline_row(&self) -> i32 {
101        unsafe { ffi::gtk_grid_layout_get_baseline_row(self.to_glib_none().0) }
102    }
103
104    /// Checks whether all columns of @self should have the same width.
105    ///
106    /// # Returns
107    ///
108    /// [`true`] if the columns are homogeneous, and [`false`] otherwise
109    #[doc(alias = "gtk_grid_layout_get_column_homogeneous")]
110    #[doc(alias = "get_column_homogeneous")]
111    #[doc(alias = "column-homogeneous")]
112    pub fn is_column_homogeneous(&self) -> bool {
113        unsafe {
114            from_glib(ffi::gtk_grid_layout_get_column_homogeneous(
115                self.to_glib_none().0,
116            ))
117        }
118    }
119
120    /// Retrieves the spacing set with gtk_grid_layout_set_column_spacing().
121    ///
122    /// # Returns
123    ///
124    /// the spacing between consecutive columns
125    #[doc(alias = "gtk_grid_layout_get_column_spacing")]
126    #[doc(alias = "get_column_spacing")]
127    #[doc(alias = "column-spacing")]
128    pub fn column_spacing(&self) -> u32 {
129        unsafe { ffi::gtk_grid_layout_get_column_spacing(self.to_glib_none().0) }
130    }
131
132    /// Returns the baseline position of @row.
133    ///
134    /// If no value has been set with
135    /// [`set_row_baseline_position()`][Self::set_row_baseline_position()],
136    /// the default value of [`BaselinePosition::Center`][crate::BaselinePosition::Center]
137    /// is returned.
138    /// ## `row`
139    /// a row index
140    ///
141    /// # Returns
142    ///
143    /// the baseline position of @row
144    #[doc(alias = "gtk_grid_layout_get_row_baseline_position")]
145    #[doc(alias = "get_row_baseline_position")]
146    pub fn row_baseline_position(&self, row: i32) -> BaselinePosition {
147        unsafe {
148            from_glib(ffi::gtk_grid_layout_get_row_baseline_position(
149                self.to_glib_none().0,
150                row,
151            ))
152        }
153    }
154
155    /// Checks whether all rows of @self should have the same height.
156    ///
157    /// # Returns
158    ///
159    /// [`true`] if the rows are homogeneous, and [`false`] otherwise
160    #[doc(alias = "gtk_grid_layout_get_row_homogeneous")]
161    #[doc(alias = "get_row_homogeneous")]
162    #[doc(alias = "row-homogeneous")]
163    pub fn is_row_homogeneous(&self) -> bool {
164        unsafe {
165            from_glib(ffi::gtk_grid_layout_get_row_homogeneous(
166                self.to_glib_none().0,
167            ))
168        }
169    }
170
171    /// Retrieves the spacing set with gtk_grid_layout_set_row_spacing().
172    ///
173    /// # Returns
174    ///
175    /// the spacing between consecutive rows
176    #[doc(alias = "gtk_grid_layout_get_row_spacing")]
177    #[doc(alias = "get_row_spacing")]
178    #[doc(alias = "row-spacing")]
179    pub fn row_spacing(&self) -> u32 {
180        unsafe { ffi::gtk_grid_layout_get_row_spacing(self.to_glib_none().0) }
181    }
182
183    /// Sets which row defines the global baseline for the entire grid.
184    ///
185    /// Each row in the grid can have its own local baseline, but only
186    /// one of those is global, meaning it will be the baseline in the
187    /// parent of the @self.
188    /// ## `row`
189    /// the row index
190    #[doc(alias = "gtk_grid_layout_set_baseline_row")]
191    #[doc(alias = "baseline-row")]
192    pub fn set_baseline_row(&self, row: i32) {
193        unsafe {
194            ffi::gtk_grid_layout_set_baseline_row(self.to_glib_none().0, row);
195        }
196    }
197
198    /// Sets whether all columns of @self should have the same width.
199    /// ## `homogeneous`
200    /// [`true`] to make columns homogeneous
201    #[doc(alias = "gtk_grid_layout_set_column_homogeneous")]
202    #[doc(alias = "column-homogeneous")]
203    pub fn set_column_homogeneous(&self, homogeneous: bool) {
204        unsafe {
205            ffi::gtk_grid_layout_set_column_homogeneous(
206                self.to_glib_none().0,
207                homogeneous.into_glib(),
208            );
209        }
210    }
211
212    /// Sets the amount of space to insert between consecutive columns.
213    /// ## `spacing`
214    /// the amount of space between columns, in pixels
215    #[doc(alias = "gtk_grid_layout_set_column_spacing")]
216    #[doc(alias = "column-spacing")]
217    pub fn set_column_spacing(&self, spacing: u32) {
218        unsafe {
219            ffi::gtk_grid_layout_set_column_spacing(self.to_glib_none().0, spacing);
220        }
221    }
222
223    /// Sets how the baseline should be positioned on @row of the
224    /// grid, in case that row is assigned more space than is requested.
225    /// ## `row`
226    /// a row index
227    /// ## `pos`
228    /// a [`BaselinePosition`][crate::BaselinePosition]
229    #[doc(alias = "gtk_grid_layout_set_row_baseline_position")]
230    pub fn set_row_baseline_position(&self, row: i32, pos: BaselinePosition) {
231        unsafe {
232            ffi::gtk_grid_layout_set_row_baseline_position(
233                self.to_glib_none().0,
234                row,
235                pos.into_glib(),
236            );
237        }
238    }
239
240    /// Sets whether all rows of @self should have the same height.
241    /// ## `homogeneous`
242    /// [`true`] to make rows homogeneous
243    #[doc(alias = "gtk_grid_layout_set_row_homogeneous")]
244    #[doc(alias = "row-homogeneous")]
245    pub fn set_row_homogeneous(&self, homogeneous: bool) {
246        unsafe {
247            ffi::gtk_grid_layout_set_row_homogeneous(
248                self.to_glib_none().0,
249                homogeneous.into_glib(),
250            );
251        }
252    }
253
254    /// Sets the amount of space to insert between consecutive rows.
255    /// ## `spacing`
256    /// the amount of space between rows, in pixels
257    #[doc(alias = "gtk_grid_layout_set_row_spacing")]
258    #[doc(alias = "row-spacing")]
259    pub fn set_row_spacing(&self, spacing: u32) {
260        unsafe {
261            ffi::gtk_grid_layout_set_row_spacing(self.to_glib_none().0, spacing);
262        }
263    }
264
265    #[doc(alias = "baseline-row")]
266    pub fn connect_baseline_row_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
267        unsafe extern "C" fn notify_baseline_row_trampoline<F: Fn(&GridLayout) + 'static>(
268            this: *mut ffi::GtkGridLayout,
269            _param_spec: glib::ffi::gpointer,
270            f: glib::ffi::gpointer,
271        ) {
272            unsafe {
273                let f: &F = &*(f as *const F);
274                f(&from_glib_borrow(this))
275            }
276        }
277        unsafe {
278            let f: Box_<F> = Box_::new(f);
279            connect_raw(
280                self.as_ptr() as *mut _,
281                c"notify::baseline-row".as_ptr() as *const _,
282                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
283                    notify_baseline_row_trampoline::<F> as *const (),
284                )),
285                Box_::into_raw(f),
286            )
287        }
288    }
289
290    #[doc(alias = "column-homogeneous")]
291    pub fn connect_column_homogeneous_notify<F: Fn(&Self) + 'static>(
292        &self,
293        f: F,
294    ) -> SignalHandlerId {
295        unsafe extern "C" fn notify_column_homogeneous_trampoline<F: Fn(&GridLayout) + 'static>(
296            this: *mut ffi::GtkGridLayout,
297            _param_spec: glib::ffi::gpointer,
298            f: glib::ffi::gpointer,
299        ) {
300            unsafe {
301                let f: &F = &*(f as *const F);
302                f(&from_glib_borrow(this))
303            }
304        }
305        unsafe {
306            let f: Box_<F> = Box_::new(f);
307            connect_raw(
308                self.as_ptr() as *mut _,
309                c"notify::column-homogeneous".as_ptr() as *const _,
310                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
311                    notify_column_homogeneous_trampoline::<F> as *const (),
312                )),
313                Box_::into_raw(f),
314            )
315        }
316    }
317
318    #[doc(alias = "column-spacing")]
319    pub fn connect_column_spacing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
320        unsafe extern "C" fn notify_column_spacing_trampoline<F: Fn(&GridLayout) + 'static>(
321            this: *mut ffi::GtkGridLayout,
322            _param_spec: glib::ffi::gpointer,
323            f: glib::ffi::gpointer,
324        ) {
325            unsafe {
326                let f: &F = &*(f as *const F);
327                f(&from_glib_borrow(this))
328            }
329        }
330        unsafe {
331            let f: Box_<F> = Box_::new(f);
332            connect_raw(
333                self.as_ptr() as *mut _,
334                c"notify::column-spacing".as_ptr() as *const _,
335                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
336                    notify_column_spacing_trampoline::<F> as *const (),
337                )),
338                Box_::into_raw(f),
339            )
340        }
341    }
342
343    #[doc(alias = "row-homogeneous")]
344    pub fn connect_row_homogeneous_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
345        unsafe extern "C" fn notify_row_homogeneous_trampoline<F: Fn(&GridLayout) + 'static>(
346            this: *mut ffi::GtkGridLayout,
347            _param_spec: glib::ffi::gpointer,
348            f: glib::ffi::gpointer,
349        ) {
350            unsafe {
351                let f: &F = &*(f as *const F);
352                f(&from_glib_borrow(this))
353            }
354        }
355        unsafe {
356            let f: Box_<F> = Box_::new(f);
357            connect_raw(
358                self.as_ptr() as *mut _,
359                c"notify::row-homogeneous".as_ptr() as *const _,
360                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
361                    notify_row_homogeneous_trampoline::<F> as *const (),
362                )),
363                Box_::into_raw(f),
364            )
365        }
366    }
367
368    #[doc(alias = "row-spacing")]
369    pub fn connect_row_spacing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
370        unsafe extern "C" fn notify_row_spacing_trampoline<F: Fn(&GridLayout) + 'static>(
371            this: *mut ffi::GtkGridLayout,
372            _param_spec: glib::ffi::gpointer,
373            f: glib::ffi::gpointer,
374        ) {
375            unsafe {
376                let f: &F = &*(f as *const F);
377                f(&from_glib_borrow(this))
378            }
379        }
380        unsafe {
381            let f: Box_<F> = Box_::new(f);
382            connect_raw(
383                self.as_ptr() as *mut _,
384                c"notify::row-spacing".as_ptr() as *const _,
385                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
386                    notify_row_spacing_trampoline::<F> as *const (),
387                )),
388                Box_::into_raw(f),
389            )
390        }
391    }
392}
393
394impl Default for GridLayout {
395    fn default() -> Self {
396        Self::new()
397    }
398}
399
400// rustdoc-stripper-ignore-next
401/// A [builder-pattern] type to construct [`GridLayout`] objects.
402///
403/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
404#[must_use = "The builder must be built to be used"]
405pub struct GridLayoutBuilder {
406    builder: glib::object::ObjectBuilder<'static, GridLayout>,
407}
408
409impl GridLayoutBuilder {
410    fn new() -> Self {
411        Self {
412            builder: glib::object::Object::builder(),
413        }
414    }
415
416    /// The row to align to the baseline, when `GtkWidget:valign` is set
417    /// to [`Align::Baseline`][crate::Align::Baseline].
418    pub fn baseline_row(self, baseline_row: i32) -> Self {
419        Self {
420            builder: self.builder.property("baseline-row", baseline_row),
421        }
422    }
423
424    /// Whether all the columns in the grid have the same width.
425    pub fn column_homogeneous(self, column_homogeneous: bool) -> Self {
426        Self {
427            builder: self
428                .builder
429                .property("column-homogeneous", column_homogeneous),
430        }
431    }
432
433    /// The amount of space between to consecutive columns.
434    pub fn column_spacing(self, column_spacing: i32) -> Self {
435        Self {
436            builder: self.builder.property("column-spacing", column_spacing),
437        }
438    }
439
440    /// Whether all the rows in the grid have the same height.
441    pub fn row_homogeneous(self, row_homogeneous: bool) -> Self {
442        Self {
443            builder: self.builder.property("row-homogeneous", row_homogeneous),
444        }
445    }
446
447    /// The amount of space between to consecutive rows.
448    pub fn row_spacing(self, row_spacing: i32) -> Self {
449        Self {
450            builder: self.builder.property("row-spacing", row_spacing),
451        }
452    }
453
454    // rustdoc-stripper-ignore-next
455    /// Build the [`GridLayout`].
456    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
457    pub fn build(self) -> GridLayout {
458        assert_initialized_main_thread!();
459        self.builder.build()
460    }
461}