gtk4/auto/
center_layout.rs
1use 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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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}