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