Skip to main content

gtk/auto/
menu_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::{Align, Buildable, Container, MenuShell, PackDirection, ResizeMode, Widget, ffi};
6use glib::{
7    prelude::*,
8    signal::{SignalHandlerId, connect_raw},
9    translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14    /// The [`MenuBar`][crate::MenuBar] is a subclass of [`MenuShell`][crate::MenuShell] which contains one or
15    /// more `GtkMenuItems`. The result is a standard menu bar which can hold
16    /// many menu items.
17    ///
18    /// # CSS nodes
19    ///
20    /// GtkMenuBar has a single CSS node with name menubar.
21    ///
22    /// ## Properties
23    ///
24    ///
25    /// #### `child-pack-direction`
26    ///  The child pack direction of the menubar. It determines how
27    /// the widgets contained in child menuitems are arranged.
28    ///
29    /// Readable | Writable
30    ///
31    ///
32    /// #### `pack-direction`
33    ///  The pack direction of the menubar. It determines how
34    /// menuitems are arranged in the menubar.
35    ///
36    /// Readable | Writable
37    /// <details><summary><h4>MenuShell</h4></summary>
38    ///
39    ///
40    /// #### `take-focus`
41    ///  A boolean that determines whether the menu and its submenus grab the
42    /// keyboard focus. See [`MenuShellExt::set_take_focus()`][crate::prelude::MenuShellExt::set_take_focus()] and
43    /// [`MenuShellExt::takes_focus()`][crate::prelude::MenuShellExt::takes_focus()].
44    ///
45    /// Readable | Writable
46    /// </details>
47    /// <details><summary><h4>Container</h4></summary>
48    ///
49    ///
50    /// #### `border-width`
51    ///  Readable | Writable
52    ///
53    ///
54    /// #### `child`
55    ///  Writable
56    ///
57    ///
58    /// #### `resize-mode`
59    ///  Readable | Writable
60    /// </details>
61    /// <details><summary><h4>Widget</h4></summary>
62    ///
63    ///
64    /// #### `app-paintable`
65    ///  Readable | Writable
66    ///
67    ///
68    /// #### `can-default`
69    ///  Readable | Writable
70    ///
71    ///
72    /// #### `can-focus`
73    ///  Readable | Writable
74    ///
75    ///
76    /// #### `composite-child`
77    ///  Readable
78    ///
79    ///
80    /// #### `double-buffered`
81    ///  Whether the widget is double buffered.
82    ///
83    /// Readable | Writable
84    ///
85    ///
86    /// #### `events`
87    ///  Readable | Writable
88    ///
89    ///
90    /// #### `expand`
91    ///  Whether to expand in both directions. Setting this sets both [`hexpand`][struct@crate::Widget#hexpand] and [`vexpand`][struct@crate::Widget#vexpand]
92    ///
93    /// Readable | Writable
94    ///
95    ///
96    /// #### `focus-on-click`
97    ///  Whether the widget should grab focus when it is clicked with the mouse.
98    ///
99    /// This property is only relevant for widgets that can take focus.
100    ///
101    /// Before 3.20, several widgets (GtkButton, GtkFileChooserButton,
102    /// GtkComboBox) implemented this property individually.
103    ///
104    /// Readable | Writable
105    ///
106    ///
107    /// #### `halign`
108    ///  How to distribute horizontal space if widget gets extra space, see [`Align`][crate::Align]
109    ///
110    /// Readable | Writable
111    ///
112    ///
113    /// #### `has-default`
114    ///  Readable | Writable
115    ///
116    ///
117    /// #### `has-focus`
118    ///  Readable | Writable
119    ///
120    ///
121    /// #### `has-tooltip`
122    ///  Enables or disables the emission of [`query-tooltip`][struct@crate::Widget#query-tooltip] on `widget`.
123    /// A value of [`true`] indicates that `widget` can have a tooltip, in this case
124    /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to determine
125    /// whether it will provide a tooltip or not.
126    ///
127    /// Note that setting this property to [`true`] for the first time will change
128    /// the event masks of the GdkWindows of this widget to include leave-notify
129    /// and motion-notify events. This cannot and will not be undone when the
130    /// property is set to [`false`] again.
131    ///
132    /// Readable | Writable
133    ///
134    ///
135    /// #### `height-request`
136    ///  Readable | Writable
137    ///
138    ///
139    /// #### `hexpand`
140    ///  Whether to expand horizontally. See [`WidgetExt::set_hexpand()`][crate::prelude::WidgetExt::set_hexpand()].
141    ///
142    /// Readable | Writable
143    ///
144    ///
145    /// #### `hexpand-set`
146    ///  Whether to use the [`hexpand`][struct@crate::Widget#hexpand] property. See [`WidgetExt::is_hexpand_set()`][crate::prelude::WidgetExt::is_hexpand_set()].
147    ///
148    /// Readable | Writable
149    ///
150    ///
151    /// #### `is-focus`
152    ///  Readable | Writable
153    ///
154    ///
155    /// #### `margin`
156    ///  Sets all four sides' margin at once. If read, returns max
157    /// margin on any side.
158    ///
159    /// Readable | Writable
160    ///
161    ///
162    /// #### `margin-bottom`
163    ///  Margin on bottom side of widget.
164    ///
165    /// This property adds margin outside of the widget's normal size
166    /// request, the margin will be added in addition to the size from
167    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
168    ///
169    /// Readable | Writable
170    ///
171    ///
172    /// #### `margin-end`
173    ///  Margin on end of widget, horizontally. This property supports
174    /// left-to-right and right-to-left text directions.
175    ///
176    /// This property adds margin outside of the widget's normal size
177    /// request, the margin will be added in addition to the size from
178    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
179    ///
180    /// Readable | Writable
181    ///
182    ///
183    /// #### `margin-left`
184    ///  Margin on left side of widget.
185    ///
186    /// This property adds margin outside of the widget's normal size
187    /// request, the margin will be added in addition to the size from
188    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
189    ///
190    /// Readable | Writable
191    ///
192    ///
193    /// #### `margin-right`
194    ///  Margin on right side of widget.
195    ///
196    /// This property adds margin outside of the widget's normal size
197    /// request, the margin will be added in addition to the size from
198    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
199    ///
200    /// Readable | Writable
201    ///
202    ///
203    /// #### `margin-start`
204    ///  Margin on start of widget, horizontally. This property supports
205    /// left-to-right and right-to-left text directions.
206    ///
207    /// This property adds margin outside of the widget's normal size
208    /// request, the margin will be added in addition to the size from
209    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
210    ///
211    /// Readable | Writable
212    ///
213    ///
214    /// #### `margin-top`
215    ///  Margin on top side of widget.
216    ///
217    /// This property adds margin outside of the widget's normal size
218    /// request, the margin will be added in addition to the size from
219    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
220    ///
221    /// Readable | Writable
222    ///
223    ///
224    /// #### `name`
225    ///  Readable | Writable
226    ///
227    ///
228    /// #### `no-show-all`
229    ///  Readable | Writable
230    ///
231    ///
232    /// #### `opacity`
233    ///  The requested opacity of the widget. See [`WidgetExt::set_opacity()`][crate::prelude::WidgetExt::set_opacity()] for
234    /// more details about window opacity.
235    ///
236    /// Before 3.8 this was only available in GtkWindow
237    ///
238    /// Readable | Writable
239    ///
240    ///
241    /// #### `parent`
242    ///  Readable | Writable
243    ///
244    ///
245    /// #### `receives-default`
246    ///  Readable | Writable
247    ///
248    ///
249    /// #### `scale-factor`
250    ///  The scale factor of the widget. See [`WidgetExt::scale_factor()`][crate::prelude::WidgetExt::scale_factor()] for
251    /// more details about widget scaling.
252    ///
253    /// Readable
254    ///
255    ///
256    /// #### `sensitive`
257    ///  Readable | Writable
258    ///
259    ///
260    /// #### `style`
261    ///  The style of the widget, which contains information about how it will look (colors, etc).
262    ///
263    /// Readable | Writable
264    ///
265    ///
266    /// #### `tooltip-markup`
267    ///  Sets the text of tooltip to be the given string, which is marked up
268    /// with the [Pango text markup language][PangoMarkupFormat].
269    /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
270    ///
271    /// This is a convenience property which will take care of getting the
272    /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
273    /// will automatically be set to [`true`] and there will be taken care of
274    /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
275    ///
276    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
277    /// are set, the last one wins.
278    ///
279    /// Readable | Writable
280    ///
281    ///
282    /// #### `tooltip-text`
283    ///  Sets the text of tooltip to be the given string.
284    ///
285    /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
286    ///
287    /// This is a convenience property which will take care of getting the
288    /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
289    /// will automatically be set to [`true`] and there will be taken care of
290    /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
291    ///
292    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
293    /// are set, the last one wins.
294    ///
295    /// Readable | Writable
296    ///
297    ///
298    /// #### `valign`
299    ///  How to distribute vertical space if widget gets extra space, see [`Align`][crate::Align]
300    ///
301    /// Readable | Writable
302    ///
303    ///
304    /// #### `vexpand`
305    ///  Whether to expand vertically. See [`WidgetExt::set_vexpand()`][crate::prelude::WidgetExt::set_vexpand()].
306    ///
307    /// Readable | Writable
308    ///
309    ///
310    /// #### `vexpand-set`
311    ///  Whether to use the [`vexpand`][struct@crate::Widget#vexpand] property. See [`WidgetExt::is_vexpand_set()`][crate::prelude::WidgetExt::is_vexpand_set()].
312    ///
313    /// Readable | Writable
314    ///
315    ///
316    /// #### `visible`
317    ///  Readable | Writable
318    ///
319    ///
320    /// #### `width-request`
321    ///  Readable | Writable
322    ///
323    ///
324    /// #### `window`
325    ///  The widget's window if it is realized, [`None`] otherwise.
326    ///
327    /// Readable
328    /// </details>
329    ///
330    /// # Implements
331    ///
332    /// [`MenuBarExt`][trait@crate::prelude::MenuBarExt], [`MenuShellExt`][trait@crate::prelude::MenuShellExt], [`ContainerExt`][trait@crate::prelude::ContainerExt], [`WidgetExt`][trait@crate::prelude::WidgetExt], [`trait@glib::ObjectExt`], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`ContainerExtManual`][trait@crate::prelude::ContainerExtManual], [`WidgetExtManual`][trait@crate::prelude::WidgetExtManual], [`BuildableExtManual`][trait@crate::prelude::BuildableExtManual]
333    #[doc(alias = "GtkMenuBar")]
334    pub struct MenuBar(Object<ffi::GtkMenuBar, ffi::GtkMenuBarClass>) @extends MenuShell, Container, Widget, @implements Buildable;
335
336    match fn {
337        type_ => || ffi::gtk_menu_bar_get_type(),
338    }
339}
340
341impl MenuBar {
342    pub const NONE: Option<&'static MenuBar> = None;
343
344    /// Creates a new [`MenuBar`][crate::MenuBar]
345    ///
346    /// # Returns
347    ///
348    /// the new menu bar, as a [`Widget`][crate::Widget]
349    #[doc(alias = "gtk_menu_bar_new")]
350    pub fn new() -> MenuBar {
351        assert_initialized_main_thread!();
352        unsafe { Widget::from_glib_none(ffi::gtk_menu_bar_new()).unsafe_cast() }
353    }
354
355    /// Creates a new [`MenuBar`][crate::MenuBar] and populates it with menu items
356    /// and submenus according to `model`.
357    ///
358    /// The created menu items are connected to actions found in the
359    /// [`ApplicationWindow`][crate::ApplicationWindow] to which the menu bar belongs - typically
360    /// by means of being contained within the `GtkApplicationWindows`
361    /// widget hierarchy.
362    /// ## `model`
363    /// a [`gio::MenuModel`][crate::gio::MenuModel]
364    ///
365    /// # Returns
366    ///
367    /// a new [`MenuBar`][crate::MenuBar]
368    #[doc(alias = "gtk_menu_bar_new_from_model")]
369    #[doc(alias = "new_from_model")]
370    pub fn from_model(model: &impl IsA<gio::MenuModel>) -> MenuBar {
371        assert_initialized_main_thread!();
372        unsafe {
373            Widget::from_glib_none(ffi::gtk_menu_bar_new_from_model(
374                model.as_ref().to_glib_none().0,
375            ))
376            .unsafe_cast()
377        }
378    }
379
380    // rustdoc-stripper-ignore-next
381    /// Creates a new builder-pattern struct instance to construct [`MenuBar`] objects.
382    ///
383    /// This method returns an instance of [`MenuBarBuilder`](crate::builders::MenuBarBuilder) which can be used to create [`MenuBar`] objects.
384    pub fn builder() -> MenuBarBuilder {
385        MenuBarBuilder::new()
386    }
387}
388
389impl Default for MenuBar {
390    fn default() -> Self {
391        Self::new()
392    }
393}
394
395// rustdoc-stripper-ignore-next
396/// A [builder-pattern] type to construct [`MenuBar`] objects.
397///
398/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
399#[must_use = "The builder must be built to be used"]
400pub struct MenuBarBuilder {
401    builder: glib::object::ObjectBuilder<'static, MenuBar>,
402}
403
404impl MenuBarBuilder {
405    fn new() -> Self {
406        Self {
407            builder: glib::object::Object::builder(),
408        }
409    }
410
411    /// The child pack direction of the menubar. It determines how
412    /// the widgets contained in child menuitems are arranged.
413    pub fn child_pack_direction(self, child_pack_direction: PackDirection) -> Self {
414        Self {
415            builder: self
416                .builder
417                .property("child-pack-direction", child_pack_direction),
418        }
419    }
420
421    /// The pack direction of the menubar. It determines how
422    /// menuitems are arranged in the menubar.
423    pub fn pack_direction(self, pack_direction: PackDirection) -> Self {
424        Self {
425            builder: self.builder.property("pack-direction", pack_direction),
426        }
427    }
428
429    /// A boolean that determines whether the menu and its submenus grab the
430    /// keyboard focus. See [`MenuShellExt::set_take_focus()`][crate::prelude::MenuShellExt::set_take_focus()] and
431    /// [`MenuShellExt::takes_focus()`][crate::prelude::MenuShellExt::takes_focus()].
432    pub fn take_focus(self, take_focus: bool) -> Self {
433        Self {
434            builder: self.builder.property("take-focus", take_focus),
435        }
436    }
437
438    pub fn border_width(self, border_width: u32) -> Self {
439        Self {
440            builder: self.builder.property("border-width", border_width),
441        }
442    }
443
444    pub fn child(self, child: &impl IsA<Widget>) -> Self {
445        Self {
446            builder: self.builder.property("child", child.clone().upcast()),
447        }
448    }
449
450    pub fn resize_mode(self, resize_mode: ResizeMode) -> Self {
451        Self {
452            builder: self.builder.property("resize-mode", resize_mode),
453        }
454    }
455
456    pub fn app_paintable(self, app_paintable: bool) -> Self {
457        Self {
458            builder: self.builder.property("app-paintable", app_paintable),
459        }
460    }
461
462    pub fn can_default(self, can_default: bool) -> Self {
463        Self {
464            builder: self.builder.property("can-default", can_default),
465        }
466    }
467
468    pub fn can_focus(self, can_focus: bool) -> Self {
469        Self {
470            builder: self.builder.property("can-focus", can_focus),
471        }
472    }
473
474    pub fn events(self, events: gdk::EventMask) -> Self {
475        Self {
476            builder: self.builder.property("events", events),
477        }
478    }
479
480    /// Whether to expand in both directions. Setting this sets both [`hexpand`][struct@crate::Widget#hexpand] and [`vexpand`][struct@crate::Widget#vexpand]
481    pub fn expand(self, expand: bool) -> Self {
482        Self {
483            builder: self.builder.property("expand", expand),
484        }
485    }
486
487    /// Whether the widget should grab focus when it is clicked with the mouse.
488    ///
489    /// This property is only relevant for widgets that can take focus.
490    ///
491    /// Before 3.20, several widgets (GtkButton, GtkFileChooserButton,
492    /// GtkComboBox) implemented this property individually.
493    pub fn focus_on_click(self, focus_on_click: bool) -> Self {
494        Self {
495            builder: self.builder.property("focus-on-click", focus_on_click),
496        }
497    }
498
499    /// How to distribute horizontal space if widget gets extra space, see [`Align`][crate::Align]
500    pub fn halign(self, halign: Align) -> Self {
501        Self {
502            builder: self.builder.property("halign", halign),
503        }
504    }
505
506    pub fn has_default(self, has_default: bool) -> Self {
507        Self {
508            builder: self.builder.property("has-default", has_default),
509        }
510    }
511
512    pub fn has_focus(self, has_focus: bool) -> Self {
513        Self {
514            builder: self.builder.property("has-focus", has_focus),
515        }
516    }
517
518    /// Enables or disables the emission of [`query-tooltip`][struct@crate::Widget#query-tooltip] on `widget`.
519    /// A value of [`true`] indicates that `widget` can have a tooltip, in this case
520    /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to determine
521    /// whether it will provide a tooltip or not.
522    ///
523    /// Note that setting this property to [`true`] for the first time will change
524    /// the event masks of the GdkWindows of this widget to include leave-notify
525    /// and motion-notify events. This cannot and will not be undone when the
526    /// property is set to [`false`] again.
527    pub fn has_tooltip(self, has_tooltip: bool) -> Self {
528        Self {
529            builder: self.builder.property("has-tooltip", has_tooltip),
530        }
531    }
532
533    pub fn height_request(self, height_request: i32) -> Self {
534        Self {
535            builder: self.builder.property("height-request", height_request),
536        }
537    }
538
539    /// Whether to expand horizontally. See [`WidgetExt::set_hexpand()`][crate::prelude::WidgetExt::set_hexpand()].
540    pub fn hexpand(self, hexpand: bool) -> Self {
541        Self {
542            builder: self.builder.property("hexpand", hexpand),
543        }
544    }
545
546    /// Whether to use the [`hexpand`][struct@crate::Widget#hexpand] property. See [`WidgetExt::is_hexpand_set()`][crate::prelude::WidgetExt::is_hexpand_set()].
547    pub fn hexpand_set(self, hexpand_set: bool) -> Self {
548        Self {
549            builder: self.builder.property("hexpand-set", hexpand_set),
550        }
551    }
552
553    pub fn is_focus(self, is_focus: bool) -> Self {
554        Self {
555            builder: self.builder.property("is-focus", is_focus),
556        }
557    }
558
559    /// Sets all four sides' margin at once. If read, returns max
560    /// margin on any side.
561    pub fn margin(self, margin: i32) -> Self {
562        Self {
563            builder: self.builder.property("margin", margin),
564        }
565    }
566
567    /// Margin on bottom side of widget.
568    ///
569    /// This property adds margin outside of the widget's normal size
570    /// request, the margin will be added in addition to the size from
571    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
572    pub fn margin_bottom(self, margin_bottom: i32) -> Self {
573        Self {
574            builder: self.builder.property("margin-bottom", margin_bottom),
575        }
576    }
577
578    /// Margin on end of widget, horizontally. This property supports
579    /// left-to-right and right-to-left text directions.
580    ///
581    /// This property adds margin outside of the widget's normal size
582    /// request, the margin will be added in addition to the size from
583    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
584    pub fn margin_end(self, margin_end: i32) -> Self {
585        Self {
586            builder: self.builder.property("margin-end", margin_end),
587        }
588    }
589
590    /// Margin on start of widget, horizontally. This property supports
591    /// left-to-right and right-to-left text directions.
592    ///
593    /// This property adds margin outside of the widget's normal size
594    /// request, the margin will be added in addition to the size from
595    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
596    pub fn margin_start(self, margin_start: i32) -> Self {
597        Self {
598            builder: self.builder.property("margin-start", margin_start),
599        }
600    }
601
602    /// Margin on top side of widget.
603    ///
604    /// This property adds margin outside of the widget's normal size
605    /// request, the margin will be added in addition to the size from
606    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
607    pub fn margin_top(self, margin_top: i32) -> Self {
608        Self {
609            builder: self.builder.property("margin-top", margin_top),
610        }
611    }
612
613    pub fn name(self, name: impl Into<glib::GString>) -> Self {
614        Self {
615            builder: self.builder.property("name", name.into()),
616        }
617    }
618
619    pub fn no_show_all(self, no_show_all: bool) -> Self {
620        Self {
621            builder: self.builder.property("no-show-all", no_show_all),
622        }
623    }
624
625    /// The requested opacity of the widget. See [`WidgetExt::set_opacity()`][crate::prelude::WidgetExt::set_opacity()] for
626    /// more details about window opacity.
627    ///
628    /// Before 3.8 this was only available in GtkWindow
629    pub fn opacity(self, opacity: f64) -> Self {
630        Self {
631            builder: self.builder.property("opacity", opacity),
632        }
633    }
634
635    pub fn parent(self, parent: &impl IsA<Container>) -> Self {
636        Self {
637            builder: self.builder.property("parent", parent.clone().upcast()),
638        }
639    }
640
641    pub fn receives_default(self, receives_default: bool) -> Self {
642        Self {
643            builder: self.builder.property("receives-default", receives_default),
644        }
645    }
646
647    pub fn sensitive(self, sensitive: bool) -> Self {
648        Self {
649            builder: self.builder.property("sensitive", sensitive),
650        }
651    }
652
653    /// Sets the text of tooltip to be the given string, which is marked up
654    /// with the [Pango text markup language][PangoMarkupFormat].
655    /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
656    ///
657    /// This is a convenience property which will take care of getting the
658    /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
659    /// will automatically be set to [`true`] and there will be taken care of
660    /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
661    ///
662    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
663    /// are set, the last one wins.
664    pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
665        Self {
666            builder: self
667                .builder
668                .property("tooltip-markup", tooltip_markup.into()),
669        }
670    }
671
672    /// Sets the text of tooltip to be the given string.
673    ///
674    /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
675    ///
676    /// This is a convenience property which will take care of getting the
677    /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
678    /// will automatically be set to [`true`] and there will be taken care of
679    /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
680    ///
681    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
682    /// are set, the last one wins.
683    pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
684        Self {
685            builder: self.builder.property("tooltip-text", tooltip_text.into()),
686        }
687    }
688
689    /// How to distribute vertical space if widget gets extra space, see [`Align`][crate::Align]
690    pub fn valign(self, valign: Align) -> Self {
691        Self {
692            builder: self.builder.property("valign", valign),
693        }
694    }
695
696    /// Whether to expand vertically. See [`WidgetExt::set_vexpand()`][crate::prelude::WidgetExt::set_vexpand()].
697    pub fn vexpand(self, vexpand: bool) -> Self {
698        Self {
699            builder: self.builder.property("vexpand", vexpand),
700        }
701    }
702
703    /// Whether to use the [`vexpand`][struct@crate::Widget#vexpand] property. See [`WidgetExt::is_vexpand_set()`][crate::prelude::WidgetExt::is_vexpand_set()].
704    pub fn vexpand_set(self, vexpand_set: bool) -> Self {
705        Self {
706            builder: self.builder.property("vexpand-set", vexpand_set),
707        }
708    }
709
710    pub fn visible(self, visible: bool) -> Self {
711        Self {
712            builder: self.builder.property("visible", visible),
713        }
714    }
715
716    pub fn width_request(self, width_request: i32) -> Self {
717        Self {
718            builder: self.builder.property("width-request", width_request),
719        }
720    }
721
722    // rustdoc-stripper-ignore-next
723    /// Build the [`MenuBar`].
724    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
725    pub fn build(self) -> MenuBar {
726        assert_initialized_main_thread!();
727        self.builder.build()
728    }
729}
730
731/// Trait containing all [`struct@MenuBar`] methods.
732///
733/// # Implementors
734///
735/// [`MenuBar`][struct@crate::MenuBar]
736pub trait MenuBarExt: IsA<MenuBar> + 'static {
737    /// Retrieves the current child pack direction of the menubar.
738    /// See [`set_child_pack_direction()`][Self::set_child_pack_direction()].
739    ///
740    /// # Returns
741    ///
742    /// the child pack direction
743    #[doc(alias = "gtk_menu_bar_get_child_pack_direction")]
744    #[doc(alias = "get_child_pack_direction")]
745    #[doc(alias = "child-pack-direction")]
746    fn child_pack_direction(&self) -> PackDirection {
747        unsafe {
748            from_glib(ffi::gtk_menu_bar_get_child_pack_direction(
749                self.as_ref().to_glib_none().0,
750            ))
751        }
752    }
753
754    /// Retrieves the current pack direction of the menubar.
755    /// See [`set_pack_direction()`][Self::set_pack_direction()].
756    ///
757    /// # Returns
758    ///
759    /// the pack direction
760    #[doc(alias = "gtk_menu_bar_get_pack_direction")]
761    #[doc(alias = "get_pack_direction")]
762    #[doc(alias = "pack-direction")]
763    fn pack_direction(&self) -> PackDirection {
764        unsafe {
765            from_glib(ffi::gtk_menu_bar_get_pack_direction(
766                self.as_ref().to_glib_none().0,
767            ))
768        }
769    }
770
771    /// Sets how widgets should be packed inside the children of a menubar.
772    /// ## `child_pack_dir`
773    /// a new [`PackDirection`][crate::PackDirection]
774    #[doc(alias = "gtk_menu_bar_set_child_pack_direction")]
775    #[doc(alias = "child-pack-direction")]
776    fn set_child_pack_direction(&self, child_pack_dir: PackDirection) {
777        unsafe {
778            ffi::gtk_menu_bar_set_child_pack_direction(
779                self.as_ref().to_glib_none().0,
780                child_pack_dir.into_glib(),
781            );
782        }
783    }
784
785    /// Sets how items should be packed inside a menubar.
786    /// ## `pack_dir`
787    /// a new [`PackDirection`][crate::PackDirection]
788    #[doc(alias = "gtk_menu_bar_set_pack_direction")]
789    #[doc(alias = "pack-direction")]
790    fn set_pack_direction(&self, pack_dir: PackDirection) {
791        unsafe {
792            ffi::gtk_menu_bar_set_pack_direction(
793                self.as_ref().to_glib_none().0,
794                pack_dir.into_glib(),
795            );
796        }
797    }
798
799    #[doc(alias = "child-pack-direction")]
800    fn connect_child_pack_direction_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
801        unsafe extern "C" fn notify_child_pack_direction_trampoline<
802            P: IsA<MenuBar>,
803            F: Fn(&P) + 'static,
804        >(
805            this: *mut ffi::GtkMenuBar,
806            _param_spec: glib::ffi::gpointer,
807            f: glib::ffi::gpointer,
808        ) {
809            unsafe {
810                let f: &F = &*(f as *const F);
811                f(MenuBar::from_glib_borrow(this).unsafe_cast_ref())
812            }
813        }
814        unsafe {
815            let f: Box_<F> = Box_::new(f);
816            connect_raw(
817                self.as_ptr() as *mut _,
818                c"notify::child-pack-direction".as_ptr(),
819                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
820                    notify_child_pack_direction_trampoline::<Self, F> as *const (),
821                )),
822                Box_::into_raw(f),
823            )
824        }
825    }
826
827    #[doc(alias = "pack-direction")]
828    fn connect_pack_direction_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
829        unsafe extern "C" fn notify_pack_direction_trampoline<
830            P: IsA<MenuBar>,
831            F: Fn(&P) + 'static,
832        >(
833            this: *mut ffi::GtkMenuBar,
834            _param_spec: glib::ffi::gpointer,
835            f: glib::ffi::gpointer,
836        ) {
837            unsafe {
838                let f: &F = &*(f as *const F);
839                f(MenuBar::from_glib_borrow(this).unsafe_cast_ref())
840            }
841        }
842        unsafe {
843            let f: Box_<F> = Box_::new(f);
844            connect_raw(
845                self.as_ptr() as *mut _,
846                c"notify::pack-direction".as_ptr(),
847                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
848                    notify_pack_direction_trampoline::<Self, F> as *const (),
849                )),
850                Box_::into_raw(f),
851            )
852        }
853    }
854}
855
856impl<O: IsA<MenuBar>> MenuBarExt for O {}