1use crate::{Align, Buildable, Container, PackType, ResizeMode, Widget};
6use glib::{
7 prelude::*,
8 signal::{connect_raw, SignalHandlerId},
9 translate::*,
10};
11use std::{boxed::Box as Box_, fmt, mem::transmute};
12
13glib::wrapper! {
14 #[doc(alias = "GtkHeaderBar")]
15 pub struct HeaderBar(Object<ffi::GtkHeaderBar, ffi::GtkHeaderBarClass>) @extends Container, Widget, @implements Buildable;
16
17 match fn {
18 type_ => || ffi::gtk_header_bar_get_type(),
19 }
20}
21
22impl HeaderBar {
23 pub const NONE: Option<&'static HeaderBar> = None;
24
25 #[doc(alias = "gtk_header_bar_new")]
26 pub fn new() -> HeaderBar {
27 assert_initialized_main_thread!();
28 unsafe { Widget::from_glib_none(ffi::gtk_header_bar_new()).unsafe_cast() }
29 }
30
31 pub fn builder() -> HeaderBarBuilder {
36 HeaderBarBuilder::new()
37 }
38}
39
40impl Default for HeaderBar {
41 fn default() -> Self {
42 Self::new()
43 }
44}
45
46#[must_use = "The builder must be built to be used"]
51pub struct HeaderBarBuilder {
52 builder: glib::object::ObjectBuilder<'static, HeaderBar>,
53}
54
55impl HeaderBarBuilder {
56 fn new() -> Self {
57 Self {
58 builder: glib::object::Object::builder(),
59 }
60 }
61
62 pub fn custom_title(self, custom_title: &impl IsA<Widget>) -> Self {
63 Self {
64 builder: self
65 .builder
66 .property("custom-title", custom_title.clone().upcast()),
67 }
68 }
69
70 pub fn decoration_layout(self, decoration_layout: impl Into<glib::GString>) -> Self {
71 Self {
72 builder: self
73 .builder
74 .property("decoration-layout", decoration_layout.into()),
75 }
76 }
77
78 pub fn decoration_layout_set(self, decoration_layout_set: bool) -> Self {
79 Self {
80 builder: self
81 .builder
82 .property("decoration-layout-set", decoration_layout_set),
83 }
84 }
85
86 pub fn has_subtitle(self, has_subtitle: bool) -> Self {
87 Self {
88 builder: self.builder.property("has-subtitle", has_subtitle),
89 }
90 }
91
92 pub fn show_close_button(self, show_close_button: bool) -> Self {
93 Self {
94 builder: self
95 .builder
96 .property("show-close-button", show_close_button),
97 }
98 }
99
100 pub fn spacing(self, spacing: i32) -> Self {
101 Self {
102 builder: self.builder.property("spacing", spacing),
103 }
104 }
105
106 pub fn subtitle(self, subtitle: impl Into<glib::GString>) -> Self {
107 Self {
108 builder: self.builder.property("subtitle", subtitle.into()),
109 }
110 }
111
112 pub fn title(self, title: impl Into<glib::GString>) -> Self {
113 Self {
114 builder: self.builder.property("title", title.into()),
115 }
116 }
117
118 pub fn border_width(self, border_width: u32) -> Self {
119 Self {
120 builder: self.builder.property("border-width", border_width),
121 }
122 }
123
124 pub fn child(self, child: &impl IsA<Widget>) -> Self {
125 Self {
126 builder: self.builder.property("child", child.clone().upcast()),
127 }
128 }
129
130 pub fn resize_mode(self, resize_mode: ResizeMode) -> Self {
131 Self {
132 builder: self.builder.property("resize-mode", resize_mode),
133 }
134 }
135
136 pub fn app_paintable(self, app_paintable: bool) -> Self {
137 Self {
138 builder: self.builder.property("app-paintable", app_paintable),
139 }
140 }
141
142 pub fn can_default(self, can_default: bool) -> Self {
143 Self {
144 builder: self.builder.property("can-default", can_default),
145 }
146 }
147
148 pub fn can_focus(self, can_focus: bool) -> Self {
149 Self {
150 builder: self.builder.property("can-focus", can_focus),
151 }
152 }
153
154 pub fn events(self, events: gdk::EventMask) -> Self {
155 Self {
156 builder: self.builder.property("events", events),
157 }
158 }
159
160 pub fn expand(self, expand: bool) -> Self {
161 Self {
162 builder: self.builder.property("expand", expand),
163 }
164 }
165
166 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
167 Self {
168 builder: self.builder.property("focus-on-click", focus_on_click),
169 }
170 }
171
172 pub fn halign(self, halign: Align) -> Self {
173 Self {
174 builder: self.builder.property("halign", halign),
175 }
176 }
177
178 pub fn has_default(self, has_default: bool) -> Self {
179 Self {
180 builder: self.builder.property("has-default", has_default),
181 }
182 }
183
184 pub fn has_focus(self, has_focus: bool) -> Self {
185 Self {
186 builder: self.builder.property("has-focus", has_focus),
187 }
188 }
189
190 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
191 Self {
192 builder: self.builder.property("has-tooltip", has_tooltip),
193 }
194 }
195
196 pub fn height_request(self, height_request: i32) -> Self {
197 Self {
198 builder: self.builder.property("height-request", height_request),
199 }
200 }
201
202 pub fn hexpand(self, hexpand: bool) -> Self {
203 Self {
204 builder: self.builder.property("hexpand", hexpand),
205 }
206 }
207
208 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
209 Self {
210 builder: self.builder.property("hexpand-set", hexpand_set),
211 }
212 }
213
214 pub fn is_focus(self, is_focus: bool) -> Self {
215 Self {
216 builder: self.builder.property("is-focus", is_focus),
217 }
218 }
219
220 pub fn margin(self, margin: i32) -> Self {
221 Self {
222 builder: self.builder.property("margin", margin),
223 }
224 }
225
226 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
227 Self {
228 builder: self.builder.property("margin-bottom", margin_bottom),
229 }
230 }
231
232 pub fn margin_end(self, margin_end: i32) -> Self {
233 Self {
234 builder: self.builder.property("margin-end", margin_end),
235 }
236 }
237
238 pub fn margin_start(self, margin_start: i32) -> Self {
239 Self {
240 builder: self.builder.property("margin-start", margin_start),
241 }
242 }
243
244 pub fn margin_top(self, margin_top: i32) -> Self {
245 Self {
246 builder: self.builder.property("margin-top", margin_top),
247 }
248 }
249
250 pub fn name(self, name: impl Into<glib::GString>) -> Self {
251 Self {
252 builder: self.builder.property("name", name.into()),
253 }
254 }
255
256 pub fn no_show_all(self, no_show_all: bool) -> Self {
257 Self {
258 builder: self.builder.property("no-show-all", no_show_all),
259 }
260 }
261
262 pub fn opacity(self, opacity: f64) -> Self {
263 Self {
264 builder: self.builder.property("opacity", opacity),
265 }
266 }
267
268 pub fn parent(self, parent: &impl IsA<Container>) -> Self {
269 Self {
270 builder: self.builder.property("parent", parent.clone().upcast()),
271 }
272 }
273
274 pub fn receives_default(self, receives_default: bool) -> Self {
275 Self {
276 builder: self.builder.property("receives-default", receives_default),
277 }
278 }
279
280 pub fn sensitive(self, sensitive: bool) -> Self {
281 Self {
282 builder: self.builder.property("sensitive", sensitive),
283 }
284 }
285
286 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
287 Self {
288 builder: self
289 .builder
290 .property("tooltip-markup", tooltip_markup.into()),
291 }
292 }
293
294 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
295 Self {
296 builder: self.builder.property("tooltip-text", tooltip_text.into()),
297 }
298 }
299
300 pub fn valign(self, valign: Align) -> Self {
301 Self {
302 builder: self.builder.property("valign", valign),
303 }
304 }
305
306 pub fn vexpand(self, vexpand: bool) -> Self {
307 Self {
308 builder: self.builder.property("vexpand", vexpand),
309 }
310 }
311
312 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
313 Self {
314 builder: self.builder.property("vexpand-set", vexpand_set),
315 }
316 }
317
318 pub fn visible(self, visible: bool) -> Self {
319 Self {
320 builder: self.builder.property("visible", visible),
321 }
322 }
323
324 pub fn width_request(self, width_request: i32) -> Self {
325 Self {
326 builder: self.builder.property("width-request", width_request),
327 }
328 }
329
330 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
333 pub fn build(self) -> HeaderBar {
334 self.builder.build()
335 }
336}
337
338mod sealed {
339 pub trait Sealed {}
340 impl<T: super::IsA<super::HeaderBar>> Sealed for T {}
341}
342
343pub trait HeaderBarExt: IsA<HeaderBar> + sealed::Sealed + 'static {
344 #[doc(alias = "gtk_header_bar_get_custom_title")]
345 #[doc(alias = "get_custom_title")]
346 fn custom_title(&self) -> Option<Widget> {
347 unsafe {
348 from_glib_none(ffi::gtk_header_bar_get_custom_title(
349 self.as_ref().to_glib_none().0,
350 ))
351 }
352 }
353
354 #[doc(alias = "gtk_header_bar_get_decoration_layout")]
355 #[doc(alias = "get_decoration_layout")]
356 fn decoration_layout(&self) -> Option<glib::GString> {
357 unsafe {
358 from_glib_none(ffi::gtk_header_bar_get_decoration_layout(
359 self.as_ref().to_glib_none().0,
360 ))
361 }
362 }
363
364 #[doc(alias = "gtk_header_bar_get_has_subtitle")]
365 #[doc(alias = "get_has_subtitle")]
366 fn has_subtitle(&self) -> bool {
367 unsafe {
368 from_glib(ffi::gtk_header_bar_get_has_subtitle(
369 self.as_ref().to_glib_none().0,
370 ))
371 }
372 }
373
374 #[doc(alias = "gtk_header_bar_get_show_close_button")]
375 #[doc(alias = "get_show_close_button")]
376 fn shows_close_button(&self) -> bool {
377 unsafe {
378 from_glib(ffi::gtk_header_bar_get_show_close_button(
379 self.as_ref().to_glib_none().0,
380 ))
381 }
382 }
383
384 #[doc(alias = "gtk_header_bar_get_subtitle")]
385 #[doc(alias = "get_subtitle")]
386 fn subtitle(&self) -> Option<glib::GString> {
387 unsafe {
388 from_glib_none(ffi::gtk_header_bar_get_subtitle(
389 self.as_ref().to_glib_none().0,
390 ))
391 }
392 }
393
394 #[doc(alias = "gtk_header_bar_get_title")]
395 #[doc(alias = "get_title")]
396 fn title(&self) -> Option<glib::GString> {
397 unsafe {
398 from_glib_none(ffi::gtk_header_bar_get_title(
399 self.as_ref().to_glib_none().0,
400 ))
401 }
402 }
403
404 #[doc(alias = "gtk_header_bar_pack_end")]
405 fn pack_end(&self, child: &impl IsA<Widget>) {
406 unsafe {
407 ffi::gtk_header_bar_pack_end(
408 self.as_ref().to_glib_none().0,
409 child.as_ref().to_glib_none().0,
410 );
411 }
412 }
413
414 #[doc(alias = "gtk_header_bar_pack_start")]
415 fn pack_start(&self, child: &impl IsA<Widget>) {
416 unsafe {
417 ffi::gtk_header_bar_pack_start(
418 self.as_ref().to_glib_none().0,
419 child.as_ref().to_glib_none().0,
420 );
421 }
422 }
423
424 #[doc(alias = "gtk_header_bar_set_custom_title")]
425 fn set_custom_title(&self, title_widget: Option<&impl IsA<Widget>>) {
426 unsafe {
427 ffi::gtk_header_bar_set_custom_title(
428 self.as_ref().to_glib_none().0,
429 title_widget.map(|p| p.as_ref()).to_glib_none().0,
430 );
431 }
432 }
433
434 #[doc(alias = "gtk_header_bar_set_decoration_layout")]
435 fn set_decoration_layout(&self, layout: Option<&str>) {
436 unsafe {
437 ffi::gtk_header_bar_set_decoration_layout(
438 self.as_ref().to_glib_none().0,
439 layout.to_glib_none().0,
440 );
441 }
442 }
443
444 #[doc(alias = "gtk_header_bar_set_has_subtitle")]
445 fn set_has_subtitle(&self, setting: bool) {
446 unsafe {
447 ffi::gtk_header_bar_set_has_subtitle(
448 self.as_ref().to_glib_none().0,
449 setting.into_glib(),
450 );
451 }
452 }
453
454 #[doc(alias = "gtk_header_bar_set_show_close_button")]
455 fn set_show_close_button(&self, setting: bool) {
456 unsafe {
457 ffi::gtk_header_bar_set_show_close_button(
458 self.as_ref().to_glib_none().0,
459 setting.into_glib(),
460 );
461 }
462 }
463
464 #[doc(alias = "gtk_header_bar_set_subtitle")]
465 fn set_subtitle(&self, subtitle: Option<&str>) {
466 unsafe {
467 ffi::gtk_header_bar_set_subtitle(
468 self.as_ref().to_glib_none().0,
469 subtitle.to_glib_none().0,
470 );
471 }
472 }
473
474 #[doc(alias = "gtk_header_bar_set_title")]
475 fn set_title(&self, title: Option<&str>) {
476 unsafe {
477 ffi::gtk_header_bar_set_title(self.as_ref().to_glib_none().0, title.to_glib_none().0);
478 }
479 }
480
481 #[doc(alias = "decoration-layout-set")]
482 fn is_decoration_layout_set(&self) -> bool {
483 ObjectExt::property(self.as_ref(), "decoration-layout-set")
484 }
485
486 #[doc(alias = "decoration-layout-set")]
487 fn set_decoration_layout_set(&self, decoration_layout_set: bool) {
488 ObjectExt::set_property(
489 self.as_ref(),
490 "decoration-layout-set",
491 decoration_layout_set,
492 )
493 }
494
495 fn spacing(&self) -> i32 {
496 ObjectExt::property(self.as_ref(), "spacing")
497 }
498
499 fn set_spacing(&self, spacing: i32) {
500 ObjectExt::set_property(self.as_ref(), "spacing", spacing)
501 }
502
503 #[doc(alias = "child.pack-type")]
504 fn child_pack_type<T: IsA<crate::Widget>>(&self, item: &T) -> PackType {
505 crate::prelude::ContainerExtManual::child_property(
506 self.as_ref(),
507 &item.clone().upcast(),
508 "pack-type",
509 )
510 }
511
512 #[doc(alias = "child.pack-type")]
513 fn set_child_pack_type<T: IsA<crate::Widget>>(&self, item: &T, pack_type: PackType) {
514 crate::prelude::ContainerExtManual::child_set_property(
515 self.as_ref(),
516 &item.clone().upcast(),
517 "pack-type",
518 &pack_type,
519 )
520 }
521
522 fn child_position<T: IsA<crate::Widget>>(&self, item: &T) -> i32 {
523 crate::prelude::ContainerExtManual::child_property(
524 self.as_ref(),
525 &item.clone().upcast(),
526 "position",
527 )
528 }
529
530 fn set_child_position<T: IsA<crate::Widget>>(&self, item: &T, position: i32) {
531 crate::prelude::ContainerExtManual::child_set_property(
532 self.as_ref(),
533 &item.clone().upcast(),
534 "position",
535 &position,
536 )
537 }
538
539 #[doc(alias = "custom-title")]
540 fn connect_custom_title_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
541 unsafe extern "C" fn notify_custom_title_trampoline<
542 P: IsA<HeaderBar>,
543 F: Fn(&P) + 'static,
544 >(
545 this: *mut ffi::GtkHeaderBar,
546 _param_spec: glib::ffi::gpointer,
547 f: glib::ffi::gpointer,
548 ) {
549 let f: &F = &*(f as *const F);
550 f(HeaderBar::from_glib_borrow(this).unsafe_cast_ref())
551 }
552 unsafe {
553 let f: Box_<F> = Box_::new(f);
554 connect_raw(
555 self.as_ptr() as *mut _,
556 b"notify::custom-title\0".as_ptr() as *const _,
557 Some(transmute::<_, unsafe extern "C" fn()>(
558 notify_custom_title_trampoline::<Self, F> as *const (),
559 )),
560 Box_::into_raw(f),
561 )
562 }
563 }
564
565 #[doc(alias = "decoration-layout")]
566 fn connect_decoration_layout_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
567 unsafe extern "C" fn notify_decoration_layout_trampoline<
568 P: IsA<HeaderBar>,
569 F: Fn(&P) + 'static,
570 >(
571 this: *mut ffi::GtkHeaderBar,
572 _param_spec: glib::ffi::gpointer,
573 f: glib::ffi::gpointer,
574 ) {
575 let f: &F = &*(f as *const F);
576 f(HeaderBar::from_glib_borrow(this).unsafe_cast_ref())
577 }
578 unsafe {
579 let f: Box_<F> = Box_::new(f);
580 connect_raw(
581 self.as_ptr() as *mut _,
582 b"notify::decoration-layout\0".as_ptr() as *const _,
583 Some(transmute::<_, unsafe extern "C" fn()>(
584 notify_decoration_layout_trampoline::<Self, F> as *const (),
585 )),
586 Box_::into_raw(f),
587 )
588 }
589 }
590
591 #[doc(alias = "decoration-layout-set")]
592 fn connect_decoration_layout_set_notify<F: Fn(&Self) + 'static>(
593 &self,
594 f: F,
595 ) -> SignalHandlerId {
596 unsafe extern "C" fn notify_decoration_layout_set_trampoline<
597 P: IsA<HeaderBar>,
598 F: Fn(&P) + 'static,
599 >(
600 this: *mut ffi::GtkHeaderBar,
601 _param_spec: glib::ffi::gpointer,
602 f: glib::ffi::gpointer,
603 ) {
604 let f: &F = &*(f as *const F);
605 f(HeaderBar::from_glib_borrow(this).unsafe_cast_ref())
606 }
607 unsafe {
608 let f: Box_<F> = Box_::new(f);
609 connect_raw(
610 self.as_ptr() as *mut _,
611 b"notify::decoration-layout-set\0".as_ptr() as *const _,
612 Some(transmute::<_, unsafe extern "C" fn()>(
613 notify_decoration_layout_set_trampoline::<Self, F> as *const (),
614 )),
615 Box_::into_raw(f),
616 )
617 }
618 }
619
620 #[doc(alias = "has-subtitle")]
621 fn connect_has_subtitle_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
622 unsafe extern "C" fn notify_has_subtitle_trampoline<
623 P: IsA<HeaderBar>,
624 F: Fn(&P) + 'static,
625 >(
626 this: *mut ffi::GtkHeaderBar,
627 _param_spec: glib::ffi::gpointer,
628 f: glib::ffi::gpointer,
629 ) {
630 let f: &F = &*(f as *const F);
631 f(HeaderBar::from_glib_borrow(this).unsafe_cast_ref())
632 }
633 unsafe {
634 let f: Box_<F> = Box_::new(f);
635 connect_raw(
636 self.as_ptr() as *mut _,
637 b"notify::has-subtitle\0".as_ptr() as *const _,
638 Some(transmute::<_, unsafe extern "C" fn()>(
639 notify_has_subtitle_trampoline::<Self, F> as *const (),
640 )),
641 Box_::into_raw(f),
642 )
643 }
644 }
645
646 #[doc(alias = "show-close-button")]
647 fn connect_show_close_button_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
648 unsafe extern "C" fn notify_show_close_button_trampoline<
649 P: IsA<HeaderBar>,
650 F: Fn(&P) + 'static,
651 >(
652 this: *mut ffi::GtkHeaderBar,
653 _param_spec: glib::ffi::gpointer,
654 f: glib::ffi::gpointer,
655 ) {
656 let f: &F = &*(f as *const F);
657 f(HeaderBar::from_glib_borrow(this).unsafe_cast_ref())
658 }
659 unsafe {
660 let f: Box_<F> = Box_::new(f);
661 connect_raw(
662 self.as_ptr() as *mut _,
663 b"notify::show-close-button\0".as_ptr() as *const _,
664 Some(transmute::<_, unsafe extern "C" fn()>(
665 notify_show_close_button_trampoline::<Self, F> as *const (),
666 )),
667 Box_::into_raw(f),
668 )
669 }
670 }
671
672 #[doc(alias = "spacing")]
673 fn connect_spacing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
674 unsafe extern "C" fn notify_spacing_trampoline<P: IsA<HeaderBar>, F: Fn(&P) + 'static>(
675 this: *mut ffi::GtkHeaderBar,
676 _param_spec: glib::ffi::gpointer,
677 f: glib::ffi::gpointer,
678 ) {
679 let f: &F = &*(f as *const F);
680 f(HeaderBar::from_glib_borrow(this).unsafe_cast_ref())
681 }
682 unsafe {
683 let f: Box_<F> = Box_::new(f);
684 connect_raw(
685 self.as_ptr() as *mut _,
686 b"notify::spacing\0".as_ptr() as *const _,
687 Some(transmute::<_, unsafe extern "C" fn()>(
688 notify_spacing_trampoline::<Self, F> as *const (),
689 )),
690 Box_::into_raw(f),
691 )
692 }
693 }
694
695 #[doc(alias = "subtitle")]
696 fn connect_subtitle_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
697 unsafe extern "C" fn notify_subtitle_trampoline<P: IsA<HeaderBar>, F: Fn(&P) + 'static>(
698 this: *mut ffi::GtkHeaderBar,
699 _param_spec: glib::ffi::gpointer,
700 f: glib::ffi::gpointer,
701 ) {
702 let f: &F = &*(f as *const F);
703 f(HeaderBar::from_glib_borrow(this).unsafe_cast_ref())
704 }
705 unsafe {
706 let f: Box_<F> = Box_::new(f);
707 connect_raw(
708 self.as_ptr() as *mut _,
709 b"notify::subtitle\0".as_ptr() as *const _,
710 Some(transmute::<_, unsafe extern "C" fn()>(
711 notify_subtitle_trampoline::<Self, F> as *const (),
712 )),
713 Box_::into_raw(f),
714 )
715 }
716 }
717
718 #[doc(alias = "title")]
719 fn connect_title_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
720 unsafe extern "C" fn notify_title_trampoline<P: IsA<HeaderBar>, F: Fn(&P) + 'static>(
721 this: *mut ffi::GtkHeaderBar,
722 _param_spec: glib::ffi::gpointer,
723 f: glib::ffi::gpointer,
724 ) {
725 let f: &F = &*(f as *const F);
726 f(HeaderBar::from_glib_borrow(this).unsafe_cast_ref())
727 }
728 unsafe {
729 let f: Box_<F> = Box_::new(f);
730 connect_raw(
731 self.as_ptr() as *mut _,
732 b"notify::title\0".as_ptr() as *const _,
733 Some(transmute::<_, unsafe extern "C" fn()>(
734 notify_title_trampoline::<Self, F> as *const (),
735 )),
736 Box_::into_raw(f),
737 )
738 }
739 }
740}
741
742impl<O: IsA<HeaderBar>> HeaderBarExt for O {}
743
744impl fmt::Display for HeaderBar {
745 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
746 f.write_str("HeaderBar")
747 }
748}