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