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