1use crate::{ffi, BaselinePosition, LayoutManager, Orientable, Orientation};
6use glib::{
7 prelude::*,
8 signal::{connect_raw, SignalHandlerId},
9 translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14 #[doc(alias = "GtkBoxLayout")]
77 pub struct BoxLayout(Object<ffi::GtkBoxLayout, ffi::GtkBoxLayoutClass>) @extends LayoutManager, @implements Orientable;
78
79 match fn {
80 type_ => || ffi::gtk_box_layout_get_type(),
81 }
82}
83
84impl BoxLayout {
85 #[doc(alias = "gtk_box_layout_new")]
93 pub fn new(orientation: Orientation) -> BoxLayout {
94 assert_initialized_main_thread!();
95 unsafe {
96 LayoutManager::from_glib_full(ffi::gtk_box_layout_new(orientation.into_glib()))
97 .unsafe_cast()
98 }
99 }
100
101 pub fn builder() -> BoxLayoutBuilder {
106 BoxLayoutBuilder::new()
107 }
108
109 #[cfg(feature = "v4_12")]
116 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
117 #[doc(alias = "gtk_box_layout_get_baseline_child")]
118 #[doc(alias = "get_baseline_child")]
119 #[doc(alias = "baseline-child")]
120 pub fn baseline_child(&self) -> i32 {
121 unsafe { ffi::gtk_box_layout_get_baseline_child(self.to_glib_none().0) }
122 }
123
124 #[doc(alias = "gtk_box_layout_get_baseline_position")]
130 #[doc(alias = "get_baseline_position")]
131 #[doc(alias = "baseline-position")]
132 pub fn baseline_position(&self) -> BaselinePosition {
133 unsafe {
134 from_glib(ffi::gtk_box_layout_get_baseline_position(
135 self.to_glib_none().0,
136 ))
137 }
138 }
139
140 #[doc(alias = "gtk_box_layout_get_homogeneous")]
146 #[doc(alias = "get_homogeneous")]
147 #[doc(alias = "homogeneous")]
148 pub fn is_homogeneous(&self) -> bool {
149 unsafe { from_glib(ffi::gtk_box_layout_get_homogeneous(self.to_glib_none().0)) }
150 }
151
152 #[doc(alias = "gtk_box_layout_get_spacing")]
158 #[doc(alias = "get_spacing")]
159 pub fn spacing(&self) -> u32 {
160 unsafe { ffi::gtk_box_layout_get_spacing(self.to_glib_none().0) }
161 }
162
163 #[cfg(feature = "v4_12")]
168 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
169 #[doc(alias = "gtk_box_layout_set_baseline_child")]
170 #[doc(alias = "baseline-child")]
171 pub fn set_baseline_child(&self, child: i32) {
172 unsafe {
173 ffi::gtk_box_layout_set_baseline_child(self.to_glib_none().0, child);
174 }
175 }
176
177 #[doc(alias = "gtk_box_layout_set_baseline_position")]
187 #[doc(alias = "baseline-position")]
188 pub fn set_baseline_position(&self, position: BaselinePosition) {
189 unsafe {
190 ffi::gtk_box_layout_set_baseline_position(self.to_glib_none().0, position.into_glib());
191 }
192 }
193
194 #[doc(alias = "gtk_box_layout_set_homogeneous")]
199 #[doc(alias = "homogeneous")]
200 pub fn set_homogeneous(&self, homogeneous: bool) {
201 unsafe {
202 ffi::gtk_box_layout_set_homogeneous(self.to_glib_none().0, homogeneous.into_glib());
203 }
204 }
205
206 #[doc(alias = "gtk_box_layout_set_spacing")]
210 #[doc(alias = "spacing")]
211 pub fn set_spacing(&self, spacing: u32) {
212 unsafe {
213 ffi::gtk_box_layout_set_spacing(self.to_glib_none().0, spacing);
214 }
215 }
216
217 #[cfg(feature = "v4_12")]
218 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
219 #[doc(alias = "baseline-child")]
220 pub fn connect_baseline_child_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
221 unsafe extern "C" fn notify_baseline_child_trampoline<F: Fn(&BoxLayout) + 'static>(
222 this: *mut ffi::GtkBoxLayout,
223 _param_spec: glib::ffi::gpointer,
224 f: glib::ffi::gpointer,
225 ) {
226 let f: &F = &*(f as *const F);
227 f(&from_glib_borrow(this))
228 }
229 unsafe {
230 let f: Box_<F> = Box_::new(f);
231 connect_raw(
232 self.as_ptr() as *mut _,
233 c"notify::baseline-child".as_ptr() as *const _,
234 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
235 notify_baseline_child_trampoline::<F> as *const (),
236 )),
237 Box_::into_raw(f),
238 )
239 }
240 }
241
242 #[doc(alias = "baseline-position")]
243 pub fn connect_baseline_position_notify<F: Fn(&Self) + 'static>(
244 &self,
245 f: F,
246 ) -> SignalHandlerId {
247 unsafe extern "C" fn notify_baseline_position_trampoline<F: Fn(&BoxLayout) + 'static>(
248 this: *mut ffi::GtkBoxLayout,
249 _param_spec: glib::ffi::gpointer,
250 f: glib::ffi::gpointer,
251 ) {
252 let f: &F = &*(f as *const F);
253 f(&from_glib_borrow(this))
254 }
255 unsafe {
256 let f: Box_<F> = Box_::new(f);
257 connect_raw(
258 self.as_ptr() as *mut _,
259 c"notify::baseline-position".as_ptr() as *const _,
260 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
261 notify_baseline_position_trampoline::<F> as *const (),
262 )),
263 Box_::into_raw(f),
264 )
265 }
266 }
267
268 #[doc(alias = "homogeneous")]
269 pub fn connect_homogeneous_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
270 unsafe extern "C" fn notify_homogeneous_trampoline<F: Fn(&BoxLayout) + 'static>(
271 this: *mut ffi::GtkBoxLayout,
272 _param_spec: glib::ffi::gpointer,
273 f: glib::ffi::gpointer,
274 ) {
275 let f: &F = &*(f as *const F);
276 f(&from_glib_borrow(this))
277 }
278 unsafe {
279 let f: Box_<F> = Box_::new(f);
280 connect_raw(
281 self.as_ptr() as *mut _,
282 c"notify::homogeneous".as_ptr() as *const _,
283 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
284 notify_homogeneous_trampoline::<F> as *const (),
285 )),
286 Box_::into_raw(f),
287 )
288 }
289 }
290
291 #[doc(alias = "spacing")]
292 pub fn connect_spacing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
293 unsafe extern "C" fn notify_spacing_trampoline<F: Fn(&BoxLayout) + 'static>(
294 this: *mut ffi::GtkBoxLayout,
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::spacing".as_ptr() as *const _,
306 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
307 notify_spacing_trampoline::<F> as *const (),
308 )),
309 Box_::into_raw(f),
310 )
311 }
312 }
313}
314
315impl Default for BoxLayout {
316 fn default() -> Self {
317 glib::object::Object::new::<Self>()
318 }
319}
320
321#[must_use = "The builder must be built to be used"]
326pub struct BoxLayoutBuilder {
327 builder: glib::object::ObjectBuilder<'static, BoxLayout>,
328}
329
330impl BoxLayoutBuilder {
331 fn new() -> Self {
332 Self {
333 builder: glib::object::Object::builder(),
334 }
335 }
336
337 #[cfg(feature = "v4_12")]
344 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
345 pub fn baseline_child(self, baseline_child: i32) -> Self {
346 Self {
347 builder: self.builder.property("baseline-child", baseline_child),
348 }
349 }
350
351 pub fn baseline_position(self, baseline_position: BaselinePosition) -> Self {
357 Self {
358 builder: self
359 .builder
360 .property("baseline-position", baseline_position),
361 }
362 }
363
364 pub fn homogeneous(self, homogeneous: bool) -> Self {
367 Self {
368 builder: self.builder.property("homogeneous", homogeneous),
369 }
370 }
371
372 pub fn spacing(self, spacing: i32) -> Self {
374 Self {
375 builder: self.builder.property("spacing", spacing),
376 }
377 }
378
379 pub fn orientation(self, orientation: Orientation) -> Self {
381 Self {
382 builder: self.builder.property("orientation", orientation),
383 }
384 }
385
386 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
389 pub fn build(self) -> BoxLayout {
390 assert_initialized_main_thread!();
391 self.builder.build()
392 }
393}