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