1use crate::{
6 ffi, Accessible, AccessibleRole, Align, BaselinePosition, Buildable, ConstraintTarget,
7 LayoutManager, Orientable, Orientation, Overflow, Widget,
8};
9use glib::{
10 prelude::*,
11 signal::{connect_raw, SignalHandlerId},
12 translate::*,
13};
14use std::boxed::Box as Box_;
15
16glib::wrapper! {
17 #[doc(alias = "GtkBox")]
18 pub struct Box(Object<ffi::GtkBox, ffi::GtkBoxClass>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget, Orientable;
19
20 match fn {
21 type_ => || ffi::gtk_box_get_type(),
22 }
23}
24
25impl Box {
26 pub const NONE: Option<&'static Box> = None;
27
28 #[doc(alias = "gtk_box_new")]
29 pub fn new(orientation: Orientation, spacing: i32) -> Box {
30 assert_initialized_main_thread!();
31 unsafe {
32 Widget::from_glib_none(ffi::gtk_box_new(orientation.into_glib(), spacing)).unsafe_cast()
33 }
34 }
35
36 pub fn builder() -> BoxBuilder {
41 BoxBuilder::new()
42 }
43}
44
45impl Default for Box {
46 fn default() -> Self {
47 glib::object::Object::new::<Self>()
48 }
49}
50
51#[must_use = "The builder must be built to be used"]
56pub struct BoxBuilder {
57 builder: glib::object::ObjectBuilder<'static, Box>,
58}
59
60impl BoxBuilder {
61 fn new() -> Self {
62 Self {
63 builder: glib::object::Object::builder(),
64 }
65 }
66
67 #[cfg(feature = "v4_12")]
68 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
69 pub fn baseline_child(self, baseline_child: i32) -> Self {
70 Self {
71 builder: self.builder.property("baseline-child", baseline_child),
72 }
73 }
74
75 pub fn baseline_position(self, baseline_position: BaselinePosition) -> Self {
76 Self {
77 builder: self
78 .builder
79 .property("baseline-position", baseline_position),
80 }
81 }
82
83 pub fn homogeneous(self, homogeneous: bool) -> Self {
84 Self {
85 builder: self.builder.property("homogeneous", homogeneous),
86 }
87 }
88
89 pub fn spacing(self, spacing: i32) -> Self {
90 Self {
91 builder: self.builder.property("spacing", spacing),
92 }
93 }
94
95 pub fn can_focus(self, can_focus: bool) -> Self {
96 Self {
97 builder: self.builder.property("can-focus", can_focus),
98 }
99 }
100
101 pub fn can_target(self, can_target: bool) -> Self {
102 Self {
103 builder: self.builder.property("can-target", can_target),
104 }
105 }
106
107 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
108 Self {
109 builder: self.builder.property("css-classes", css_classes.into()),
110 }
111 }
112
113 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
114 Self {
115 builder: self.builder.property("css-name", css_name.into()),
116 }
117 }
118
119 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
120 Self {
121 builder: self.builder.property("cursor", cursor.clone()),
122 }
123 }
124
125 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
126 Self {
127 builder: self.builder.property("focus-on-click", focus_on_click),
128 }
129 }
130
131 pub fn focusable(self, focusable: bool) -> Self {
132 Self {
133 builder: self.builder.property("focusable", focusable),
134 }
135 }
136
137 pub fn halign(self, halign: Align) -> Self {
138 Self {
139 builder: self.builder.property("halign", halign),
140 }
141 }
142
143 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
144 Self {
145 builder: self.builder.property("has-tooltip", has_tooltip),
146 }
147 }
148
149 pub fn height_request(self, height_request: i32) -> Self {
150 Self {
151 builder: self.builder.property("height-request", height_request),
152 }
153 }
154
155 pub fn hexpand(self, hexpand: bool) -> Self {
156 Self {
157 builder: self.builder.property("hexpand", hexpand),
158 }
159 }
160
161 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
162 Self {
163 builder: self.builder.property("hexpand-set", hexpand_set),
164 }
165 }
166
167 pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
168 Self {
169 builder: self
170 .builder
171 .property("layout-manager", layout_manager.clone().upcast()),
172 }
173 }
174
175 #[cfg(feature = "v4_18")]
176 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
177 pub fn limit_events(self, limit_events: bool) -> Self {
178 Self {
179 builder: self.builder.property("limit-events", limit_events),
180 }
181 }
182
183 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
184 Self {
185 builder: self.builder.property("margin-bottom", margin_bottom),
186 }
187 }
188
189 pub fn margin_end(self, margin_end: i32) -> Self {
190 Self {
191 builder: self.builder.property("margin-end", margin_end),
192 }
193 }
194
195 pub fn margin_start(self, margin_start: i32) -> Self {
196 Self {
197 builder: self.builder.property("margin-start", margin_start),
198 }
199 }
200
201 pub fn margin_top(self, margin_top: i32) -> Self {
202 Self {
203 builder: self.builder.property("margin-top", margin_top),
204 }
205 }
206
207 pub fn name(self, name: impl Into<glib::GString>) -> Self {
208 Self {
209 builder: self.builder.property("name", name.into()),
210 }
211 }
212
213 pub fn opacity(self, opacity: f64) -> Self {
214 Self {
215 builder: self.builder.property("opacity", opacity),
216 }
217 }
218
219 pub fn overflow(self, overflow: Overflow) -> Self {
220 Self {
221 builder: self.builder.property("overflow", overflow),
222 }
223 }
224
225 pub fn receives_default(self, receives_default: bool) -> Self {
226 Self {
227 builder: self.builder.property("receives-default", receives_default),
228 }
229 }
230
231 pub fn sensitive(self, sensitive: bool) -> Self {
232 Self {
233 builder: self.builder.property("sensitive", sensitive),
234 }
235 }
236
237 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
238 Self {
239 builder: self
240 .builder
241 .property("tooltip-markup", tooltip_markup.into()),
242 }
243 }
244
245 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
246 Self {
247 builder: self.builder.property("tooltip-text", tooltip_text.into()),
248 }
249 }
250
251 pub fn valign(self, valign: Align) -> Self {
252 Self {
253 builder: self.builder.property("valign", valign),
254 }
255 }
256
257 pub fn vexpand(self, vexpand: bool) -> Self {
258 Self {
259 builder: self.builder.property("vexpand", vexpand),
260 }
261 }
262
263 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
264 Self {
265 builder: self.builder.property("vexpand-set", vexpand_set),
266 }
267 }
268
269 pub fn visible(self, visible: bool) -> Self {
270 Self {
271 builder: self.builder.property("visible", visible),
272 }
273 }
274
275 pub fn width_request(self, width_request: i32) -> Self {
276 Self {
277 builder: self.builder.property("width-request", width_request),
278 }
279 }
280
281 pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
282 Self {
283 builder: self.builder.property("accessible-role", accessible_role),
284 }
285 }
286
287 pub fn orientation(self, orientation: Orientation) -> Self {
288 Self {
289 builder: self.builder.property("orientation", orientation),
290 }
291 }
292
293 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
296 pub fn build(self) -> Box {
297 assert_initialized_main_thread!();
298 self.builder.build()
299 }
300}
301
302mod sealed {
303 pub trait Sealed {}
304 impl<T: super::IsA<super::Box>> Sealed for T {}
305}
306
307pub trait BoxExt: IsA<Box> + sealed::Sealed + 'static {
308 #[doc(alias = "gtk_box_append")]
309 fn append(&self, child: &impl IsA<Widget>) {
310 unsafe {
311 ffi::gtk_box_append(
312 self.as_ref().to_glib_none().0,
313 child.as_ref().to_glib_none().0,
314 );
315 }
316 }
317
318 #[cfg(feature = "v4_12")]
319 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
320 #[doc(alias = "gtk_box_get_baseline_child")]
321 #[doc(alias = "get_baseline_child")]
322 #[doc(alias = "baseline-child")]
323 fn baseline_child(&self) -> i32 {
324 unsafe { ffi::gtk_box_get_baseline_child(self.as_ref().to_glib_none().0) }
325 }
326
327 #[doc(alias = "gtk_box_get_baseline_position")]
328 #[doc(alias = "get_baseline_position")]
329 #[doc(alias = "baseline-position")]
330 fn baseline_position(&self) -> BaselinePosition {
331 unsafe {
332 from_glib(ffi::gtk_box_get_baseline_position(
333 self.as_ref().to_glib_none().0,
334 ))
335 }
336 }
337
338 #[doc(alias = "gtk_box_get_homogeneous")]
339 #[doc(alias = "get_homogeneous")]
340 #[doc(alias = "homogeneous")]
341 fn is_homogeneous(&self) -> bool {
342 unsafe { from_glib(ffi::gtk_box_get_homogeneous(self.as_ref().to_glib_none().0)) }
343 }
344
345 #[doc(alias = "gtk_box_get_spacing")]
346 #[doc(alias = "get_spacing")]
347 fn spacing(&self) -> i32 {
348 unsafe { ffi::gtk_box_get_spacing(self.as_ref().to_glib_none().0) }
349 }
350
351 #[doc(alias = "gtk_box_insert_child_after")]
352 fn insert_child_after(&self, child: &impl IsA<Widget>, sibling: Option<&impl IsA<Widget>>) {
353 unsafe {
354 ffi::gtk_box_insert_child_after(
355 self.as_ref().to_glib_none().0,
356 child.as_ref().to_glib_none().0,
357 sibling.map(|p| p.as_ref()).to_glib_none().0,
358 );
359 }
360 }
361
362 #[doc(alias = "gtk_box_prepend")]
363 fn prepend(&self, child: &impl IsA<Widget>) {
364 unsafe {
365 ffi::gtk_box_prepend(
366 self.as_ref().to_glib_none().0,
367 child.as_ref().to_glib_none().0,
368 );
369 }
370 }
371
372 #[doc(alias = "gtk_box_remove")]
373 fn remove(&self, child: &impl IsA<Widget>) {
374 unsafe {
375 ffi::gtk_box_remove(
376 self.as_ref().to_glib_none().0,
377 child.as_ref().to_glib_none().0,
378 );
379 }
380 }
381
382 #[doc(alias = "gtk_box_reorder_child_after")]
383 fn reorder_child_after(&self, child: &impl IsA<Widget>, sibling: Option<&impl IsA<Widget>>) {
384 unsafe {
385 ffi::gtk_box_reorder_child_after(
386 self.as_ref().to_glib_none().0,
387 child.as_ref().to_glib_none().0,
388 sibling.map(|p| p.as_ref()).to_glib_none().0,
389 );
390 }
391 }
392
393 #[cfg(feature = "v4_12")]
394 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
395 #[doc(alias = "gtk_box_set_baseline_child")]
396 #[doc(alias = "baseline-child")]
397 fn set_baseline_child(&self, child: i32) {
398 unsafe {
399 ffi::gtk_box_set_baseline_child(self.as_ref().to_glib_none().0, child);
400 }
401 }
402
403 #[doc(alias = "gtk_box_set_baseline_position")]
404 #[doc(alias = "baseline-position")]
405 fn set_baseline_position(&self, position: BaselinePosition) {
406 unsafe {
407 ffi::gtk_box_set_baseline_position(
408 self.as_ref().to_glib_none().0,
409 position.into_glib(),
410 );
411 }
412 }
413
414 #[doc(alias = "gtk_box_set_homogeneous")]
415 #[doc(alias = "homogeneous")]
416 fn set_homogeneous(&self, homogeneous: bool) {
417 unsafe {
418 ffi::gtk_box_set_homogeneous(self.as_ref().to_glib_none().0, homogeneous.into_glib());
419 }
420 }
421
422 #[doc(alias = "gtk_box_set_spacing")]
423 #[doc(alias = "spacing")]
424 fn set_spacing(&self, spacing: i32) {
425 unsafe {
426 ffi::gtk_box_set_spacing(self.as_ref().to_glib_none().0, spacing);
427 }
428 }
429
430 #[cfg(feature = "v4_12")]
431 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
432 #[doc(alias = "baseline-child")]
433 fn connect_baseline_child_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
434 unsafe extern "C" fn notify_baseline_child_trampoline<P: IsA<Box>, F: Fn(&P) + 'static>(
435 this: *mut ffi::GtkBox,
436 _param_spec: glib::ffi::gpointer,
437 f: glib::ffi::gpointer,
438 ) {
439 let f: &F = &*(f as *const F);
440 f(Box::from_glib_borrow(this).unsafe_cast_ref())
441 }
442 unsafe {
443 let f: Box_<F> = Box_::new(f);
444 connect_raw(
445 self.as_ptr() as *mut _,
446 b"notify::baseline-child\0".as_ptr() as *const _,
447 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
448 notify_baseline_child_trampoline::<Self, F> as *const (),
449 )),
450 Box_::into_raw(f),
451 )
452 }
453 }
454
455 #[doc(alias = "baseline-position")]
456 fn connect_baseline_position_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
457 unsafe extern "C" fn notify_baseline_position_trampoline<
458 P: IsA<Box>,
459 F: Fn(&P) + 'static,
460 >(
461 this: *mut ffi::GtkBox,
462 _param_spec: glib::ffi::gpointer,
463 f: glib::ffi::gpointer,
464 ) {
465 let f: &F = &*(f as *const F);
466 f(Box::from_glib_borrow(this).unsafe_cast_ref())
467 }
468 unsafe {
469 let f: Box_<F> = Box_::new(f);
470 connect_raw(
471 self.as_ptr() as *mut _,
472 b"notify::baseline-position\0".as_ptr() as *const _,
473 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
474 notify_baseline_position_trampoline::<Self, F> as *const (),
475 )),
476 Box_::into_raw(f),
477 )
478 }
479 }
480
481 #[doc(alias = "homogeneous")]
482 fn connect_homogeneous_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
483 unsafe extern "C" fn notify_homogeneous_trampoline<P: IsA<Box>, F: Fn(&P) + 'static>(
484 this: *mut ffi::GtkBox,
485 _param_spec: glib::ffi::gpointer,
486 f: glib::ffi::gpointer,
487 ) {
488 let f: &F = &*(f as *const F);
489 f(Box::from_glib_borrow(this).unsafe_cast_ref())
490 }
491 unsafe {
492 let f: Box_<F> = Box_::new(f);
493 connect_raw(
494 self.as_ptr() as *mut _,
495 b"notify::homogeneous\0".as_ptr() as *const _,
496 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
497 notify_homogeneous_trampoline::<Self, F> as *const (),
498 )),
499 Box_::into_raw(f),
500 )
501 }
502 }
503
504 #[doc(alias = "spacing")]
505 fn connect_spacing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
506 unsafe extern "C" fn notify_spacing_trampoline<P: IsA<Box>, F: Fn(&P) + 'static>(
507 this: *mut ffi::GtkBox,
508 _param_spec: glib::ffi::gpointer,
509 f: glib::ffi::gpointer,
510 ) {
511 let f: &F = &*(f as *const F);
512 f(Box::from_glib_borrow(this).unsafe_cast_ref())
513 }
514 unsafe {
515 let f: Box_<F> = Box_::new(f);
516 connect_raw(
517 self.as_ptr() as *mut _,
518 b"notify::spacing\0".as_ptr() as *const _,
519 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
520 notify_spacing_trampoline::<Self, F> as *const (),
521 )),
522 Box_::into_raw(f),
523 )
524 }
525 }
526}
527
528impl<O: IsA<Box>> BoxExt for O {}