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::{ffi, BaselinePosition, LayoutManager};
6use glib::{
7    prelude::*,
8    signal::{connect_raw, SignalHandlerId},
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            let f: &F = &*(f as *const F);
273            f(&from_glib_borrow(this))
274        }
275        unsafe {
276            let f: Box_<F> = Box_::new(f);
277            connect_raw(
278                self.as_ptr() as *mut _,
279                c"notify::baseline-row".as_ptr() as *const _,
280                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
281                    notify_baseline_row_trampoline::<F> as *const (),
282                )),
283                Box_::into_raw(f),
284            )
285        }
286    }
287
288    #[doc(alias = "column-homogeneous")]
289    pub fn connect_column_homogeneous_notify<F: Fn(&Self) + 'static>(
290        &self,
291        f: F,
292    ) -> SignalHandlerId {
293        unsafe extern "C" fn notify_column_homogeneous_trampoline<F: Fn(&GridLayout) + 'static>(
294            this: *mut ffi::GtkGridLayout,
295            _param_spec: glib::ffi::gpointer,
296            f: glib::ffi::gpointer,
297        ) {
298            let f: &F = &*(f as *const F);
299            f(&from_glib_borrow(this))
300        }
301        unsafe {
302            let f: Box_<F> = Box_::new(f);
303            connect_raw(
304                self.as_ptr() as *mut _,
305                c"notify::column-homogeneous".as_ptr() as *const _,
306                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
307                    notify_column_homogeneous_trampoline::<F> as *const (),
308                )),
309                Box_::into_raw(f),
310            )
311        }
312    }
313
314    #[doc(alias = "column-spacing")]
315    pub fn connect_column_spacing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
316        unsafe extern "C" fn notify_column_spacing_trampoline<F: Fn(&GridLayout) + 'static>(
317            this: *mut ffi::GtkGridLayout,
318            _param_spec: glib::ffi::gpointer,
319            f: glib::ffi::gpointer,
320        ) {
321            let f: &F = &*(f as *const F);
322            f(&from_glib_borrow(this))
323        }
324        unsafe {
325            let f: Box_<F> = Box_::new(f);
326            connect_raw(
327                self.as_ptr() as *mut _,
328                c"notify::column-spacing".as_ptr() as *const _,
329                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
330                    notify_column_spacing_trampoline::<F> as *const (),
331                )),
332                Box_::into_raw(f),
333            )
334        }
335    }
336
337    #[doc(alias = "row-homogeneous")]
338    pub fn connect_row_homogeneous_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
339        unsafe extern "C" fn notify_row_homogeneous_trampoline<F: Fn(&GridLayout) + 'static>(
340            this: *mut ffi::GtkGridLayout,
341            _param_spec: glib::ffi::gpointer,
342            f: glib::ffi::gpointer,
343        ) {
344            let f: &F = &*(f as *const F);
345            f(&from_glib_borrow(this))
346        }
347        unsafe {
348            let f: Box_<F> = Box_::new(f);
349            connect_raw(
350                self.as_ptr() as *mut _,
351                c"notify::row-homogeneous".as_ptr() as *const _,
352                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
353                    notify_row_homogeneous_trampoline::<F> as *const (),
354                )),
355                Box_::into_raw(f),
356            )
357        }
358    }
359
360    #[doc(alias = "row-spacing")]
361    pub fn connect_row_spacing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
362        unsafe extern "C" fn notify_row_spacing_trampoline<F: Fn(&GridLayout) + 'static>(
363            this: *mut ffi::GtkGridLayout,
364            _param_spec: glib::ffi::gpointer,
365            f: glib::ffi::gpointer,
366        ) {
367            let f: &F = &*(f as *const F);
368            f(&from_glib_borrow(this))
369        }
370        unsafe {
371            let f: Box_<F> = Box_::new(f);
372            connect_raw(
373                self.as_ptr() as *mut _,
374                c"notify::row-spacing".as_ptr() as *const _,
375                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
376                    notify_row_spacing_trampoline::<F> as *const (),
377                )),
378                Box_::into_raw(f),
379            )
380        }
381    }
382}
383
384impl Default for GridLayout {
385    fn default() -> Self {
386        Self::new()
387    }
388}
389
390// rustdoc-stripper-ignore-next
391/// A [builder-pattern] type to construct [`GridLayout`] objects.
392///
393/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
394#[must_use = "The builder must be built to be used"]
395pub struct GridLayoutBuilder {
396    builder: glib::object::ObjectBuilder<'static, GridLayout>,
397}
398
399impl GridLayoutBuilder {
400    fn new() -> Self {
401        Self {
402            builder: glib::object::Object::builder(),
403        }
404    }
405
406    /// The row to align to the baseline, when `GtkWidget:valign` is set
407    /// to [`Align::Baseline`][crate::Align::Baseline].
408    pub fn baseline_row(self, baseline_row: i32) -> Self {
409        Self {
410            builder: self.builder.property("baseline-row", baseline_row),
411        }
412    }
413
414    /// Whether all the columns in the grid have the same width.
415    pub fn column_homogeneous(self, column_homogeneous: bool) -> Self {
416        Self {
417            builder: self
418                .builder
419                .property("column-homogeneous", column_homogeneous),
420        }
421    }
422
423    /// The amount of space between to consecutive columns.
424    pub fn column_spacing(self, column_spacing: i32) -> Self {
425        Self {
426            builder: self.builder.property("column-spacing", column_spacing),
427        }
428    }
429
430    /// Whether all the rows in the grid have the same height.
431    pub fn row_homogeneous(self, row_homogeneous: bool) -> Self {
432        Self {
433            builder: self.builder.property("row-homogeneous", row_homogeneous),
434        }
435    }
436
437    /// The amount of space between to consecutive rows.
438    pub fn row_spacing(self, row_spacing: i32) -> Self {
439        Self {
440            builder: self.builder.property("row-spacing", row_spacing),
441        }
442    }
443
444    // rustdoc-stripper-ignore-next
445    /// Build the [`GridLayout`].
446    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
447    pub fn build(self) -> GridLayout {
448        assert_initialized_main_thread!();
449        self.builder.build()
450    }
451}