1use crate::{CenteringPolicy, ffi};
7use glib::{
8 prelude::*,
9 signal::{SignalHandlerId, connect_raw},
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 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 unsafe {
218 let f: &F = &*(f as *const F);
219 f(&from_glib_borrow(this))
220 }
221 }
222 unsafe {
223 let f: Box_<F> = Box_::new(f);
224 connect_raw(
225 self.as_ptr() as *mut _,
226 c"notify::centering-policy".as_ptr(),
227 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
228 notify_centering_policy_trampoline::<F> as *const (),
229 )),
230 Box_::into_raw(f),
231 )
232 }
233 }
234
235 #[doc(alias = "decoration-layout")]
236 pub fn connect_decoration_layout_notify<F: Fn(&Self) + 'static>(
237 &self,
238 f: F,
239 ) -> SignalHandlerId {
240 unsafe extern "C" fn notify_decoration_layout_trampoline<F: Fn(&HeaderBar) + 'static>(
241 this: *mut ffi::AdwHeaderBar,
242 _param_spec: glib::ffi::gpointer,
243 f: glib::ffi::gpointer,
244 ) {
245 unsafe {
246 let f: &F = &*(f as *const F);
247 f(&from_glib_borrow(this))
248 }
249 }
250 unsafe {
251 let f: Box_<F> = Box_::new(f);
252 connect_raw(
253 self.as_ptr() as *mut _,
254 c"notify::decoration-layout".as_ptr(),
255 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
256 notify_decoration_layout_trampoline::<F> as *const (),
257 )),
258 Box_::into_raw(f),
259 )
260 }
261 }
262
263 #[cfg(feature = "v1_4")]
264 #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
265 #[doc(alias = "show-back-button")]
266 pub fn connect_show_back_button_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
267 unsafe extern "C" fn notify_show_back_button_trampoline<F: Fn(&HeaderBar) + 'static>(
268 this: *mut ffi::AdwHeaderBar,
269 _param_spec: glib::ffi::gpointer,
270 f: glib::ffi::gpointer,
271 ) {
272 unsafe {
273 let f: &F = &*(f as *const F);
274 f(&from_glib_borrow(this))
275 }
276 }
277 unsafe {
278 let f: Box_<F> = Box_::new(f);
279 connect_raw(
280 self.as_ptr() as *mut _,
281 c"notify::show-back-button".as_ptr(),
282 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
283 notify_show_back_button_trampoline::<F> as *const (),
284 )),
285 Box_::into_raw(f),
286 )
287 }
288 }
289
290 #[doc(alias = "show-end-title-buttons")]
291 pub fn connect_show_end_title_buttons_notify<F: Fn(&Self) + 'static>(
292 &self,
293 f: F,
294 ) -> SignalHandlerId {
295 unsafe extern "C" fn notify_show_end_title_buttons_trampoline<
296 F: Fn(&HeaderBar) + 'static,
297 >(
298 this: *mut ffi::AdwHeaderBar,
299 _param_spec: glib::ffi::gpointer,
300 f: glib::ffi::gpointer,
301 ) {
302 unsafe {
303 let f: &F = &*(f as *const F);
304 f(&from_glib_borrow(this))
305 }
306 }
307 unsafe {
308 let f: Box_<F> = Box_::new(f);
309 connect_raw(
310 self.as_ptr() as *mut _,
311 c"notify::show-end-title-buttons".as_ptr(),
312 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
313 notify_show_end_title_buttons_trampoline::<F> as *const (),
314 )),
315 Box_::into_raw(f),
316 )
317 }
318 }
319
320 #[doc(alias = "show-start-title-buttons")]
321 pub fn connect_show_start_title_buttons_notify<F: Fn(&Self) + 'static>(
322 &self,
323 f: F,
324 ) -> SignalHandlerId {
325 unsafe extern "C" fn notify_show_start_title_buttons_trampoline<
326 F: Fn(&HeaderBar) + 'static,
327 >(
328 this: *mut ffi::AdwHeaderBar,
329 _param_spec: glib::ffi::gpointer,
330 f: glib::ffi::gpointer,
331 ) {
332 unsafe {
333 let f: &F = &*(f as *const F);
334 f(&from_glib_borrow(this))
335 }
336 }
337 unsafe {
338 let f: Box_<F> = Box_::new(f);
339 connect_raw(
340 self.as_ptr() as *mut _,
341 c"notify::show-start-title-buttons".as_ptr(),
342 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
343 notify_show_start_title_buttons_trampoline::<F> as *const (),
344 )),
345 Box_::into_raw(f),
346 )
347 }
348 }
349
350 #[cfg(feature = "v1_4")]
351 #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
352 #[doc(alias = "show-title")]
353 pub fn connect_show_title_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
354 unsafe extern "C" fn notify_show_title_trampoline<F: Fn(&HeaderBar) + 'static>(
355 this: *mut ffi::AdwHeaderBar,
356 _param_spec: glib::ffi::gpointer,
357 f: glib::ffi::gpointer,
358 ) {
359 unsafe {
360 let f: &F = &*(f as *const F);
361 f(&from_glib_borrow(this))
362 }
363 }
364 unsafe {
365 let f: Box_<F> = Box_::new(f);
366 connect_raw(
367 self.as_ptr() as *mut _,
368 c"notify::show-title".as_ptr(),
369 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
370 notify_show_title_trampoline::<F> as *const (),
371 )),
372 Box_::into_raw(f),
373 )
374 }
375 }
376
377 #[doc(alias = "title-widget")]
378 pub fn connect_title_widget_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
379 unsafe extern "C" fn notify_title_widget_trampoline<F: Fn(&HeaderBar) + 'static>(
380 this: *mut ffi::AdwHeaderBar,
381 _param_spec: glib::ffi::gpointer,
382 f: glib::ffi::gpointer,
383 ) {
384 unsafe {
385 let f: &F = &*(f as *const F);
386 f(&from_glib_borrow(this))
387 }
388 }
389 unsafe {
390 let f: Box_<F> = Box_::new(f);
391 connect_raw(
392 self.as_ptr() as *mut _,
393 c"notify::title-widget".as_ptr(),
394 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
395 notify_title_widget_trampoline::<F> as *const (),
396 )),
397 Box_::into_raw(f),
398 )
399 }
400 }
401}
402
403impl Default for HeaderBar {
404 fn default() -> Self {
405 Self::new()
406 }
407}
408
409#[must_use = "The builder must be built to be used"]
414pub struct HeaderBarBuilder {
415 builder: glib::object::ObjectBuilder<'static, HeaderBar>,
416}
417
418impl HeaderBarBuilder {
419 fn new() -> Self {
420 Self {
421 builder: glib::object::Object::builder(),
422 }
423 }
424
425 pub fn centering_policy(self, centering_policy: CenteringPolicy) -> Self {
426 Self {
427 builder: self.builder.property("centering-policy", centering_policy),
428 }
429 }
430
431 pub fn decoration_layout(self, decoration_layout: impl Into<glib::GString>) -> Self {
432 Self {
433 builder: self
434 .builder
435 .property("decoration-layout", decoration_layout.into()),
436 }
437 }
438
439 #[cfg(feature = "v1_4")]
440 #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
441 pub fn show_back_button(self, show_back_button: bool) -> Self {
442 Self {
443 builder: self.builder.property("show-back-button", show_back_button),
444 }
445 }
446
447 pub fn show_end_title_buttons(self, show_end_title_buttons: bool) -> Self {
448 Self {
449 builder: self
450 .builder
451 .property("show-end-title-buttons", show_end_title_buttons),
452 }
453 }
454
455 pub fn show_start_title_buttons(self, show_start_title_buttons: bool) -> Self {
456 Self {
457 builder: self
458 .builder
459 .property("show-start-title-buttons", show_start_title_buttons),
460 }
461 }
462
463 #[cfg(feature = "v1_4")]
464 #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
465 pub fn show_title(self, show_title: bool) -> Self {
466 Self {
467 builder: self.builder.property("show-title", show_title),
468 }
469 }
470
471 pub fn title_widget(self, title_widget: &impl IsA<gtk::Widget>) -> Self {
472 Self {
473 builder: self
474 .builder
475 .property("title-widget", title_widget.clone().upcast()),
476 }
477 }
478
479 pub fn can_focus(self, can_focus: bool) -> Self {
480 Self {
481 builder: self.builder.property("can-focus", can_focus),
482 }
483 }
484
485 pub fn can_target(self, can_target: bool) -> Self {
486 Self {
487 builder: self.builder.property("can-target", can_target),
488 }
489 }
490
491 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
492 Self {
493 builder: self.builder.property("css-classes", css_classes.into()),
494 }
495 }
496
497 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
498 Self {
499 builder: self.builder.property("css-name", css_name.into()),
500 }
501 }
502
503 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
504 Self {
505 builder: self.builder.property("cursor", cursor.clone()),
506 }
507 }
508
509 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
510 Self {
511 builder: self.builder.property("focus-on-click", focus_on_click),
512 }
513 }
514
515 pub fn focusable(self, focusable: bool) -> Self {
516 Self {
517 builder: self.builder.property("focusable", focusable),
518 }
519 }
520
521 pub fn halign(self, halign: gtk::Align) -> Self {
522 Self {
523 builder: self.builder.property("halign", halign),
524 }
525 }
526
527 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
528 Self {
529 builder: self.builder.property("has-tooltip", has_tooltip),
530 }
531 }
532
533 pub fn height_request(self, height_request: i32) -> Self {
534 Self {
535 builder: self.builder.property("height-request", height_request),
536 }
537 }
538
539 pub fn hexpand(self, hexpand: bool) -> Self {
540 Self {
541 builder: self.builder.property("hexpand", hexpand),
542 }
543 }
544
545 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
546 Self {
547 builder: self.builder.property("hexpand-set", hexpand_set),
548 }
549 }
550
551 pub fn layout_manager(self, layout_manager: &impl IsA<gtk::LayoutManager>) -> Self {
552 Self {
553 builder: self
554 .builder
555 .property("layout-manager", layout_manager.clone().upcast()),
556 }
557 }
558
559 #[cfg(feature = "gtk_v4_18")]
560 #[cfg_attr(docsrs, doc(cfg(feature = "gtk_v4_18")))]
561 pub fn limit_events(self, limit_events: bool) -> Self {
562 Self {
563 builder: self.builder.property("limit-events", limit_events),
564 }
565 }
566
567 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
568 Self {
569 builder: self.builder.property("margin-bottom", margin_bottom),
570 }
571 }
572
573 pub fn margin_end(self, margin_end: i32) -> Self {
574 Self {
575 builder: self.builder.property("margin-end", margin_end),
576 }
577 }
578
579 pub fn margin_start(self, margin_start: i32) -> Self {
580 Self {
581 builder: self.builder.property("margin-start", margin_start),
582 }
583 }
584
585 pub fn margin_top(self, margin_top: i32) -> Self {
586 Self {
587 builder: self.builder.property("margin-top", margin_top),
588 }
589 }
590
591 pub fn name(self, name: impl Into<glib::GString>) -> Self {
592 Self {
593 builder: self.builder.property("name", name.into()),
594 }
595 }
596
597 pub fn opacity(self, opacity: f64) -> Self {
598 Self {
599 builder: self.builder.property("opacity", opacity),
600 }
601 }
602
603 pub fn overflow(self, overflow: gtk::Overflow) -> Self {
604 Self {
605 builder: self.builder.property("overflow", overflow),
606 }
607 }
608
609 pub fn receives_default(self, receives_default: bool) -> Self {
610 Self {
611 builder: self.builder.property("receives-default", receives_default),
612 }
613 }
614
615 pub fn sensitive(self, sensitive: bool) -> Self {
616 Self {
617 builder: self.builder.property("sensitive", sensitive),
618 }
619 }
620
621 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
622 Self {
623 builder: self
624 .builder
625 .property("tooltip-markup", tooltip_markup.into()),
626 }
627 }
628
629 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
630 Self {
631 builder: self.builder.property("tooltip-text", tooltip_text.into()),
632 }
633 }
634
635 pub fn valign(self, valign: gtk::Align) -> Self {
636 Self {
637 builder: self.builder.property("valign", valign),
638 }
639 }
640
641 pub fn vexpand(self, vexpand: bool) -> Self {
642 Self {
643 builder: self.builder.property("vexpand", vexpand),
644 }
645 }
646
647 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
648 Self {
649 builder: self.builder.property("vexpand-set", vexpand_set),
650 }
651 }
652
653 pub fn visible(self, visible: bool) -> Self {
654 Self {
655 builder: self.builder.property("visible", visible),
656 }
657 }
658
659 pub fn width_request(self, width_request: i32) -> Self {
660 Self {
661 builder: self.builder.property("width-request", width_request),
662 }
663 }
664
665 pub fn accessible_role(self, accessible_role: gtk::AccessibleRole) -> Self {
666 Self {
667 builder: self.builder.property("accessible-role", accessible_role),
668 }
669 }
670
671 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
674 pub fn build(self) -> HeaderBar {
675 assert_initialized_main_thread!();
676 self.builder.build()
677 }
678}