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