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
5use crate::{
6    Accessible, AccessibleRole, Align, Buildable, ConstraintTarget, LayoutManager, Overflow,
7    Widget, ffi,
8};
9use glib::{
10    prelude::*,
11    signal::{SignalHandlerId, connect_raw},
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            unsafe {
659                let f: &F = &*(f as *const F);
660                f(&from_glib_borrow(this))
661            }
662        }
663        unsafe {
664            let f: Box_<F> = Box_::new(f);
665            connect_raw(
666                self.as_ptr() as *mut _,
667                c"notify::decoration-layout".as_ptr() as *const _,
668                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
669                    notify_decoration_layout_trampoline::<F> as *const (),
670                )),
671                Box_::into_raw(f),
672            )
673        }
674    }
675
676    #[doc(alias = "show-title-buttons")]
677    pub fn connect_show_title_buttons_notify<F: Fn(&Self) + 'static>(
678        &self,
679        f: F,
680    ) -> SignalHandlerId {
681        unsafe extern "C" fn notify_show_title_buttons_trampoline<F: Fn(&HeaderBar) + 'static>(
682            this: *mut ffi::GtkHeaderBar,
683            _param_spec: glib::ffi::gpointer,
684            f: glib::ffi::gpointer,
685        ) {
686            unsafe {
687                let f: &F = &*(f as *const F);
688                f(&from_glib_borrow(this))
689            }
690        }
691        unsafe {
692            let f: Box_<F> = Box_::new(f);
693            connect_raw(
694                self.as_ptr() as *mut _,
695                c"notify::show-title-buttons".as_ptr() as *const _,
696                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
697                    notify_show_title_buttons_trampoline::<F> as *const (),
698                )),
699                Box_::into_raw(f),
700            )
701        }
702    }
703
704    #[doc(alias = "title-widget")]
705    pub fn connect_title_widget_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
706        unsafe extern "C" fn notify_title_widget_trampoline<F: Fn(&HeaderBar) + 'static>(
707            this: *mut ffi::GtkHeaderBar,
708            _param_spec: glib::ffi::gpointer,
709            f: glib::ffi::gpointer,
710        ) {
711            unsafe {
712                let f: &F = &*(f as *const F);
713                f(&from_glib_borrow(this))
714            }
715        }
716        unsafe {
717            let f: Box_<F> = Box_::new(f);
718            connect_raw(
719                self.as_ptr() as *mut _,
720                c"notify::title-widget".as_ptr() as *const _,
721                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
722                    notify_title_widget_trampoline::<F> as *const (),
723                )),
724                Box_::into_raw(f),
725            )
726        }
727    }
728
729    #[cfg(feature = "v4_18")]
730    #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
731    #[doc(alias = "use-native-controls")]
732    pub fn connect_use_native_controls_notify<F: Fn(&Self) + 'static>(
733        &self,
734        f: F,
735    ) -> SignalHandlerId {
736        unsafe extern "C" fn notify_use_native_controls_trampoline<F: Fn(&HeaderBar) + 'static>(
737            this: *mut ffi::GtkHeaderBar,
738            _param_spec: glib::ffi::gpointer,
739            f: glib::ffi::gpointer,
740        ) {
741            unsafe {
742                let f: &F = &*(f as *const F);
743                f(&from_glib_borrow(this))
744            }
745        }
746        unsafe {
747            let f: Box_<F> = Box_::new(f);
748            connect_raw(
749                self.as_ptr() as *mut _,
750                c"notify::use-native-controls".as_ptr() as *const _,
751                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
752                    notify_use_native_controls_trampoline::<F> as *const (),
753                )),
754                Box_::into_raw(f),
755            )
756        }
757    }
758}
759
760impl Default for HeaderBar {
761    fn default() -> Self {
762        Self::new()
763    }
764}
765
766// rustdoc-stripper-ignore-next
767/// A [builder-pattern] type to construct [`HeaderBar`] objects.
768///
769/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
770#[must_use = "The builder must be built to be used"]
771pub struct HeaderBarBuilder {
772    builder: glib::object::ObjectBuilder<'static, HeaderBar>,
773}
774
775impl HeaderBarBuilder {
776    fn new() -> Self {
777        Self {
778            builder: glib::object::Object::builder(),
779        }
780    }
781
782    /// The decoration layout for buttons.
783    ///
784    /// If this property is not set, the
785    /// [`gtk-decoration-layout`][struct@crate::Settings#gtk-decoration-layout] setting is used.
786    pub fn decoration_layout(self, decoration_layout: impl Into<glib::GString>) -> Self {
787        Self {
788            builder: self
789                .builder
790                .property("decoration-layout", decoration_layout.into()),
791        }
792    }
793
794    /// Whether to show title buttons like close, minimize, maximize.
795    ///
796    /// Which buttons are actually shown and where is determined
797    /// by the [`decoration-layout`][struct@crate::HeaderBar#decoration-layout] property,
798    /// and by the state of the window (e.g. a close button will not
799    /// be shown if the window can't be closed).
800    pub fn show_title_buttons(self, show_title_buttons: bool) -> Self {
801        Self {
802            builder: self
803                .builder
804                .property("show-title-buttons", show_title_buttons),
805        }
806    }
807
808    /// The title widget to display.
809    pub fn title_widget(self, title_widget: &impl IsA<Widget>) -> Self {
810        Self {
811            builder: self
812                .builder
813                .property("title-widget", title_widget.clone().upcast()),
814        }
815    }
816
817    /// Whether to show platform native close/minimize/maximize buttons.
818    ///
819    /// For macOS, the [`decoration-layout`][struct@crate::HeaderBar#decoration-layout] property
820    /// can be used to enable/disable controls.
821    ///
822    /// On Linux, this option has no effect.
823    ///
824    /// See also [Using GTK on Apple macOS](osx.html?native-window-controls).
825    #[cfg(feature = "v4_18")]
826    #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
827    pub fn use_native_controls(self, use_native_controls: bool) -> Self {
828        Self {
829            builder: self
830                .builder
831                .property("use-native-controls", use_native_controls),
832        }
833    }
834
835    /// Whether the widget or any of its descendents can accept
836    /// the input focus.
837    ///
838    /// This property is meant to be set by widget implementations,
839    /// typically in their instance init function.
840    pub fn can_focus(self, can_focus: bool) -> Self {
841        Self {
842            builder: self.builder.property("can-focus", can_focus),
843        }
844    }
845
846    /// Whether the widget can receive pointer events.
847    pub fn can_target(self, can_target: bool) -> Self {
848        Self {
849            builder: self.builder.property("can-target", can_target),
850        }
851    }
852
853    /// A list of css classes applied to this widget.
854    pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
855        Self {
856            builder: self.builder.property("css-classes", css_classes.into()),
857        }
858    }
859
860    /// The name of this widget in the CSS tree.
861    ///
862    /// This property is meant to be set by widget implementations,
863    /// typically in their instance init function.
864    pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
865        Self {
866            builder: self.builder.property("css-name", css_name.into()),
867        }
868    }
869
870    /// The cursor used by @widget.
871    pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
872        Self {
873            builder: self.builder.property("cursor", cursor.clone()),
874        }
875    }
876
877    /// Whether the widget should grab focus when it is clicked with the mouse.
878    ///
879    /// This property is only relevant for widgets that can take focus.
880    pub fn focus_on_click(self, focus_on_click: bool) -> Self {
881        Self {
882            builder: self.builder.property("focus-on-click", focus_on_click),
883        }
884    }
885
886    /// Whether this widget itself will accept the input focus.
887    pub fn focusable(self, focusable: bool) -> Self {
888        Self {
889            builder: self.builder.property("focusable", focusable),
890        }
891    }
892
893    /// How to distribute horizontal space if widget gets extra space.
894    pub fn halign(self, halign: Align) -> Self {
895        Self {
896            builder: self.builder.property("halign", halign),
897        }
898    }
899
900    /// Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
901    /// signal on @widget.
902    ///
903    /// A true value indicates that @widget can have a tooltip, in this case
904    /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
905    /// determine whether it will provide a tooltip or not.
906    pub fn has_tooltip(self, has_tooltip: bool) -> Self {
907        Self {
908            builder: self.builder.property("has-tooltip", has_tooltip),
909        }
910    }
911
912    /// Overrides for height request of the widget.
913    ///
914    /// If this is -1, the natural request will be used.
915    pub fn height_request(self, height_request: i32) -> Self {
916        Self {
917            builder: self.builder.property("height-request", height_request),
918        }
919    }
920
921    /// Whether to expand horizontally.
922    pub fn hexpand(self, hexpand: bool) -> Self {
923        Self {
924            builder: self.builder.property("hexpand", hexpand),
925        }
926    }
927
928    /// Whether to use the `hexpand` property.
929    pub fn hexpand_set(self, hexpand_set: bool) -> Self {
930        Self {
931            builder: self.builder.property("hexpand-set", hexpand_set),
932        }
933    }
934
935    /// The [`LayoutManager`][crate::LayoutManager] instance to use to compute
936    /// the preferred size of the widget, and allocate its children.
937    ///
938    /// This property is meant to be set by widget implementations,
939    /// typically in their instance init function.
940    pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
941        Self {
942            builder: self
943                .builder
944                .property("layout-manager", layout_manager.clone().upcast()),
945        }
946    }
947
948    /// Makes this widget act like a modal dialog, with respect to
949    /// event delivery.
950    ///
951    /// Global event controllers will not handle events with targets
952    /// inside the widget, unless they are set up to ignore propagation
953    /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
954    #[cfg(feature = "v4_18")]
955    #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
956    pub fn limit_events(self, limit_events: bool) -> Self {
957        Self {
958            builder: self.builder.property("limit-events", limit_events),
959        }
960    }
961
962    /// Margin on bottom side of widget.
963    ///
964    /// This property adds margin outside of the widget's normal size
965    /// request, the margin will be added in addition to the size from
966    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
967    pub fn margin_bottom(self, margin_bottom: i32) -> Self {
968        Self {
969            builder: self.builder.property("margin-bottom", margin_bottom),
970        }
971    }
972
973    /// Margin on end of widget, horizontally.
974    ///
975    /// This property supports left-to-right and right-to-left text
976    /// directions.
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_end(self, margin_end: i32) -> Self {
982        Self {
983            builder: self.builder.property("margin-end", margin_end),
984        }
985    }
986
987    /// Margin on start 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_start(self, margin_start: i32) -> Self {
996        Self {
997            builder: self.builder.property("margin-start", margin_start),
998        }
999    }
1000
1001    /// Margin on top side of widget.
1002    ///
1003    /// This property adds margin outside of the widget's normal size
1004    /// request, the margin will be added in addition to the size from
1005    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1006    pub fn margin_top(self, margin_top: i32) -> Self {
1007        Self {
1008            builder: self.builder.property("margin-top", margin_top),
1009        }
1010    }
1011
1012    /// The name of the widget.
1013    pub fn name(self, name: impl Into<glib::GString>) -> Self {
1014        Self {
1015            builder: self.builder.property("name", name.into()),
1016        }
1017    }
1018
1019    /// The requested opacity of the widget.
1020    pub fn opacity(self, opacity: f64) -> Self {
1021        Self {
1022            builder: self.builder.property("opacity", opacity),
1023        }
1024    }
1025
1026    /// How content outside the widget's content area is treated.
1027    ///
1028    /// This property is meant to be set by widget implementations,
1029    /// typically in their instance init function.
1030    pub fn overflow(self, overflow: Overflow) -> Self {
1031        Self {
1032            builder: self.builder.property("overflow", overflow),
1033        }
1034    }
1035
1036    /// Whether the widget will receive the default action when it is focused.
1037    pub fn receives_default(self, receives_default: bool) -> Self {
1038        Self {
1039            builder: self.builder.property("receives-default", receives_default),
1040        }
1041    }
1042
1043    /// Whether the widget responds to input.
1044    pub fn sensitive(self, sensitive: bool) -> Self {
1045        Self {
1046            builder: self.builder.property("sensitive", sensitive),
1047        }
1048    }
1049
1050    /// Sets the text of tooltip to be the given string, which is marked up
1051    /// with Pango markup.
1052    ///
1053    /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
1054    ///
1055    /// This is a convenience property which will take care of getting the
1056    /// tooltip shown if the given string is not `NULL`:
1057    /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
1058    /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
1059    /// the default signal handler.
1060    ///
1061    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
1062    /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
1063    pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
1064        Self {
1065            builder: self
1066                .builder
1067                .property("tooltip-markup", tooltip_markup.into()),
1068        }
1069    }
1070
1071    /// Sets the text of tooltip to be the given string.
1072    ///
1073    /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
1074    ///
1075    /// This is a convenience property which will take care of getting the
1076    /// tooltip shown if the given string is not `NULL`:
1077    /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
1078    /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
1079    /// the default signal handler.
1080    ///
1081    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
1082    /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
1083    pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
1084        Self {
1085            builder: self.builder.property("tooltip-text", tooltip_text.into()),
1086        }
1087    }
1088
1089    /// How to distribute vertical space if widget gets extra space.
1090    pub fn valign(self, valign: Align) -> Self {
1091        Self {
1092            builder: self.builder.property("valign", valign),
1093        }
1094    }
1095
1096    /// Whether to expand vertically.
1097    pub fn vexpand(self, vexpand: bool) -> Self {
1098        Self {
1099            builder: self.builder.property("vexpand", vexpand),
1100        }
1101    }
1102
1103    /// Whether to use the `vexpand` property.
1104    pub fn vexpand_set(self, vexpand_set: bool) -> Self {
1105        Self {
1106            builder: self.builder.property("vexpand-set", vexpand_set),
1107        }
1108    }
1109
1110    /// Whether the widget is visible.
1111    pub fn visible(self, visible: bool) -> Self {
1112        Self {
1113            builder: self.builder.property("visible", visible),
1114        }
1115    }
1116
1117    /// Overrides for width request of the widget.
1118    ///
1119    /// If this is -1, the natural request will be used.
1120    pub fn width_request(self, width_request: i32) -> Self {
1121        Self {
1122            builder: self.builder.property("width-request", width_request),
1123        }
1124    }
1125
1126    /// The accessible role of the given [`Accessible`][crate::Accessible] implementation.
1127    ///
1128    /// The accessible role cannot be changed once set.
1129    pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
1130        Self {
1131            builder: self.builder.property("accessible-role", accessible_role),
1132        }
1133    }
1134
1135    // rustdoc-stripper-ignore-next
1136    /// Build the [`HeaderBar`].
1137    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
1138    pub fn build(self) -> HeaderBar {
1139        assert_initialized_main_thread!();
1140        self.builder.build()
1141    }
1142}