Skip to main content

libadwaita/auto/
header_bar.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from
3// from gir-files (https://github.com/gtk-rs/gir-files.git)
4// DO NOT EDIT
5
6use crate::{CenteringPolicy, ffi};
7use glib::{
8    prelude::*,
9    signal::{SignalHandlerId, connect_raw},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14#[cfg(feature = "gtk_v4_10")]
15#[cfg_attr(docsrs, doc(cfg(feature = "gtk_v4_10")))]
16glib::wrapper! {
17    #[doc(alias = "AdwHeaderBar")]
18    pub struct HeaderBar(Object<ffi::AdwHeaderBar, ffi::AdwHeaderBarClass>) @extends gtk::Widget, @implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget;
19
20    match fn {
21        type_ => || ffi::adw_header_bar_get_type(),
22    }
23}
24
25#[cfg(not(feature = "gtk_v4_10"))]
26glib::wrapper! {
27    #[doc(alias = "AdwHeaderBar")]
28    pub struct HeaderBar(Object<ffi::AdwHeaderBar, ffi::AdwHeaderBarClass>) @extends gtk::Widget, @implements gtk::Buildable, gtk::ConstraintTarget;
29
30    match fn {
31        type_ => || ffi::adw_header_bar_get_type(),
32    }
33}
34
35impl HeaderBar {
36    #[doc(alias = "adw_header_bar_new")]
37    pub fn new() -> HeaderBar {
38        assert_initialized_main_thread!();
39        unsafe { gtk::Widget::from_glib_none(ffi::adw_header_bar_new()).unsafe_cast() }
40    }
41
42    // rustdoc-stripper-ignore-next
43    /// Creates a new builder-pattern struct instance to construct [`HeaderBar`] objects.
44    ///
45    /// This method returns an instance of [`HeaderBarBuilder`](crate::builders::HeaderBarBuilder) which can be used to create [`HeaderBar`] objects.
46    pub fn builder() -> HeaderBarBuilder {
47        HeaderBarBuilder::new()
48    }
49
50    #[doc(alias = "adw_header_bar_get_centering_policy")]
51    #[doc(alias = "get_centering_policy")]
52    #[doc(alias = "centering-policy")]
53    pub fn centering_policy(&self) -> CenteringPolicy {
54        unsafe {
55            from_glib(ffi::adw_header_bar_get_centering_policy(
56                self.to_glib_none().0,
57            ))
58        }
59    }
60
61    #[doc(alias = "adw_header_bar_get_decoration_layout")]
62    #[doc(alias = "get_decoration_layout")]
63    #[doc(alias = "decoration-layout")]
64    pub fn decoration_layout(&self) -> Option<glib::GString> {
65        unsafe {
66            from_glib_none(ffi::adw_header_bar_get_decoration_layout(
67                self.to_glib_none().0,
68            ))
69        }
70    }
71
72    #[cfg(feature = "v1_4")]
73    #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
74    #[doc(alias = "adw_header_bar_get_show_back_button")]
75    #[doc(alias = "get_show_back_button")]
76    #[doc(alias = "show-back-button")]
77    pub fn shows_back_button(&self) -> bool {
78        unsafe {
79            from_glib(ffi::adw_header_bar_get_show_back_button(
80                self.to_glib_none().0,
81            ))
82        }
83    }
84
85    #[doc(alias = "adw_header_bar_get_show_end_title_buttons")]
86    #[doc(alias = "get_show_end_title_buttons")]
87    #[doc(alias = "show-end-title-buttons")]
88    pub fn shows_end_title_buttons(&self) -> bool {
89        unsafe {
90            from_glib(ffi::adw_header_bar_get_show_end_title_buttons(
91                self.to_glib_none().0,
92            ))
93        }
94    }
95
96    #[doc(alias = "adw_header_bar_get_show_start_title_buttons")]
97    #[doc(alias = "get_show_start_title_buttons")]
98    #[doc(alias = "show-start-title-buttons")]
99    pub fn shows_start_title_buttons(&self) -> bool {
100        unsafe {
101            from_glib(ffi::adw_header_bar_get_show_start_title_buttons(
102                self.to_glib_none().0,
103            ))
104        }
105    }
106
107    #[cfg(feature = "v1_4")]
108    #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
109    #[doc(alias = "adw_header_bar_get_show_title")]
110    #[doc(alias = "get_show_title")]
111    #[doc(alias = "show-title")]
112    pub fn shows_title(&self) -> bool {
113        unsafe { from_glib(ffi::adw_header_bar_get_show_title(self.to_glib_none().0)) }
114    }
115
116    #[doc(alias = "adw_header_bar_get_title_widget")]
117    #[doc(alias = "get_title_widget")]
118    #[doc(alias = "title-widget")]
119    pub fn title_widget(&self) -> Option<gtk::Widget> {
120        unsafe { from_glib_none(ffi::adw_header_bar_get_title_widget(self.to_glib_none().0)) }
121    }
122
123    #[doc(alias = "adw_header_bar_pack_end")]
124    pub fn pack_end(&self, child: &impl IsA<gtk::Widget>) {
125        unsafe {
126            ffi::adw_header_bar_pack_end(self.to_glib_none().0, child.as_ref().to_glib_none().0);
127        }
128    }
129
130    #[doc(alias = "adw_header_bar_pack_start")]
131    pub fn pack_start(&self, child: &impl IsA<gtk::Widget>) {
132        unsafe {
133            ffi::adw_header_bar_pack_start(self.to_glib_none().0, child.as_ref().to_glib_none().0);
134        }
135    }
136
137    #[doc(alias = "adw_header_bar_remove")]
138    pub fn remove(&self, child: &impl IsA<gtk::Widget>) {
139        unsafe {
140            ffi::adw_header_bar_remove(self.to_glib_none().0, child.as_ref().to_glib_none().0);
141        }
142    }
143
144    #[doc(alias = "adw_header_bar_set_centering_policy")]
145    #[doc(alias = "centering-policy")]
146    pub fn set_centering_policy(&self, centering_policy: CenteringPolicy) {
147        unsafe {
148            ffi::adw_header_bar_set_centering_policy(
149                self.to_glib_none().0,
150                centering_policy.into_glib(),
151            );
152        }
153    }
154
155    #[doc(alias = "adw_header_bar_set_decoration_layout")]
156    #[doc(alias = "decoration-layout")]
157    pub fn set_decoration_layout(&self, layout: Option<&str>) {
158        unsafe {
159            ffi::adw_header_bar_set_decoration_layout(
160                self.to_glib_none().0,
161                layout.to_glib_none().0,
162            );
163        }
164    }
165
166    #[cfg(feature = "v1_4")]
167    #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
168    #[doc(alias = "adw_header_bar_set_show_back_button")]
169    #[doc(alias = "show-back-button")]
170    pub fn set_show_back_button(&self, show_back_button: bool) {
171        unsafe {
172            ffi::adw_header_bar_set_show_back_button(
173                self.to_glib_none().0,
174                show_back_button.into_glib(),
175            );
176        }
177    }
178
179    #[doc(alias = "adw_header_bar_set_show_end_title_buttons")]
180    #[doc(alias = "show-end-title-buttons")]
181    pub fn set_show_end_title_buttons(&self, setting: bool) {
182        unsafe {
183            ffi::adw_header_bar_set_show_end_title_buttons(
184                self.to_glib_none().0,
185                setting.into_glib(),
186            );
187        }
188    }
189
190    #[doc(alias = "adw_header_bar_set_show_start_title_buttons")]
191    #[doc(alias = "show-start-title-buttons")]
192    pub fn set_show_start_title_buttons(&self, setting: bool) {
193        unsafe {
194            ffi::adw_header_bar_set_show_start_title_buttons(
195                self.to_glib_none().0,
196                setting.into_glib(),
197            );
198        }
199    }
200
201    #[cfg(feature = "v1_4")]
202    #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
203    #[doc(alias = "adw_header_bar_set_show_title")]
204    #[doc(alias = "show-title")]
205    pub fn set_show_title(&self, show_title: bool) {
206        unsafe {
207            ffi::adw_header_bar_set_show_title(self.to_glib_none().0, show_title.into_glib());
208        }
209    }
210
211    #[doc(alias = "adw_header_bar_set_title_widget")]
212    #[doc(alias = "title-widget")]
213    pub fn set_title_widget(&self, title_widget: Option<&impl IsA<gtk::Widget>>) {
214        unsafe {
215            ffi::adw_header_bar_set_title_widget(
216                self.to_glib_none().0,
217                title_widget.map(|p| p.as_ref()).to_glib_none().0,
218            );
219        }
220    }
221
222    #[doc(alias = "centering-policy")]
223    pub fn connect_centering_policy_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
224        unsafe extern "C" fn notify_centering_policy_trampoline<F: Fn(&HeaderBar) + 'static>(
225            this: *mut ffi::AdwHeaderBar,
226            _param_spec: glib::ffi::gpointer,
227            f: glib::ffi::gpointer,
228        ) {
229            unsafe {
230                let f: &F = &*(f as *const F);
231                f(&from_glib_borrow(this))
232            }
233        }
234        unsafe {
235            let f: Box_<F> = Box_::new(f);
236            connect_raw(
237                self.as_ptr() as *mut _,
238                c"notify::centering-policy".as_ptr(),
239                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
240                    notify_centering_policy_trampoline::<F> as *const (),
241                )),
242                Box_::into_raw(f),
243            )
244        }
245    }
246
247    #[doc(alias = "decoration-layout")]
248    pub fn connect_decoration_layout_notify<F: Fn(&Self) + 'static>(
249        &self,
250        f: F,
251    ) -> SignalHandlerId {
252        unsafe extern "C" fn notify_decoration_layout_trampoline<F: Fn(&HeaderBar) + 'static>(
253            this: *mut ffi::AdwHeaderBar,
254            _param_spec: glib::ffi::gpointer,
255            f: glib::ffi::gpointer,
256        ) {
257            unsafe {
258                let f: &F = &*(f as *const F);
259                f(&from_glib_borrow(this))
260            }
261        }
262        unsafe {
263            let f: Box_<F> = Box_::new(f);
264            connect_raw(
265                self.as_ptr() as *mut _,
266                c"notify::decoration-layout".as_ptr(),
267                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
268                    notify_decoration_layout_trampoline::<F> as *const (),
269                )),
270                Box_::into_raw(f),
271            )
272        }
273    }
274
275    #[cfg(feature = "v1_4")]
276    #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
277    #[doc(alias = "show-back-button")]
278    pub fn connect_show_back_button_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
279        unsafe extern "C" fn notify_show_back_button_trampoline<F: Fn(&HeaderBar) + 'static>(
280            this: *mut ffi::AdwHeaderBar,
281            _param_spec: glib::ffi::gpointer,
282            f: glib::ffi::gpointer,
283        ) {
284            unsafe {
285                let f: &F = &*(f as *const F);
286                f(&from_glib_borrow(this))
287            }
288        }
289        unsafe {
290            let f: Box_<F> = Box_::new(f);
291            connect_raw(
292                self.as_ptr() as *mut _,
293                c"notify::show-back-button".as_ptr(),
294                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
295                    notify_show_back_button_trampoline::<F> as *const (),
296                )),
297                Box_::into_raw(f),
298            )
299        }
300    }
301
302    #[doc(alias = "show-end-title-buttons")]
303    pub fn connect_show_end_title_buttons_notify<F: Fn(&Self) + 'static>(
304        &self,
305        f: F,
306    ) -> SignalHandlerId {
307        unsafe extern "C" fn notify_show_end_title_buttons_trampoline<
308            F: Fn(&HeaderBar) + 'static,
309        >(
310            this: *mut ffi::AdwHeaderBar,
311            _param_spec: glib::ffi::gpointer,
312            f: glib::ffi::gpointer,
313        ) {
314            unsafe {
315                let f: &F = &*(f as *const F);
316                f(&from_glib_borrow(this))
317            }
318        }
319        unsafe {
320            let f: Box_<F> = Box_::new(f);
321            connect_raw(
322                self.as_ptr() as *mut _,
323                c"notify::show-end-title-buttons".as_ptr(),
324                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
325                    notify_show_end_title_buttons_trampoline::<F> as *const (),
326                )),
327                Box_::into_raw(f),
328            )
329        }
330    }
331
332    #[doc(alias = "show-start-title-buttons")]
333    pub fn connect_show_start_title_buttons_notify<F: Fn(&Self) + 'static>(
334        &self,
335        f: F,
336    ) -> SignalHandlerId {
337        unsafe extern "C" fn notify_show_start_title_buttons_trampoline<
338            F: Fn(&HeaderBar) + 'static,
339        >(
340            this: *mut ffi::AdwHeaderBar,
341            _param_spec: glib::ffi::gpointer,
342            f: glib::ffi::gpointer,
343        ) {
344            unsafe {
345                let f: &F = &*(f as *const F);
346                f(&from_glib_borrow(this))
347            }
348        }
349        unsafe {
350            let f: Box_<F> = Box_::new(f);
351            connect_raw(
352                self.as_ptr() as *mut _,
353                c"notify::show-start-title-buttons".as_ptr(),
354                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
355                    notify_show_start_title_buttons_trampoline::<F> as *const (),
356                )),
357                Box_::into_raw(f),
358            )
359        }
360    }
361
362    #[cfg(feature = "v1_4")]
363    #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
364    #[doc(alias = "show-title")]
365    pub fn connect_show_title_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
366        unsafe extern "C" fn notify_show_title_trampoline<F: Fn(&HeaderBar) + 'static>(
367            this: *mut ffi::AdwHeaderBar,
368            _param_spec: glib::ffi::gpointer,
369            f: glib::ffi::gpointer,
370        ) {
371            unsafe {
372                let f: &F = &*(f as *const F);
373                f(&from_glib_borrow(this))
374            }
375        }
376        unsafe {
377            let f: Box_<F> = Box_::new(f);
378            connect_raw(
379                self.as_ptr() as *mut _,
380                c"notify::show-title".as_ptr(),
381                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
382                    notify_show_title_trampoline::<F> as *const (),
383                )),
384                Box_::into_raw(f),
385            )
386        }
387    }
388
389    #[doc(alias = "title-widget")]
390    pub fn connect_title_widget_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
391        unsafe extern "C" fn notify_title_widget_trampoline<F: Fn(&HeaderBar) + 'static>(
392            this: *mut ffi::AdwHeaderBar,
393            _param_spec: glib::ffi::gpointer,
394            f: glib::ffi::gpointer,
395        ) {
396            unsafe {
397                let f: &F = &*(f as *const F);
398                f(&from_glib_borrow(this))
399            }
400        }
401        unsafe {
402            let f: Box_<F> = Box_::new(f);
403            connect_raw(
404                self.as_ptr() as *mut _,
405                c"notify::title-widget".as_ptr(),
406                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
407                    notify_title_widget_trampoline::<F> as *const (),
408                )),
409                Box_::into_raw(f),
410            )
411        }
412    }
413}
414
415impl Default for HeaderBar {
416    fn default() -> Self {
417        Self::new()
418    }
419}
420
421// rustdoc-stripper-ignore-next
422/// A [builder-pattern] type to construct [`HeaderBar`] objects.
423///
424/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
425#[must_use = "The builder must be built to be used"]
426pub struct HeaderBarBuilder {
427    builder: glib::object::ObjectBuilder<'static, HeaderBar>,
428}
429
430impl HeaderBarBuilder {
431    fn new() -> Self {
432        Self {
433            builder: glib::object::Object::builder(),
434        }
435    }
436
437    pub fn centering_policy(self, centering_policy: CenteringPolicy) -> Self {
438        Self {
439            builder: self.builder.property("centering-policy", centering_policy),
440        }
441    }
442
443    pub fn decoration_layout(self, decoration_layout: impl Into<glib::GString>) -> Self {
444        Self {
445            builder: self
446                .builder
447                .property("decoration-layout", decoration_layout.into()),
448        }
449    }
450
451    #[cfg(feature = "v1_4")]
452    #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
453    pub fn show_back_button(self, show_back_button: bool) -> Self {
454        Self {
455            builder: self.builder.property("show-back-button", show_back_button),
456        }
457    }
458
459    pub fn show_end_title_buttons(self, show_end_title_buttons: bool) -> Self {
460        Self {
461            builder: self
462                .builder
463                .property("show-end-title-buttons", show_end_title_buttons),
464        }
465    }
466
467    pub fn show_start_title_buttons(self, show_start_title_buttons: bool) -> Self {
468        Self {
469            builder: self
470                .builder
471                .property("show-start-title-buttons", show_start_title_buttons),
472        }
473    }
474
475    #[cfg(feature = "v1_4")]
476    #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
477    pub fn show_title(self, show_title: bool) -> Self {
478        Self {
479            builder: self.builder.property("show-title", show_title),
480        }
481    }
482
483    pub fn title_widget(self, title_widget: &impl IsA<gtk::Widget>) -> Self {
484        Self {
485            builder: self
486                .builder
487                .property("title-widget", title_widget.clone().upcast()),
488        }
489    }
490
491    pub fn can_focus(self, can_focus: bool) -> Self {
492        Self {
493            builder: self.builder.property("can-focus", can_focus),
494        }
495    }
496
497    pub fn can_target(self, can_target: bool) -> Self {
498        Self {
499            builder: self.builder.property("can-target", can_target),
500        }
501    }
502
503    pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
504        Self {
505            builder: self.builder.property("css-classes", css_classes.into()),
506        }
507    }
508
509    pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
510        Self {
511            builder: self.builder.property("css-name", css_name.into()),
512        }
513    }
514
515    pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
516        Self {
517            builder: self.builder.property("cursor", cursor.clone()),
518        }
519    }
520
521    pub fn focus_on_click(self, focus_on_click: bool) -> Self {
522        Self {
523            builder: self.builder.property("focus-on-click", focus_on_click),
524        }
525    }
526
527    pub fn focusable(self, focusable: bool) -> Self {
528        Self {
529            builder: self.builder.property("focusable", focusable),
530        }
531    }
532
533    pub fn halign(self, halign: gtk::Align) -> Self {
534        Self {
535            builder: self.builder.property("halign", halign),
536        }
537    }
538
539    pub fn has_tooltip(self, has_tooltip: bool) -> Self {
540        Self {
541            builder: self.builder.property("has-tooltip", has_tooltip),
542        }
543    }
544
545    pub fn height_request(self, height_request: i32) -> Self {
546        Self {
547            builder: self.builder.property("height-request", height_request),
548        }
549    }
550
551    pub fn hexpand(self, hexpand: bool) -> Self {
552        Self {
553            builder: self.builder.property("hexpand", hexpand),
554        }
555    }
556
557    pub fn hexpand_set(self, hexpand_set: bool) -> Self {
558        Self {
559            builder: self.builder.property("hexpand-set", hexpand_set),
560        }
561    }
562
563    pub fn layout_manager(self, layout_manager: &impl IsA<gtk::LayoutManager>) -> Self {
564        Self {
565            builder: self
566                .builder
567                .property("layout-manager", layout_manager.clone().upcast()),
568        }
569    }
570
571    #[cfg(feature = "gtk_v4_18")]
572    #[cfg_attr(docsrs, doc(cfg(feature = "gtk_v4_18")))]
573    pub fn limit_events(self, limit_events: bool) -> Self {
574        Self {
575            builder: self.builder.property("limit-events", limit_events),
576        }
577    }
578
579    pub fn margin_bottom(self, margin_bottom: i32) -> Self {
580        Self {
581            builder: self.builder.property("margin-bottom", margin_bottom),
582        }
583    }
584
585    pub fn margin_end(self, margin_end: i32) -> Self {
586        Self {
587            builder: self.builder.property("margin-end", margin_end),
588        }
589    }
590
591    pub fn margin_start(self, margin_start: i32) -> Self {
592        Self {
593            builder: self.builder.property("margin-start", margin_start),
594        }
595    }
596
597    pub fn margin_top(self, margin_top: i32) -> Self {
598        Self {
599            builder: self.builder.property("margin-top", margin_top),
600        }
601    }
602
603    pub fn name(self, name: impl Into<glib::GString>) -> Self {
604        Self {
605            builder: self.builder.property("name", name.into()),
606        }
607    }
608
609    pub fn opacity(self, opacity: f64) -> Self {
610        Self {
611            builder: self.builder.property("opacity", opacity),
612        }
613    }
614
615    pub fn overflow(self, overflow: gtk::Overflow) -> Self {
616        Self {
617            builder: self.builder.property("overflow", overflow),
618        }
619    }
620
621    pub fn receives_default(self, receives_default: bool) -> Self {
622        Self {
623            builder: self.builder.property("receives-default", receives_default),
624        }
625    }
626
627    pub fn sensitive(self, sensitive: bool) -> Self {
628        Self {
629            builder: self.builder.property("sensitive", sensitive),
630        }
631    }
632
633    pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
634        Self {
635            builder: self
636                .builder
637                .property("tooltip-markup", tooltip_markup.into()),
638        }
639    }
640
641    pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
642        Self {
643            builder: self.builder.property("tooltip-text", tooltip_text.into()),
644        }
645    }
646
647    pub fn valign(self, valign: gtk::Align) -> Self {
648        Self {
649            builder: self.builder.property("valign", valign),
650        }
651    }
652
653    pub fn vexpand(self, vexpand: bool) -> Self {
654        Self {
655            builder: self.builder.property("vexpand", vexpand),
656        }
657    }
658
659    pub fn vexpand_set(self, vexpand_set: bool) -> Self {
660        Self {
661            builder: self.builder.property("vexpand-set", vexpand_set),
662        }
663    }
664
665    pub fn visible(self, visible: bool) -> Self {
666        Self {
667            builder: self.builder.property("visible", visible),
668        }
669    }
670
671    pub fn width_request(self, width_request: i32) -> Self {
672        Self {
673            builder: self.builder.property("width-request", width_request),
674        }
675    }
676
677    pub fn accessible_role(self, accessible_role: gtk::AccessibleRole) -> Self {
678        Self {
679            builder: self.builder.property("accessible-role", accessible_role),
680        }
681    }
682
683    // rustdoc-stripper-ignore-next
684    /// Build the [`HeaderBar`].
685    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
686    pub fn build(self) -> HeaderBar {
687        assert_initialized_main_thread!();
688        self.builder.build()
689    }
690}