gtk4/auto/
center_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, Orientation, Widget};
6#[cfg(feature = "v4_12")]
7#[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
8use glib::signal::{connect_raw, SignalHandlerId};
9use glib::{prelude::*, translate::*};
10#[cfg(feature = "v4_12")]
11#[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    /// [`CenterLayout`][crate::CenterLayout] is a layout manager that manages up to three children.
16    ///
17    /// The start widget is allocated at the start of the layout (left in
18    /// left-to-right locales and right in right-to-left ones), and the end
19    /// widget at the end.
20    ///
21    /// The center widget is centered regarding the full width of the layout's.
22    ///
23    /// ## Properties
24    ///
25    ///
26    /// #### `shrink-center-last`
27    ///  Whether to shrink the center widget after other children.
28    ///
29    /// By default, when there's no space to give all three children their
30    /// natural widths, the start and end widgets start shrinking and the
31    /// center child keeps natural width until they reach minimum width.
32    ///
33    /// If set to `FALSE`, start and end widgets keep natural width and the
34    /// center widget starts shrinking instead.
35    ///
36    /// Readable | Writeable
37    ///
38    /// # Implements
39    ///
40    /// [`LayoutManagerExt`][trait@crate::prelude::LayoutManagerExt], [`trait@glib::ObjectExt`]
41    #[doc(alias = "GtkCenterLayout")]
42    pub struct CenterLayout(Object<ffi::GtkCenterLayout, ffi::GtkCenterLayoutClass>) @extends LayoutManager;
43
44    match fn {
45        type_ => || ffi::gtk_center_layout_get_type(),
46    }
47}
48
49impl CenterLayout {
50    /// Creates a new [`CenterLayout`][crate::CenterLayout].
51    ///
52    /// # Returns
53    ///
54    /// the newly created [`CenterLayout`][crate::CenterLayout]
55    #[doc(alias = "gtk_center_layout_new")]
56    pub fn new() -> CenterLayout {
57        assert_initialized_main_thread!();
58        unsafe { LayoutManager::from_glib_full(ffi::gtk_center_layout_new()).unsafe_cast() }
59    }
60
61    /// Returns the baseline position of the layout.
62    ///
63    /// # Returns
64    ///
65    /// The current baseline position of @self.
66    #[doc(alias = "gtk_center_layout_get_baseline_position")]
67    #[doc(alias = "get_baseline_position")]
68    pub fn baseline_position(&self) -> BaselinePosition {
69        unsafe {
70            from_glib(ffi::gtk_center_layout_get_baseline_position(
71                self.to_glib_none().0,
72            ))
73        }
74    }
75
76    /// Returns the center widget of the layout.
77    ///
78    /// # Returns
79    ///
80    /// the current center widget of @self
81    #[doc(alias = "gtk_center_layout_get_center_widget")]
82    #[doc(alias = "get_center_widget")]
83    pub fn center_widget(&self) -> Option<Widget> {
84        unsafe {
85            from_glib_none(ffi::gtk_center_layout_get_center_widget(
86                self.to_glib_none().0,
87            ))
88        }
89    }
90
91    /// Returns the end widget of the layout.
92    ///
93    /// # Returns
94    ///
95    /// the current end widget of @self
96    #[doc(alias = "gtk_center_layout_get_end_widget")]
97    #[doc(alias = "get_end_widget")]
98    pub fn end_widget(&self) -> Option<Widget> {
99        unsafe { from_glib_none(ffi::gtk_center_layout_get_end_widget(self.to_glib_none().0)) }
100    }
101
102    /// Gets the current orienration of the layout manager.
103    ///
104    /// # Returns
105    ///
106    /// The current orientation of @self
107    #[doc(alias = "gtk_center_layout_get_orientation")]
108    #[doc(alias = "get_orientation")]
109    pub fn orientation(&self) -> Orientation {
110        unsafe {
111            from_glib(ffi::gtk_center_layout_get_orientation(
112                self.to_glib_none().0,
113            ))
114        }
115    }
116
117    /// Gets whether @self shrinks the center widget after other children.
118    ///
119    /// # Returns
120    ///
121    /// whether to shrink the center widget after others
122    #[cfg(feature = "v4_12")]
123    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
124    #[doc(alias = "gtk_center_layout_get_shrink_center_last")]
125    #[doc(alias = "get_shrink_center_last")]
126    #[doc(alias = "shrink-center-last")]
127    pub fn shrinks_center_last(&self) -> bool {
128        unsafe {
129            from_glib(ffi::gtk_center_layout_get_shrink_center_last(
130                self.to_glib_none().0,
131            ))
132        }
133    }
134
135    /// Returns the start widget of the layout.
136    ///
137    /// # Returns
138    ///
139    /// The current start widget of @self
140    #[doc(alias = "gtk_center_layout_get_start_widget")]
141    #[doc(alias = "get_start_widget")]
142    pub fn start_widget(&self) -> Option<Widget> {
143        unsafe {
144            from_glib_none(ffi::gtk_center_layout_get_start_widget(
145                self.to_glib_none().0,
146            ))
147        }
148    }
149
150    /// Sets the new baseline position of @self
151    /// ## `baseline_position`
152    /// the new baseline position
153    #[doc(alias = "gtk_center_layout_set_baseline_position")]
154    pub fn set_baseline_position(&self, baseline_position: BaselinePosition) {
155        unsafe {
156            ffi::gtk_center_layout_set_baseline_position(
157                self.to_glib_none().0,
158                baseline_position.into_glib(),
159            );
160        }
161    }
162
163    /// Sets the new center widget of @self.
164    ///
165    /// To remove the existing center widget, pass [`None`].
166    /// ## `widget`
167    /// the new center widget
168    #[doc(alias = "gtk_center_layout_set_center_widget")]
169    pub fn set_center_widget(&self, widget: Option<&impl IsA<Widget>>) {
170        unsafe {
171            ffi::gtk_center_layout_set_center_widget(
172                self.to_glib_none().0,
173                widget.map(|p| p.as_ref()).to_glib_none().0,
174            );
175        }
176    }
177
178    /// Sets the new end widget of @self.
179    ///
180    /// To remove the existing center widget, pass [`None`].
181    /// ## `widget`
182    /// the new end widget
183    #[doc(alias = "gtk_center_layout_set_end_widget")]
184    pub fn set_end_widget(&self, widget: Option<&impl IsA<Widget>>) {
185        unsafe {
186            ffi::gtk_center_layout_set_end_widget(
187                self.to_glib_none().0,
188                widget.map(|p| p.as_ref()).to_glib_none().0,
189            );
190        }
191    }
192
193    /// Sets the orientation of @self.
194    /// ## `orientation`
195    /// the new orientation
196    #[doc(alias = "gtk_center_layout_set_orientation")]
197    pub fn set_orientation(&self, orientation: Orientation) {
198        unsafe {
199            ffi::gtk_center_layout_set_orientation(self.to_glib_none().0, orientation.into_glib());
200        }
201    }
202
203    /// Sets whether to shrink the center widget after other children.
204    ///
205    /// By default, when there's no space to give all three children their
206    /// natural widths, the start and end widgets start shrinking and the
207    /// center child keeps natural width until they reach minimum width.
208    ///
209    /// If set to `FALSE`, start and end widgets keep natural width and the
210    /// center widget starts shrinking instead.
211    /// ## `shrink_center_last`
212    /// whether to shrink the center widget after others
213    #[cfg(feature = "v4_12")]
214    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
215    #[doc(alias = "gtk_center_layout_set_shrink_center_last")]
216    #[doc(alias = "shrink-center-last")]
217    pub fn set_shrink_center_last(&self, shrink_center_last: bool) {
218        unsafe {
219            ffi::gtk_center_layout_set_shrink_center_last(
220                self.to_glib_none().0,
221                shrink_center_last.into_glib(),
222            );
223        }
224    }
225
226    /// Sets the new start widget of @self.
227    ///
228    /// To remove the existing start widget, pass [`None`].
229    /// ## `widget`
230    /// the new start widget
231    #[doc(alias = "gtk_center_layout_set_start_widget")]
232    pub fn set_start_widget(&self, widget: Option<&impl IsA<Widget>>) {
233        unsafe {
234            ffi::gtk_center_layout_set_start_widget(
235                self.to_glib_none().0,
236                widget.map(|p| p.as_ref()).to_glib_none().0,
237            );
238        }
239    }
240
241    #[cfg(feature = "v4_12")]
242    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
243    #[doc(alias = "shrink-center-last")]
244    pub fn connect_shrink_center_last_notify<F: Fn(&Self) + 'static>(
245        &self,
246        f: F,
247    ) -> SignalHandlerId {
248        unsafe extern "C" fn notify_shrink_center_last_trampoline<
249            F: Fn(&CenterLayout) + 'static,
250        >(
251            this: *mut ffi::GtkCenterLayout,
252            _param_spec: glib::ffi::gpointer,
253            f: glib::ffi::gpointer,
254        ) {
255            let f: &F = &*(f as *const F);
256            f(&from_glib_borrow(this))
257        }
258        unsafe {
259            let f: Box_<F> = Box_::new(f);
260            connect_raw(
261                self.as_ptr() as *mut _,
262                b"notify::shrink-center-last\0".as_ptr() as *const _,
263                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
264                    notify_shrink_center_last_trampoline::<F> as *const (),
265                )),
266                Box_::into_raw(f),
267            )
268        }
269    }
270}
271
272impl Default for CenterLayout {
273    fn default() -> Self {
274        Self::new()
275    }
276}