Skip to main content

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