gtk4/auto/header_bar.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5#[cfg(feature = "v4_10")]
6#[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
7use crate::Accessible;
8use crate::{
9 AccessibleRole, Align, Buildable, ConstraintTarget, LayoutManager, Overflow, Widget, ffi,
10};
11use glib::{
12 prelude::*,
13 signal::{SignalHandlerId, connect_raw},
14 translate::*,
15};
16use std::boxed::Box as Box_;
17
18#[cfg(feature = "v4_10")]
19#[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
20glib::wrapper! {
21 ///
22 /// ```text
23 ///
24 /// # CSS nodes
25 ///
26 /// ```
27 /// headerbar
28 /// ╰── windowhandle
29 /// ╰── box
30 /// ├── box.start
31 /// │ ├── windowcontrols.start
32 /// │ ╰── [other children]
33 /// ├── [Title Widget]
34 /// ╰── box.end
35 /// ├── [other children]
36 /// ╰── windowcontrols.end
37 /// ```text
38 ///
39 /// A [`HeaderBar`][crate::HeaderBar]'s CSS node is called `headerbar`. It contains a `windowhandle`
40 /// subnode, which contains a `box` subnode, which contains two `box` subnodes at
41 /// the start and end of the header bar, as well as a center node that represents
42 /// the title.
43 ///
44 /// Each of the boxes contains a `windowcontrols` subnode, see
45 /// [`WindowControls`][crate::WindowControls] for details, as well as other children.
46 ///
47 /// # Accessibility
48 ///
49 /// [`HeaderBar`][crate::HeaderBar] uses the [enum@Gtk.AccessibleRole.group] role.
50 ///
51 /// ## Properties
52 ///
53 ///
54 /// #### `decoration-layout`
55 /// The decoration layout for buttons.
56 ///
57 /// If this property is not set, the
58 /// [`gtk-decoration-layout`][struct@crate::Settings#gtk-decoration-layout] setting is used.
59 ///
60 /// Readable | Writable
61 ///
62 ///
63 /// #### `show-title-buttons`
64 /// Whether to show title buttons like close, minimize, maximize.
65 ///
66 /// Which buttons are actually shown and where is determined
67 /// by the [`decoration-layout`][struct@crate::HeaderBar#decoration-layout] property,
68 /// and by the state of the window (e.g. a close button will not
69 /// be shown if the window can't be closed).
70 ///
71 /// Readable | Writable
72 ///
73 ///
74 /// #### `title-widget`
75 /// The title widget to display.
76 ///
77 /// Readable | Writable
78 ///
79 ///
80 /// #### `use-native-controls`
81 /// Whether to show platform native close/minimize/maximize buttons.
82 ///
83 /// For macOS, the [`decoration-layout`][struct@crate::HeaderBar#decoration-layout] property
84 /// can be used to enable/disable controls.
85 ///
86 /// On Linux, this option has no effect.
87 ///
88 /// See also [Using GTK on Apple macOS](osx.html?native-window-controls).
89 ///
90 /// Readable | Writable
91 /// <details><summary><h4>Widget</h4></summary>
92 ///
93 ///
94 /// #### `can-focus`
95 /// Whether the widget or any of its descendents can accept
96 /// the input focus.
97 ///
98 /// This property is meant to be set by widget implementations,
99 /// typically in their instance init function.
100 ///
101 /// Readable | Writable
102 ///
103 ///
104 /// #### `can-target`
105 /// Whether the widget can receive pointer events.
106 ///
107 /// Readable | Writable
108 ///
109 ///
110 /// #### `css-classes`
111 /// A list of css classes applied to this widget.
112 ///
113 /// Readable | Writable
114 ///
115 ///
116 /// #### `css-name`
117 /// The name of this widget in the CSS tree.
118 ///
119 /// This property is meant to be set by widget implementations,
120 /// typically in their instance init function.
121 ///
122 /// Readable | Writable | Construct Only
123 ///
124 ///
125 /// #### `cursor`
126 /// The cursor used by @widget.
127 ///
128 /// Readable | Writable
129 ///
130 ///
131 /// #### `focus-on-click`
132 /// Whether the widget should grab focus when it is clicked with the mouse.
133 ///
134 /// This property is only relevant for widgets that can take focus.
135 ///
136 /// Readable | Writable
137 ///
138 ///
139 /// #### `focusable`
140 /// Whether this widget itself will accept the input focus.
141 ///
142 /// Readable | Writable
143 ///
144 ///
145 /// #### `halign`
146 /// How to distribute horizontal space if widget gets extra space.
147 ///
148 /// Readable | Writable
149 ///
150 ///
151 /// #### `has-default`
152 /// Whether the widget is the default widget.
153 ///
154 /// Readable
155 ///
156 ///
157 /// #### `has-focus`
158 /// Whether the widget has the input focus.
159 ///
160 /// Readable
161 ///
162 ///
163 /// #### `has-tooltip`
164 /// Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
165 /// signal on @widget.
166 ///
167 /// A true value indicates that @widget can have a tooltip, in this case
168 /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
169 /// determine whether it will provide a tooltip or not.
170 ///
171 /// Readable | Writable
172 ///
173 ///
174 /// #### `height-request`
175 /// Overrides for height request of the widget.
176 ///
177 /// If this is -1, the natural request will be used.
178 ///
179 /// Readable | Writable
180 ///
181 ///
182 /// #### `hexpand`
183 /// Whether to expand horizontally.
184 ///
185 /// Readable | Writable
186 ///
187 ///
188 /// #### `hexpand-set`
189 /// Whether to use the `hexpand` property.
190 ///
191 /// Readable | Writable
192 ///
193 ///
194 /// #### `layout-manager`
195 /// The [`LayoutManager`][crate::LayoutManager] instance to use to compute
196 /// the preferred size of the widget, and allocate its children.
197 ///
198 /// This property is meant to be set by widget implementations,
199 /// typically in their instance init function.
200 ///
201 /// Readable | Writable
202 ///
203 ///
204 /// #### `limit-events`
205 /// Makes this widget act like a modal dialog, with respect to
206 /// event delivery.
207 ///
208 /// Global event controllers will not handle events with targets
209 /// inside the widget, unless they are set up to ignore propagation
210 /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
211 ///
212 /// Readable | Writable
213 ///
214 ///
215 /// #### `margin-bottom`
216 /// Margin on bottom side of widget.
217 ///
218 /// This property adds margin outside of the widget's normal size
219 /// request, the margin will be added in addition to the size from
220 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
221 ///
222 /// Readable | Writable
223 ///
224 ///
225 /// #### `margin-end`
226 /// Margin on end of widget, horizontally.
227 ///
228 /// This property supports left-to-right and right-to-left text
229 /// directions.
230 ///
231 /// This property adds margin outside of the widget's normal size
232 /// request, the margin will be added in addition to the size from
233 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
234 ///
235 /// Readable | Writable
236 ///
237 ///
238 /// #### `margin-start`
239 /// Margin on start of widget, horizontally.
240 ///
241 /// This property supports left-to-right and right-to-left text
242 /// directions.
243 ///
244 /// This property adds margin outside of the widget's normal size
245 /// request, the margin will be added in addition to the size from
246 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
247 ///
248 /// Readable | Writable
249 ///
250 ///
251 /// #### `margin-top`
252 /// Margin on top side of widget.
253 ///
254 /// This property adds margin outside of the widget's normal size
255 /// request, the margin will be added in addition to the size from
256 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
257 ///
258 /// Readable | Writable
259 ///
260 ///
261 /// #### `name`
262 /// The name of the widget.
263 ///
264 /// Readable | Writable
265 ///
266 ///
267 /// #### `opacity`
268 /// The requested opacity of the widget.
269 ///
270 /// Readable | Writable
271 ///
272 ///
273 /// #### `overflow`
274 /// How content outside the widget's content area is treated.
275 ///
276 /// This property is meant to be set by widget implementations,
277 /// typically in their instance init function.
278 ///
279 /// Readable | Writable
280 ///
281 ///
282 /// #### `parent`
283 /// The parent widget of this widget.
284 ///
285 /// Readable
286 ///
287 ///
288 /// #### `receives-default`
289 /// Whether the widget will receive the default action when it is focused.
290 ///
291 /// Readable | Writable
292 ///
293 ///
294 /// #### `root`
295 /// The [`Root`][crate::Root] widget of the widget tree containing this widget.
296 ///
297 /// This will be `NULL` if the widget is not contained in a root widget.
298 ///
299 /// Readable
300 ///
301 ///
302 /// #### `scale-factor`
303 /// The scale factor of the widget.
304 ///
305 /// Readable
306 ///
307 ///
308 /// #### `sensitive`
309 /// Whether the widget responds to input.
310 ///
311 /// Readable | Writable
312 ///
313 ///
314 /// #### `tooltip-markup`
315 /// Sets the text of tooltip to be the given string, which is marked up
316 /// with Pango markup.
317 ///
318 /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
319 ///
320 /// This is a convenience property which will take care of getting the
321 /// tooltip shown if the given string is not `NULL`:
322 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
323 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
324 /// the default signal handler.
325 ///
326 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
327 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
328 ///
329 /// Readable | Writable
330 ///
331 ///
332 /// #### `tooltip-text`
333 /// Sets the text of tooltip to be the given string.
334 ///
335 /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
336 ///
337 /// This is a convenience property which will take care of getting the
338 /// tooltip shown if the given string is not `NULL`:
339 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
340 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
341 /// the default signal handler.
342 ///
343 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
344 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
345 ///
346 /// Readable | Writable
347 ///
348 ///
349 /// #### `valign`
350 /// How to distribute vertical space if widget gets extra space.
351 ///
352 /// Readable | Writable
353 ///
354 ///
355 /// #### `vexpand`
356 /// Whether to expand vertically.
357 ///
358 /// Readable | Writable
359 ///
360 ///
361 /// #### `vexpand-set`
362 /// Whether to use the `vexpand` property.
363 ///
364 /// Readable | Writable
365 ///
366 ///
367 /// #### `visible`
368 /// Whether the widget is visible.
369 ///
370 /// Readable | Writable
371 ///
372 ///
373 /// #### `width-request`
374 /// Overrides for width request of the widget.
375 ///
376 /// If this is -1, the natural request will be used.
377 ///
378 /// Readable | Writable
379 /// </details>
380 /// <details><summary><h4>Accessible</h4></summary>
381 ///
382 ///
383 /// #### `accessible-role`
384 /// The accessible role of the given [`Accessible`][crate::Accessible] implementation.
385 ///
386 /// The accessible role cannot be changed once set.
387 ///
388 /// Readable | Writable
389 /// </details>
390 ///
391 /// # Implements
392 ///
393 /// [`WidgetExt`][trait@crate::prelude::WidgetExt], [`trait@glib::ObjectExt`], [`AccessibleExt`][trait@crate::prelude::AccessibleExt], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`ConstraintTargetExt`][trait@crate::prelude::ConstraintTargetExt], [`WidgetExtManual`][trait@crate::prelude::WidgetExtManual], [`AccessibleExtManual`][trait@crate::prelude::AccessibleExtManual]
394 #[doc(alias = "GtkHeaderBar")]
395 pub struct HeaderBar(Object<ffi::GtkHeaderBar>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget;
396
397 match fn {
398 type_ => || ffi::gtk_header_bar_get_type(),
399 }
400}
401
402#[cfg(not(feature = "v4_10"))]
403glib::wrapper! {
404 #[doc(alias = "GtkHeaderBar")]
405 pub struct HeaderBar(Object<ffi::GtkHeaderBar>) @extends Widget, @implements Buildable, ConstraintTarget;
406
407 match fn {
408 type_ => || ffi::gtk_header_bar_get_type(),
409 }
410}
411
412impl HeaderBar {
413 /// Creates a new [`HeaderBar`][crate::HeaderBar] widget.
414 ///
415 /// # Returns
416 ///
417 /// a new [`HeaderBar`][crate::HeaderBar]
418 #[doc(alias = "gtk_header_bar_new")]
419 pub fn new() -> HeaderBar {
420 assert_initialized_main_thread!();
421 unsafe { Widget::from_glib_none(ffi::gtk_header_bar_new()).unsafe_cast() }
422 }
423
424 // rustdoc-stripper-ignore-next
425 /// Creates a new builder-pattern struct instance to construct [`HeaderBar`] objects.
426 ///
427 /// This method returns an instance of [`HeaderBarBuilder`](crate::builders::HeaderBarBuilder) which can be used to create [`HeaderBar`] objects.
428 pub fn builder() -> HeaderBarBuilder {
429 HeaderBarBuilder::new()
430 }
431
432 /// Gets the decoration layout of the header bar.
433 ///
434 /// # Returns
435 ///
436 /// the decoration layout
437 #[doc(alias = "gtk_header_bar_get_decoration_layout")]
438 #[doc(alias = "get_decoration_layout")]
439 #[doc(alias = "decoration-layout")]
440 pub fn decoration_layout(&self) -> Option<glib::GString> {
441 unsafe {
442 from_glib_none(ffi::gtk_header_bar_get_decoration_layout(
443 self.to_glib_none().0,
444 ))
445 }
446 }
447
448 /// Returns whether this header bar shows the standard window
449 /// title buttons.
450 ///
451 /// # Returns
452 ///
453 /// true if title buttons are shown
454 #[doc(alias = "gtk_header_bar_get_show_title_buttons")]
455 #[doc(alias = "get_show_title_buttons")]
456 #[doc(alias = "show-title-buttons")]
457 pub fn shows_title_buttons(&self) -> bool {
458 unsafe {
459 from_glib(ffi::gtk_header_bar_get_show_title_buttons(
460 self.to_glib_none().0,
461 ))
462 }
463 }
464
465 /// Retrieves the title widget of the header bar.
466 ///
467 /// See [`set_title_widget()`][Self::set_title_widget()].
468 ///
469 /// # Returns
470 ///
471 /// the title widget
472 #[doc(alias = "gtk_header_bar_get_title_widget")]
473 #[doc(alias = "get_title_widget")]
474 #[doc(alias = "title-widget")]
475 pub fn title_widget(&self) -> Option<Widget> {
476 unsafe { from_glib_none(ffi::gtk_header_bar_get_title_widget(self.to_glib_none().0)) }
477 }
478
479 /// Returns whether this header bar shows platform
480 /// native window controls.
481 ///
482 /// # Returns
483 ///
484 /// true if native window controls are shown
485 #[cfg(feature = "v4_18")]
486 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
487 #[doc(alias = "gtk_header_bar_get_use_native_controls")]
488 #[doc(alias = "get_use_native_controls")]
489 #[doc(alias = "use-native-controls")]
490 pub fn uses_native_controls(&self) -> bool {
491 unsafe {
492 from_glib(ffi::gtk_header_bar_get_use_native_controls(
493 self.to_glib_none().0,
494 ))
495 }
496 }
497
498 /// Adds a child to the header bar, packed with reference to the end.
499 /// ## `child`
500 /// the widget to be added to @self
501 #[doc(alias = "gtk_header_bar_pack_end")]
502 pub fn pack_end(&self, child: &impl IsA<Widget>) {
503 unsafe {
504 ffi::gtk_header_bar_pack_end(self.to_glib_none().0, child.as_ref().to_glib_none().0);
505 }
506 }
507
508 /// Adds a child to the header bar, packed with reference to the start.
509 /// ## `child`
510 /// the widget to be added to @self
511 #[doc(alias = "gtk_header_bar_pack_start")]
512 pub fn pack_start(&self, child: &impl IsA<Widget>) {
513 unsafe {
514 ffi::gtk_header_bar_pack_start(self.to_glib_none().0, child.as_ref().to_glib_none().0);
515 }
516 }
517
518 /// Removes a child from the header bar.
519 ///
520 /// The child must have been added with
521 /// [`pack_start()`][Self::pack_start()],
522 /// [`pack_end()`][Self::pack_end()] or
523 /// [`set_title_widget()`][Self::set_title_widget()].
524 /// ## `child`
525 /// the child to remove
526 #[doc(alias = "gtk_header_bar_remove")]
527 pub fn remove(&self, child: &impl IsA<Widget>) {
528 unsafe {
529 ffi::gtk_header_bar_remove(self.to_glib_none().0, child.as_ref().to_glib_none().0);
530 }
531 }
532
533 /// Sets the decoration layout for this header bar.
534 ///
535 /// This property overrides the
536 /// [`gtk-decoration-layout`][struct@crate::Settings#gtk-decoration-layout] setting.
537 ///
538 /// There can be valid reasons for overriding the setting, such
539 /// as a header bar design that does not allow for buttons to take
540 /// room on the right, or only offers room for a single close button.
541 /// Split header bars are another example for overriding the setting.
542 ///
543 /// The format of the string is button names, separated by commas.
544 /// A colon separates the buttons that should appear on the left
545 /// from those on the right. Recognized button names are minimize,
546 /// maximize, close and icon (the window icon).
547 ///
548 /// For example, “icon:minimize,maximize,close” specifies an icon
549 /// on the left, and minimize, maximize and close buttons on the right.
550 /// ## `layout`
551 /// a decoration layout
552 #[doc(alias = "gtk_header_bar_set_decoration_layout")]
553 #[doc(alias = "decoration-layout")]
554 pub fn set_decoration_layout(&self, layout: Option<&str>) {
555 unsafe {
556 ffi::gtk_header_bar_set_decoration_layout(
557 self.to_glib_none().0,
558 layout.to_glib_none().0,
559 );
560 }
561 }
562
563 /// Sets whether this header bar shows the standard window
564 /// title buttons.
565 /// ## `setting`
566 /// true to show standard title buttons
567 #[doc(alias = "gtk_header_bar_set_show_title_buttons")]
568 #[doc(alias = "show-title-buttons")]
569 pub fn set_show_title_buttons(&self, setting: bool) {
570 unsafe {
571 ffi::gtk_header_bar_set_show_title_buttons(self.to_glib_none().0, setting.into_glib());
572 }
573 }
574
575 /// Sets the title for the header bar.
576 ///
577 /// When set to `NULL`, the headerbar will display the title of
578 /// the window it is contained in.
579 ///
580 /// The title should help a user identify the current view.
581 /// To achieve the same style as the builtin title, use the
582 /// “title” style class.
583 ///
584 /// You should set the title widget to `NULL`, for the window
585 /// title label to be visible again.
586 /// ## `title_widget`
587 /// a widget to use for a title
588 #[doc(alias = "gtk_header_bar_set_title_widget")]
589 #[doc(alias = "title-widget")]
590 pub fn set_title_widget(&self, title_widget: Option<&impl IsA<Widget>>) {
591 unsafe {
592 ffi::gtk_header_bar_set_title_widget(
593 self.to_glib_none().0,
594 title_widget.map(|p| p.as_ref()).to_glib_none().0,
595 );
596 }
597 }
598
599 /// Sets whether this header bar shows native window controls.
600 ///
601 /// This option shows the "stoplight" buttons on macOS.
602 /// For Linux, this option has no effect.
603 ///
604 /// See also [Using GTK on Apple macOS](osx.html?native-window-controls).
605 /// ## `setting`
606 /// true to show native window controls
607 #[cfg(feature = "v4_18")]
608 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
609 #[doc(alias = "gtk_header_bar_set_use_native_controls")]
610 #[doc(alias = "use-native-controls")]
611 pub fn set_use_native_controls(&self, setting: bool) {
612 unsafe {
613 ffi::gtk_header_bar_set_use_native_controls(self.to_glib_none().0, setting.into_glib());
614 }
615 }
616
617 #[doc(alias = "decoration-layout")]
618 pub fn connect_decoration_layout_notify<F: Fn(&Self) + 'static>(
619 &self,
620 f: F,
621 ) -> SignalHandlerId {
622 unsafe extern "C" fn notify_decoration_layout_trampoline<F: Fn(&HeaderBar) + 'static>(
623 this: *mut ffi::GtkHeaderBar,
624 _param_spec: glib::ffi::gpointer,
625 f: glib::ffi::gpointer,
626 ) {
627 unsafe {
628 let f: &F = &*(f as *const F);
629 f(&from_glib_borrow(this))
630 }
631 }
632 unsafe {
633 let f: Box_<F> = Box_::new(f);
634 connect_raw(
635 self.as_ptr() as *mut _,
636 c"notify::decoration-layout".as_ptr(),
637 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
638 notify_decoration_layout_trampoline::<F> as *const (),
639 )),
640 Box_::into_raw(f),
641 )
642 }
643 }
644
645 #[doc(alias = "show-title-buttons")]
646 pub fn connect_show_title_buttons_notify<F: Fn(&Self) + 'static>(
647 &self,
648 f: F,
649 ) -> SignalHandlerId {
650 unsafe extern "C" fn notify_show_title_buttons_trampoline<F: Fn(&HeaderBar) + 'static>(
651 this: *mut ffi::GtkHeaderBar,
652 _param_spec: glib::ffi::gpointer,
653 f: glib::ffi::gpointer,
654 ) {
655 unsafe {
656 let f: &F = &*(f as *const F);
657 f(&from_glib_borrow(this))
658 }
659 }
660 unsafe {
661 let f: Box_<F> = Box_::new(f);
662 connect_raw(
663 self.as_ptr() as *mut _,
664 c"notify::show-title-buttons".as_ptr(),
665 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
666 notify_show_title_buttons_trampoline::<F> as *const (),
667 )),
668 Box_::into_raw(f),
669 )
670 }
671 }
672
673 #[doc(alias = "title-widget")]
674 pub fn connect_title_widget_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
675 unsafe extern "C" fn notify_title_widget_trampoline<F: Fn(&HeaderBar) + 'static>(
676 this: *mut ffi::GtkHeaderBar,
677 _param_spec: glib::ffi::gpointer,
678 f: glib::ffi::gpointer,
679 ) {
680 unsafe {
681 let f: &F = &*(f as *const F);
682 f(&from_glib_borrow(this))
683 }
684 }
685 unsafe {
686 let f: Box_<F> = Box_::new(f);
687 connect_raw(
688 self.as_ptr() as *mut _,
689 c"notify::title-widget".as_ptr(),
690 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
691 notify_title_widget_trampoline::<F> as *const (),
692 )),
693 Box_::into_raw(f),
694 )
695 }
696 }
697
698 #[cfg(feature = "v4_18")]
699 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
700 #[doc(alias = "use-native-controls")]
701 pub fn connect_use_native_controls_notify<F: Fn(&Self) + 'static>(
702 &self,
703 f: F,
704 ) -> SignalHandlerId {
705 unsafe extern "C" fn notify_use_native_controls_trampoline<F: Fn(&HeaderBar) + 'static>(
706 this: *mut ffi::GtkHeaderBar,
707 _param_spec: glib::ffi::gpointer,
708 f: glib::ffi::gpointer,
709 ) {
710 unsafe {
711 let f: &F = &*(f as *const F);
712 f(&from_glib_borrow(this))
713 }
714 }
715 unsafe {
716 let f: Box_<F> = Box_::new(f);
717 connect_raw(
718 self.as_ptr() as *mut _,
719 c"notify::use-native-controls".as_ptr(),
720 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
721 notify_use_native_controls_trampoline::<F> as *const (),
722 )),
723 Box_::into_raw(f),
724 )
725 }
726 }
727}
728
729impl Default for HeaderBar {
730 fn default() -> Self {
731 Self::new()
732 }
733}
734
735// rustdoc-stripper-ignore-next
736/// A [builder-pattern] type to construct [`HeaderBar`] objects.
737///
738/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
739#[must_use = "The builder must be built to be used"]
740pub struct HeaderBarBuilder {
741 builder: glib::object::ObjectBuilder<'static, HeaderBar>,
742}
743
744impl HeaderBarBuilder {
745 fn new() -> Self {
746 Self {
747 builder: glib::object::Object::builder(),
748 }
749 }
750
751 /// The decoration layout for buttons.
752 ///
753 /// If this property is not set, the
754 /// [`gtk-decoration-layout`][struct@crate::Settings#gtk-decoration-layout] setting is used.
755 pub fn decoration_layout(self, decoration_layout: impl Into<glib::GString>) -> Self {
756 Self {
757 builder: self
758 .builder
759 .property("decoration-layout", decoration_layout.into()),
760 }
761 }
762
763 /// Whether to show title buttons like close, minimize, maximize.
764 ///
765 /// Which buttons are actually shown and where is determined
766 /// by the [`decoration-layout`][struct@crate::HeaderBar#decoration-layout] property,
767 /// and by the state of the window (e.g. a close button will not
768 /// be shown if the window can't be closed).
769 pub fn show_title_buttons(self, show_title_buttons: bool) -> Self {
770 Self {
771 builder: self
772 .builder
773 .property("show-title-buttons", show_title_buttons),
774 }
775 }
776
777 /// The title widget to display.
778 pub fn title_widget(self, title_widget: &impl IsA<Widget>) -> Self {
779 Self {
780 builder: self
781 .builder
782 .property("title-widget", title_widget.clone().upcast()),
783 }
784 }
785
786 /// Whether to show platform native close/minimize/maximize buttons.
787 ///
788 /// For macOS, the [`decoration-layout`][struct@crate::HeaderBar#decoration-layout] property
789 /// can be used to enable/disable controls.
790 ///
791 /// On Linux, this option has no effect.
792 ///
793 /// See also [Using GTK on Apple macOS](osx.html?native-window-controls).
794 #[cfg(feature = "v4_18")]
795 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
796 pub fn use_native_controls(self, use_native_controls: bool) -> Self {
797 Self {
798 builder: self
799 .builder
800 .property("use-native-controls", use_native_controls),
801 }
802 }
803
804 /// Whether the widget or any of its descendents can accept
805 /// the input focus.
806 ///
807 /// This property is meant to be set by widget implementations,
808 /// typically in their instance init function.
809 pub fn can_focus(self, can_focus: bool) -> Self {
810 Self {
811 builder: self.builder.property("can-focus", can_focus),
812 }
813 }
814
815 /// Whether the widget can receive pointer events.
816 pub fn can_target(self, can_target: bool) -> Self {
817 Self {
818 builder: self.builder.property("can-target", can_target),
819 }
820 }
821
822 /// A list of css classes applied to this widget.
823 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
824 Self {
825 builder: self.builder.property("css-classes", css_classes.into()),
826 }
827 }
828
829 /// The name of this widget in the CSS tree.
830 ///
831 /// This property is meant to be set by widget implementations,
832 /// typically in their instance init function.
833 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
834 Self {
835 builder: self.builder.property("css-name", css_name.into()),
836 }
837 }
838
839 /// The cursor used by @widget.
840 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
841 Self {
842 builder: self.builder.property("cursor", cursor.clone()),
843 }
844 }
845
846 /// Whether the widget should grab focus when it is clicked with the mouse.
847 ///
848 /// This property is only relevant for widgets that can take focus.
849 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
850 Self {
851 builder: self.builder.property("focus-on-click", focus_on_click),
852 }
853 }
854
855 /// Whether this widget itself will accept the input focus.
856 pub fn focusable(self, focusable: bool) -> Self {
857 Self {
858 builder: self.builder.property("focusable", focusable),
859 }
860 }
861
862 /// How to distribute horizontal space if widget gets extra space.
863 pub fn halign(self, halign: Align) -> Self {
864 Self {
865 builder: self.builder.property("halign", halign),
866 }
867 }
868
869 /// Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
870 /// signal on @widget.
871 ///
872 /// A true value indicates that @widget can have a tooltip, in this case
873 /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
874 /// determine whether it will provide a tooltip or not.
875 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
876 Self {
877 builder: self.builder.property("has-tooltip", has_tooltip),
878 }
879 }
880
881 /// Overrides for height request of the widget.
882 ///
883 /// If this is -1, the natural request will be used.
884 pub fn height_request(self, height_request: i32) -> Self {
885 Self {
886 builder: self.builder.property("height-request", height_request),
887 }
888 }
889
890 /// Whether to expand horizontally.
891 pub fn hexpand(self, hexpand: bool) -> Self {
892 Self {
893 builder: self.builder.property("hexpand", hexpand),
894 }
895 }
896
897 /// Whether to use the `hexpand` property.
898 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
899 Self {
900 builder: self.builder.property("hexpand-set", hexpand_set),
901 }
902 }
903
904 /// The [`LayoutManager`][crate::LayoutManager] instance to use to compute
905 /// the preferred size of the widget, and allocate its children.
906 ///
907 /// This property is meant to be set by widget implementations,
908 /// typically in their instance init function.
909 pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
910 Self {
911 builder: self
912 .builder
913 .property("layout-manager", layout_manager.clone().upcast()),
914 }
915 }
916
917 /// Makes this widget act like a modal dialog, with respect to
918 /// event delivery.
919 ///
920 /// Global event controllers will not handle events with targets
921 /// inside the widget, unless they are set up to ignore propagation
922 /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
923 #[cfg(feature = "v4_18")]
924 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
925 pub fn limit_events(self, limit_events: bool) -> Self {
926 Self {
927 builder: self.builder.property("limit-events", limit_events),
928 }
929 }
930
931 /// Margin on bottom side of widget.
932 ///
933 /// This property adds margin outside of the widget's normal size
934 /// request, the margin will be added in addition to the size from
935 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
936 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
937 Self {
938 builder: self.builder.property("margin-bottom", margin_bottom),
939 }
940 }
941
942 /// Margin on end of widget, horizontally.
943 ///
944 /// This property supports left-to-right and right-to-left text
945 /// directions.
946 ///
947 /// This property adds margin outside of the widget's normal size
948 /// request, the margin will be added in addition to the size from
949 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
950 pub fn margin_end(self, margin_end: i32) -> Self {
951 Self {
952 builder: self.builder.property("margin-end", margin_end),
953 }
954 }
955
956 /// Margin on start of widget, horizontally.
957 ///
958 /// This property supports left-to-right and right-to-left text
959 /// directions.
960 ///
961 /// This property adds margin outside of the widget's normal size
962 /// request, the margin will be added in addition to the size from
963 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
964 pub fn margin_start(self, margin_start: i32) -> Self {
965 Self {
966 builder: self.builder.property("margin-start", margin_start),
967 }
968 }
969
970 /// Margin on top side of widget.
971 ///
972 /// This property adds margin outside of the widget's normal size
973 /// request, the margin will be added in addition to the size from
974 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
975 pub fn margin_top(self, margin_top: i32) -> Self {
976 Self {
977 builder: self.builder.property("margin-top", margin_top),
978 }
979 }
980
981 /// The name of the widget.
982 pub fn name(self, name: impl Into<glib::GString>) -> Self {
983 Self {
984 builder: self.builder.property("name", name.into()),
985 }
986 }
987
988 /// The requested opacity of the widget.
989 pub fn opacity(self, opacity: f64) -> Self {
990 Self {
991 builder: self.builder.property("opacity", opacity),
992 }
993 }
994
995 /// How content outside the widget's content area is treated.
996 ///
997 /// This property is meant to be set by widget implementations,
998 /// typically in their instance init function.
999 pub fn overflow(self, overflow: Overflow) -> Self {
1000 Self {
1001 builder: self.builder.property("overflow", overflow),
1002 }
1003 }
1004
1005 /// Whether the widget will receive the default action when it is focused.
1006 pub fn receives_default(self, receives_default: bool) -> Self {
1007 Self {
1008 builder: self.builder.property("receives-default", receives_default),
1009 }
1010 }
1011
1012 /// Whether the widget responds to input.
1013 pub fn sensitive(self, sensitive: bool) -> Self {
1014 Self {
1015 builder: self.builder.property("sensitive", sensitive),
1016 }
1017 }
1018
1019 /// Sets the text of tooltip to be the given string, which is marked up
1020 /// with Pango markup.
1021 ///
1022 /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
1023 ///
1024 /// This is a convenience property which will take care of getting the
1025 /// tooltip shown if the given string is not `NULL`:
1026 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
1027 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
1028 /// the default signal handler.
1029 ///
1030 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
1031 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
1032 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
1033 Self {
1034 builder: self
1035 .builder
1036 .property("tooltip-markup", tooltip_markup.into()),
1037 }
1038 }
1039
1040 /// Sets the text of tooltip to be the given string.
1041 ///
1042 /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
1043 ///
1044 /// This is a convenience property which will take care of getting the
1045 /// tooltip shown if the given string is not `NULL`:
1046 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
1047 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
1048 /// the default signal handler.
1049 ///
1050 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
1051 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
1052 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
1053 Self {
1054 builder: self.builder.property("tooltip-text", tooltip_text.into()),
1055 }
1056 }
1057
1058 /// How to distribute vertical space if widget gets extra space.
1059 pub fn valign(self, valign: Align) -> Self {
1060 Self {
1061 builder: self.builder.property("valign", valign),
1062 }
1063 }
1064
1065 /// Whether to expand vertically.
1066 pub fn vexpand(self, vexpand: bool) -> Self {
1067 Self {
1068 builder: self.builder.property("vexpand", vexpand),
1069 }
1070 }
1071
1072 /// Whether to use the `vexpand` property.
1073 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
1074 Self {
1075 builder: self.builder.property("vexpand-set", vexpand_set),
1076 }
1077 }
1078
1079 /// Whether the widget is visible.
1080 pub fn visible(self, visible: bool) -> Self {
1081 Self {
1082 builder: self.builder.property("visible", visible),
1083 }
1084 }
1085
1086 /// Overrides for width request of the widget.
1087 ///
1088 /// If this is -1, the natural request will be used.
1089 pub fn width_request(self, width_request: i32) -> Self {
1090 Self {
1091 builder: self.builder.property("width-request", width_request),
1092 }
1093 }
1094
1095 /// The accessible role of the given [`Accessible`][crate::Accessible] implementation.
1096 ///
1097 /// The accessible role cannot be changed once set.
1098 pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
1099 Self {
1100 builder: self.builder.property("accessible-role", accessible_role),
1101 }
1102 }
1103
1104 // rustdoc-stripper-ignore-next
1105 /// Build the [`HeaderBar`].
1106 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
1107 pub fn build(self) -> HeaderBar {
1108 assert_initialized_main_thread!();
1109 self.builder.build()
1110 }
1111}