gtk4/auto/menu_button.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{
6 ffi, Accessible, AccessibleRole, Align, ArrowType, Buildable, ConstraintTarget, LayoutManager,
7 Overflow, Popover, Widget,
8};
9#[cfg(feature = "v4_4")]
10#[cfg_attr(docsrs, doc(cfg(feature = "v4_4")))]
11use glib::object::ObjectType as _;
12use glib::{
13 prelude::*,
14 signal::{connect_raw, SignalHandlerId},
15 translate::*,
16};
17use std::boxed::Box as Box_;
18
19glib::wrapper! {
20 /// Displays a popup when clicked.
21 ///
22 /// <picture>
23 /// <source srcset="menu-button-dark.png" media="(prefers-color-scheme: dark)">
24 /// <img alt="An example GtkMenuButton" src="menu-button.png">
25 /// </picture>
26 ///
27 /// This popup can be provided either as a [`Popover`][crate::Popover] or as an abstract
28 /// `GMenuModel`.
29 ///
30 /// The [`MenuButton`][crate::MenuButton] widget can show either an icon (set with the
31 /// [`icon-name`][struct@crate::MenuButton#icon-name] property) or a label (set with the
32 /// [`label`][struct@crate::MenuButton#label] property). If neither is explicitly set,
33 /// a [`Image`][crate::Image] is automatically created, using an arrow image oriented
34 /// according to [`direction`][struct@crate::MenuButton#direction] or the generic
35 /// “open-menu-symbolic” icon if the direction is not set.
36 ///
37 /// The positioning of the popup is determined by the
38 /// [`direction`][struct@crate::MenuButton#direction] property of the menu button.
39 ///
40 /// For menus, the [`halign`][struct@crate::Widget#halign] and [`valign`][struct@crate::Widget#valign]
41 /// properties of the menu are also taken into account. For example, when the
42 /// direction is [`ArrowType::Down`][crate::ArrowType::Down] and the horizontal alignment is [`Align::Start`][crate::Align::Start],
43 /// the menu will be positioned below the button, with the starting edge
44 /// (depending on the text direction) of the menu aligned with the starting
45 /// edge of the button. If there is not enough space below the button, the
46 /// menu is popped up above the button instead. If the alignment would move
47 /// part of the menu offscreen, it is “pushed in”.
48 ///
49 /// | | start | center | end |
50 /// | - | --- | --- | --- |
51 /// | **down** |  |  |  |
52 /// | **up** |  |  |  |
53 /// | **left** |  |  |  |
54 /// | **right** |  |  |  |
55 ///
56 /// # CSS nodes
57 ///
58 /// ```text
59 /// menubutton
60 /// ╰── button.toggle
61 /// ╰── <content>
62 /// ╰── [arrow]
63 /// ```
64 ///
65 /// [`MenuButton`][crate::MenuButton] has a single CSS node with name `menubutton`
66 /// which contains a `button` node with a `.toggle` style class.
67 ///
68 /// If the button contains an icon, it will have the `.image-button` style class,
69 /// if it contains text, it will have `.text-button` style class. If an arrow is
70 /// visible in addition to an icon, text or a custom child, it will also have
71 /// `.arrow-button` style class.
72 ///
73 /// Inside the toggle button content, there is an `arrow` node for
74 /// the indicator, which will carry one of the `.none`, `.up`, `.down`,
75 /// `.left` or `.right` style classes to indicate the direction that
76 /// the menu will appear in. The CSS is expected to provide a suitable
77 /// image for each of these cases using the `-gtk-icon-source` property.
78 ///
79 /// Optionally, the `menubutton` node can carry the `.circular` style class
80 /// to request a round appearance.
81 ///
82 /// # Accessibility
83 ///
84 /// [`MenuButton`][crate::MenuButton] uses the [enum@Gtk.AccessibleRole.button] role.
85 ///
86 /// ## Properties
87 ///
88 ///
89 /// #### `active`
90 /// Whether the menu button is active.
91 ///
92 /// Readable | Writeable
93 ///
94 ///
95 /// #### `always-show-arrow`
96 /// Whether to show a dropdown arrow even when using an icon or a custom child.
97 ///
98 /// Readable | Writeable
99 ///
100 ///
101 /// #### `can-shrink`
102 /// Whether the size of the button can be made smaller than the natural
103 /// size of its contents.
104 ///
105 /// Readable | Writeable
106 ///
107 ///
108 /// #### `child`
109 /// The child widget.
110 ///
111 /// Readable | Writeable
112 ///
113 ///
114 /// #### `direction`
115 /// The [`ArrowType`][crate::ArrowType] representing the direction in which the
116 /// menu or popover will be popped out.
117 ///
118 /// Readable | Writeable
119 ///
120 ///
121 /// #### `has-frame`
122 /// Whether the button has a frame.
123 ///
124 /// Readable | Writeable
125 ///
126 ///
127 /// #### `icon-name`
128 /// The name of the icon used to automatically populate the button.
129 ///
130 /// Readable | Writeable
131 ///
132 ///
133 /// #### `label`
134 /// The label for the button.
135 ///
136 /// Readable | Writeable
137 ///
138 ///
139 /// #### `menu-model`
140 /// The `GMenuModel` from which the popup will be created.
141 ///
142 /// See [`MenuButton::set_menu_model()`][crate::MenuButton::set_menu_model()] for the interaction
143 /// with the [`popover`][struct@crate::MenuButton#popover] property.
144 ///
145 /// Readable | Writeable
146 ///
147 ///
148 /// #### `popover`
149 /// The [`Popover`][crate::Popover] that will be popped up when the button is clicked.
150 ///
151 /// Readable | Writeable
152 ///
153 ///
154 /// #### `primary`
155 /// Whether the menu button acts as a primary menu.
156 ///
157 /// Primary menus can be opened using the <kbd>F10</kbd> key
158 ///
159 /// Readable | Writeable
160 ///
161 ///
162 /// #### `use-underline`
163 /// If set an underscore in the text indicates a mnemonic.
164 ///
165 /// Readable | Writeable
166 /// <details><summary><h4>Widget</h4></summary>
167 ///
168 ///
169 /// #### `can-focus`
170 /// Whether the widget or any of its descendents can accept
171 /// the input focus.
172 ///
173 /// This property is meant to be set by widget implementations,
174 /// typically in their instance init function.
175 ///
176 /// Readable | Writeable
177 ///
178 ///
179 /// #### `can-target`
180 /// Whether the widget can receive pointer events.
181 ///
182 /// Readable | Writeable
183 ///
184 ///
185 /// #### `css-classes`
186 /// A list of css classes applied to this widget.
187 ///
188 /// Readable | Writeable
189 ///
190 ///
191 /// #### `css-name`
192 /// The name of this widget in the CSS tree.
193 ///
194 /// This property is meant to be set by widget implementations,
195 /// typically in their instance init function.
196 ///
197 /// Readable | Writeable | Construct Only
198 ///
199 ///
200 /// #### `cursor`
201 /// The cursor used by @widget.
202 ///
203 /// Readable | Writeable
204 ///
205 ///
206 /// #### `focus-on-click`
207 /// Whether the widget should grab focus when it is clicked with the mouse.
208 ///
209 /// This property is only relevant for widgets that can take focus.
210 ///
211 /// Readable | Writeable
212 ///
213 ///
214 /// #### `focusable`
215 /// Whether this widget itself will accept the input focus.
216 ///
217 /// Readable | Writeable
218 ///
219 ///
220 /// #### `halign`
221 /// How to distribute horizontal space if widget gets extra space.
222 ///
223 /// Readable | Writeable
224 ///
225 ///
226 /// #### `has-default`
227 /// Whether the widget is the default widget.
228 ///
229 /// Readable
230 ///
231 ///
232 /// #### `has-focus`
233 /// Whether the widget has the input focus.
234 ///
235 /// Readable
236 ///
237 ///
238 /// #### `has-tooltip`
239 /// Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
240 /// signal on @widget.
241 ///
242 /// A true value indicates that @widget can have a tooltip, in this case
243 /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
244 /// determine whether it will provide a tooltip or not.
245 ///
246 /// Readable | Writeable
247 ///
248 ///
249 /// #### `height-request`
250 /// Overrides for height request of the widget.
251 ///
252 /// If this is -1, the natural request will be used.
253 ///
254 /// Readable | Writeable
255 ///
256 ///
257 /// #### `hexpand`
258 /// Whether to expand horizontally.
259 ///
260 /// Readable | Writeable
261 ///
262 ///
263 /// #### `hexpand-set`
264 /// Whether to use the `hexpand` property.
265 ///
266 /// Readable | Writeable
267 ///
268 ///
269 /// #### `layout-manager`
270 /// The [`LayoutManager`][crate::LayoutManager] instance to use to compute
271 /// the preferred size of the widget, and allocate its children.
272 ///
273 /// This property is meant to be set by widget implementations,
274 /// typically in their instance init function.
275 ///
276 /// Readable | Writeable
277 ///
278 ///
279 /// #### `limit-events`
280 /// Makes this widget act like a modal dialog, with respect to
281 /// event delivery.
282 ///
283 /// Global event controllers will not handle events with targets
284 /// inside the widget, unless they are set up to ignore propagation
285 /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
286 ///
287 /// Readable | Writeable
288 ///
289 ///
290 /// #### `margin-bottom`
291 /// Margin on bottom side of widget.
292 ///
293 /// This property adds margin outside of the widget's normal size
294 /// request, the margin will be added in addition to the size from
295 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
296 ///
297 /// Readable | Writeable
298 ///
299 ///
300 /// #### `margin-end`
301 /// Margin on end of widget, horizontally.
302 ///
303 /// This property supports left-to-right and right-to-left text
304 /// directions.
305 ///
306 /// This property adds margin outside of the widget's normal size
307 /// request, the margin will be added in addition to the size from
308 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
309 ///
310 /// Readable | Writeable
311 ///
312 ///
313 /// #### `margin-start`
314 /// Margin on start of widget, horizontally.
315 ///
316 /// This property supports left-to-right and right-to-left text
317 /// directions.
318 ///
319 /// This property adds margin outside of the widget's normal size
320 /// request, the margin will be added in addition to the size from
321 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
322 ///
323 /// Readable | Writeable
324 ///
325 ///
326 /// #### `margin-top`
327 /// Margin on top side of widget.
328 ///
329 /// This property adds margin outside of the widget's normal size
330 /// request, the margin will be added in addition to the size from
331 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
332 ///
333 /// Readable | Writeable
334 ///
335 ///
336 /// #### `name`
337 /// The name of the widget.
338 ///
339 /// Readable | Writeable
340 ///
341 ///
342 /// #### `opacity`
343 /// The requested opacity of the widget.
344 ///
345 /// Readable | Writeable
346 ///
347 ///
348 /// #### `overflow`
349 /// How content outside the widget's content area is treated.
350 ///
351 /// This property is meant to be set by widget implementations,
352 /// typically in their instance init function.
353 ///
354 /// Readable | Writeable
355 ///
356 ///
357 /// #### `parent`
358 /// The parent widget of this widget.
359 ///
360 /// Readable
361 ///
362 ///
363 /// #### `receives-default`
364 /// Whether the widget will receive the default action when it is focused.
365 ///
366 /// Readable | Writeable
367 ///
368 ///
369 /// #### `root`
370 /// The [`Root`][crate::Root] widget of the widget tree containing this widget.
371 ///
372 /// This will be `NULL` if the widget is not contained in a root widget.
373 ///
374 /// Readable
375 ///
376 ///
377 /// #### `scale-factor`
378 /// The scale factor of the widget.
379 ///
380 /// Readable
381 ///
382 ///
383 /// #### `sensitive`
384 /// Whether the widget responds to input.
385 ///
386 /// Readable | Writeable
387 ///
388 ///
389 /// #### `tooltip-markup`
390 /// Sets the text of tooltip to be the given string, which is marked up
391 /// with Pango markup.
392 ///
393 /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
394 ///
395 /// This is a convenience property which will take care of getting the
396 /// tooltip shown if the given string is not `NULL`:
397 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
398 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
399 /// the default signal handler.
400 ///
401 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
402 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
403 ///
404 /// Readable | Writeable
405 ///
406 ///
407 /// #### `tooltip-text`
408 /// Sets the text of tooltip to be the given string.
409 ///
410 /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
411 ///
412 /// This is a convenience property which will take care of getting the
413 /// tooltip shown if the given string is not `NULL`:
414 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
415 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
416 /// the default signal handler.
417 ///
418 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
419 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
420 ///
421 /// Readable | Writeable
422 ///
423 ///
424 /// #### `valign`
425 /// How to distribute vertical space if widget gets extra space.
426 ///
427 /// Readable | Writeable
428 ///
429 ///
430 /// #### `vexpand`
431 /// Whether to expand vertically.
432 ///
433 /// Readable | Writeable
434 ///
435 ///
436 /// #### `vexpand-set`
437 /// Whether to use the `vexpand` property.
438 ///
439 /// Readable | Writeable
440 ///
441 ///
442 /// #### `visible`
443 /// Whether the widget is visible.
444 ///
445 /// Readable | Writeable
446 ///
447 ///
448 /// #### `width-request`
449 /// Overrides for width request of the widget.
450 ///
451 /// If this is -1, the natural request will be used.
452 ///
453 /// Readable | Writeable
454 /// </details>
455 /// <details><summary><h4>Accessible</h4></summary>
456 ///
457 ///
458 /// #### `accessible-role`
459 /// The accessible role of the given [`Accessible`][crate::Accessible] implementation.
460 ///
461 /// The accessible role cannot be changed once set.
462 ///
463 /// Readable | Writeable
464 /// </details>
465 ///
466 /// ## Signals
467 ///
468 ///
469 /// #### `activate`
470 /// Emitted to when the menu button is activated.
471 ///
472 /// The `::activate` signal on [`MenuButton`][crate::MenuButton] is an action signal and
473 /// emitting it causes the button to pop up its menu.
474 ///
475 /// Action
476 /// <details><summary><h4>Widget</h4></summary>
477 ///
478 ///
479 /// #### `destroy`
480 /// Signals that all holders of a reference to the widget should release
481 /// the reference that they hold.
482 ///
483 /// May result in finalization of the widget if all references are released.
484 ///
485 /// This signal is not suitable for saving widget state.
486 ///
487 ///
488 ///
489 ///
490 /// #### `direction-changed`
491 /// Emitted when the text direction of a widget changes.
492 ///
493 ///
494 ///
495 ///
496 /// #### `hide`
497 /// Emitted when @widget is hidden.
498 ///
499 ///
500 ///
501 ///
502 /// #### `keynav-failed`
503 /// Emitted if keyboard navigation fails.
504 ///
505 /// See [`WidgetExt::keynav_failed()`][crate::prelude::WidgetExt::keynav_failed()] for details.
506 ///
507 ///
508 ///
509 ///
510 /// #### `map`
511 /// Emitted when @widget is going to be mapped.
512 ///
513 /// A widget is mapped when the widget is visible (which is controlled with
514 /// [`visible`][struct@crate::Widget#visible]) and all its parents up to the toplevel widget
515 /// are also visible.
516 ///
517 /// The `::map` signal can be used to determine whether a widget will be drawn,
518 /// for instance it can resume an animation that was stopped during the
519 /// emission of [`unmap`][struct@crate::Widget#unmap].
520 ///
521 ///
522 ///
523 ///
524 /// #### `mnemonic-activate`
525 /// Emitted when a widget is activated via a mnemonic.
526 ///
527 /// The default handler for this signal activates @widget if @group_cycling
528 /// is false, or just makes @widget grab focus if @group_cycling is true.
529 ///
530 ///
531 ///
532 ///
533 /// #### `move-focus`
534 /// Emitted when the focus is moved.
535 ///
536 /// The `::move-focus` signal is a [keybinding signal](class.SignalAction.html).
537 ///
538 /// The default bindings for this signal are <kbd>Tab</kbd> to move forward,
539 /// and <kbd>Shift</kbd>+<kbd>Tab</kbd> to move backward.
540 ///
541 /// Action
542 ///
543 ///
544 /// #### `query-tooltip`
545 /// Emitted when the widget’s tooltip is about to be shown.
546 ///
547 /// This happens when the [`has-tooltip`][struct@crate::Widget#has-tooltip] property
548 /// is true and the hover timeout has expired with the cursor hovering
549 /// above @widget; or emitted when @widget got focus in keyboard mode.
550 ///
551 /// Using the given coordinates, the signal handler should determine
552 /// whether a tooltip should be shown for @widget. If this is the case
553 /// true should be returned, false otherwise. Note that if @keyboard_mode
554 /// is true, the values of @x and @y are undefined and should not be used.
555 ///
556 /// The signal handler is free to manipulate @tooltip with the therefore
557 /// destined function calls.
558 ///
559 ///
560 ///
561 ///
562 /// #### `realize`
563 /// Emitted when @widget is associated with a [`gdk::Surface`][crate::gdk::Surface].
564 ///
565 /// This means that [`WidgetExt::realize()`][crate::prelude::WidgetExt::realize()] has been called
566 /// or the widget has been mapped (that is, it is going to be drawn).
567 ///
568 ///
569 ///
570 ///
571 /// #### `show`
572 /// Emitted when @widget is shown.
573 ///
574 ///
575 ///
576 ///
577 /// #### `state-flags-changed`
578 /// Emitted when the widget state changes.
579 ///
580 /// See [`WidgetExt::state_flags()`][crate::prelude::WidgetExt::state_flags()].
581 ///
582 ///
583 ///
584 ///
585 /// #### `unmap`
586 /// Emitted when @widget is going to be unmapped.
587 ///
588 /// A widget is unmapped when either it or any of its parents up to the
589 /// toplevel widget have been set as hidden.
590 ///
591 /// As `::unmap` indicates that a widget will not be shown any longer,
592 /// it can be used to, for example, stop an animation on the widget.
593 ///
594 ///
595 ///
596 ///
597 /// #### `unrealize`
598 /// Emitted when the [`gdk::Surface`][crate::gdk::Surface] associated with @widget is destroyed.
599 ///
600 /// This means that [`WidgetExt::unrealize()`][crate::prelude::WidgetExt::unrealize()] has been called
601 /// or the widget has been unmapped (that is, it is going to be hidden).
602 ///
603 ///
604 /// </details>
605 ///
606 /// # Implements
607 ///
608 /// [`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]
609 #[doc(alias = "GtkMenuButton")]
610 pub struct MenuButton(Object<ffi::GtkMenuButton>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget;
611
612 match fn {
613 type_ => || ffi::gtk_menu_button_get_type(),
614 }
615}
616
617impl MenuButton {
618 /// Creates a new [`MenuButton`][crate::MenuButton] widget with downwards-pointing
619 /// arrow as the only child.
620 ///
621 /// You can replace the child widget with another [`Widget`][crate::Widget]
622 /// should you wish to.
623 ///
624 /// # Returns
625 ///
626 /// The newly created [`MenuButton`][crate::MenuButton]
627 #[doc(alias = "gtk_menu_button_new")]
628 pub fn new() -> MenuButton {
629 assert_initialized_main_thread!();
630 unsafe { Widget::from_glib_none(ffi::gtk_menu_button_new()).unsafe_cast() }
631 }
632
633 // rustdoc-stripper-ignore-next
634 /// Creates a new builder-pattern struct instance to construct [`MenuButton`] objects.
635 ///
636 /// This method returns an instance of [`MenuButtonBuilder`](crate::builders::MenuButtonBuilder) which can be used to create [`MenuButton`] objects.
637 pub fn builder() -> MenuButtonBuilder {
638 MenuButtonBuilder::new()
639 }
640
641 /// Returns whether the menu button is active.
642 ///
643 /// # Returns
644 ///
645 /// TRUE if the button is active
646 #[cfg(feature = "v4_10")]
647 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
648 #[doc(alias = "gtk_menu_button_get_active")]
649 #[doc(alias = "get_active")]
650 #[doc(alias = "active")]
651 pub fn is_active(&self) -> bool {
652 unsafe { from_glib(ffi::gtk_menu_button_get_active(self.to_glib_none().0)) }
653 }
654
655 /// Gets whether to show a dropdown arrow even when using an icon or a custom
656 /// child.
657 ///
658 /// # Returns
659 ///
660 /// whether to show a dropdown arrow even when using an icon or a custom
661 /// child.
662 #[cfg(feature = "v4_4")]
663 #[cfg_attr(docsrs, doc(cfg(feature = "v4_4")))]
664 #[doc(alias = "gtk_menu_button_get_always_show_arrow")]
665 #[doc(alias = "get_always_show_arrow")]
666 #[doc(alias = "always-show-arrow")]
667 pub fn must_always_show_arrow(&self) -> bool {
668 unsafe {
669 from_glib(ffi::gtk_menu_button_get_always_show_arrow(
670 self.to_glib_none().0,
671 ))
672 }
673 }
674
675 /// Retrieves whether the button can be smaller than the natural
676 /// size of its contents.
677 ///
678 /// # Returns
679 ///
680 /// true if the button can shrink, and false otherwise
681 #[cfg(feature = "v4_12")]
682 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
683 #[doc(alias = "gtk_menu_button_get_can_shrink")]
684 #[doc(alias = "get_can_shrink")]
685 #[doc(alias = "can-shrink")]
686 pub fn can_shrink(&self) -> bool {
687 unsafe { from_glib(ffi::gtk_menu_button_get_can_shrink(self.to_glib_none().0)) }
688 }
689
690 /// Gets the child widget of @self.
691 ///
692 /// # Returns
693 ///
694 /// the child widget of @self
695 #[cfg(feature = "v4_6")]
696 #[cfg_attr(docsrs, doc(cfg(feature = "v4_6")))]
697 #[doc(alias = "gtk_menu_button_get_child")]
698 #[doc(alias = "get_child")]
699 pub fn child(&self) -> Option<Widget> {
700 unsafe { from_glib_none(ffi::gtk_menu_button_get_child(self.to_glib_none().0)) }
701 }
702
703 /// Returns the direction the popup will be pointing at when popped up.
704 ///
705 /// # Returns
706 ///
707 /// a [`ArrowType`][crate::ArrowType] value
708 #[doc(alias = "gtk_menu_button_get_direction")]
709 #[doc(alias = "get_direction")]
710 pub fn direction(&self) -> ArrowType {
711 unsafe { from_glib(ffi::gtk_menu_button_get_direction(self.to_glib_none().0)) }
712 }
713
714 /// Returns whether the button has a frame.
715 ///
716 /// # Returns
717 ///
718 /// [`true`] if the button has a frame
719 #[doc(alias = "gtk_menu_button_get_has_frame")]
720 #[doc(alias = "get_has_frame")]
721 #[doc(alias = "has-frame")]
722 pub fn has_frame(&self) -> bool {
723 unsafe { from_glib(ffi::gtk_menu_button_get_has_frame(self.to_glib_none().0)) }
724 }
725
726 /// Gets the name of the icon shown in the button.
727 ///
728 /// # Returns
729 ///
730 /// the name of the icon shown in the button
731 #[doc(alias = "gtk_menu_button_get_icon_name")]
732 #[doc(alias = "get_icon_name")]
733 #[doc(alias = "icon-name")]
734 pub fn icon_name(&self) -> Option<glib::GString> {
735 unsafe { from_glib_none(ffi::gtk_menu_button_get_icon_name(self.to_glib_none().0)) }
736 }
737
738 /// Gets the label shown in the button
739 ///
740 /// # Returns
741 ///
742 /// the label shown in the button
743 #[doc(alias = "gtk_menu_button_get_label")]
744 #[doc(alias = "get_label")]
745 pub fn label(&self) -> Option<glib::GString> {
746 unsafe { from_glib_none(ffi::gtk_menu_button_get_label(self.to_glib_none().0)) }
747 }
748
749 /// Returns the `GMenuModel` used to generate the popup.
750 ///
751 /// # Returns
752 ///
753 /// a `GMenuModel`
754 #[doc(alias = "gtk_menu_button_get_menu_model")]
755 #[doc(alias = "get_menu_model")]
756 #[doc(alias = "menu-model")]
757 pub fn menu_model(&self) -> Option<gio::MenuModel> {
758 unsafe { from_glib_none(ffi::gtk_menu_button_get_menu_model(self.to_glib_none().0)) }
759 }
760
761 /// Returns the [`Popover`][crate::Popover] that pops out of the button.
762 ///
763 /// If the button is not using a [`Popover`][crate::Popover], this function
764 /// returns [`None`].
765 ///
766 /// # Returns
767 ///
768 /// a [`Popover`][crate::Popover] or [`None`]
769 #[doc(alias = "gtk_menu_button_get_popover")]
770 #[doc(alias = "get_popover")]
771 pub fn popover(&self) -> Option<Popover> {
772 unsafe { from_glib_none(ffi::gtk_menu_button_get_popover(self.to_glib_none().0)) }
773 }
774
775 /// Returns whether the menu button acts as a primary menu.
776 ///
777 /// # Returns
778 ///
779 /// [`true`] if the button is a primary menu
780 #[cfg(feature = "v4_4")]
781 #[cfg_attr(docsrs, doc(cfg(feature = "v4_4")))]
782 #[doc(alias = "gtk_menu_button_get_primary")]
783 #[doc(alias = "get_primary")]
784 #[doc(alias = "primary")]
785 pub fn is_primary(&self) -> bool {
786 unsafe { from_glib(ffi::gtk_menu_button_get_primary(self.to_glib_none().0)) }
787 }
788
789 /// Returns whether an embedded underline in the text indicates a
790 /// mnemonic.
791 ///
792 /// # Returns
793 ///
794 /// [`true`] whether an embedded underline in the text indicates
795 /// the mnemonic accelerator keys.
796 #[doc(alias = "gtk_menu_button_get_use_underline")]
797 #[doc(alias = "get_use_underline")]
798 #[doc(alias = "use-underline")]
799 pub fn uses_underline(&self) -> bool {
800 unsafe {
801 from_glib(ffi::gtk_menu_button_get_use_underline(
802 self.to_glib_none().0,
803 ))
804 }
805 }
806
807 /// Dismiss the menu.
808 #[doc(alias = "gtk_menu_button_popdown")]
809 pub fn popdown(&self) {
810 unsafe {
811 ffi::gtk_menu_button_popdown(self.to_glib_none().0);
812 }
813 }
814
815 /// Pop up the menu.
816 #[doc(alias = "gtk_menu_button_popup")]
817 pub fn popup(&self) {
818 unsafe {
819 ffi::gtk_menu_button_popup(self.to_glib_none().0);
820 }
821 }
822
823 /// Sets whether the menu button is active.
824 /// ## `active`
825 /// whether the menu button is active
826 #[cfg(feature = "v4_10")]
827 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
828 #[doc(alias = "gtk_menu_button_set_active")]
829 #[doc(alias = "active")]
830 pub fn set_active(&self, active: bool) {
831 unsafe {
832 ffi::gtk_menu_button_set_active(self.to_glib_none().0, active.into_glib());
833 }
834 }
835
836 /// Sets whether to show a dropdown arrow even when using an icon or a custom
837 /// child.
838 /// ## `always_show_arrow`
839 /// whether to show a dropdown arrow even when using an icon
840 /// or a custom child
841 #[cfg(feature = "v4_4")]
842 #[cfg_attr(docsrs, doc(cfg(feature = "v4_4")))]
843 #[doc(alias = "gtk_menu_button_set_always_show_arrow")]
844 #[doc(alias = "always-show-arrow")]
845 pub fn set_always_show_arrow(&self, always_show_arrow: bool) {
846 unsafe {
847 ffi::gtk_menu_button_set_always_show_arrow(
848 self.to_glib_none().0,
849 always_show_arrow.into_glib(),
850 );
851 }
852 }
853
854 /// Sets whether the button size can be smaller than the natural size of
855 /// its contents.
856 ///
857 /// For text buttons, setting @can_shrink to true will ellipsize the label.
858 ///
859 /// For icon buttons, this function has no effect.
860 /// ## `can_shrink`
861 /// whether the button can shrink
862 #[cfg(feature = "v4_12")]
863 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
864 #[doc(alias = "gtk_menu_button_set_can_shrink")]
865 #[doc(alias = "can-shrink")]
866 pub fn set_can_shrink(&self, can_shrink: bool) {
867 unsafe {
868 ffi::gtk_menu_button_set_can_shrink(self.to_glib_none().0, can_shrink.into_glib());
869 }
870 }
871
872 /// Sets the child widget of @self.
873 ///
874 /// Setting a child resets [`label`][struct@crate::MenuButton#label] and
875 /// [`icon-name`][struct@crate::MenuButton#icon-name].
876 ///
877 /// If [`always-show-arrow`][struct@crate::MenuButton#always-show-arrow] is set to `TRUE` and
878 /// [`direction`][struct@crate::MenuButton#direction] is not `GTK_ARROW_NONE`, a dropdown arrow
879 /// will be shown next to the child.
880 /// ## `child`
881 /// the child widget
882 #[cfg(feature = "v4_6")]
883 #[cfg_attr(docsrs, doc(cfg(feature = "v4_6")))]
884 #[doc(alias = "gtk_menu_button_set_child")]
885 #[doc(alias = "child")]
886 pub fn set_child(&self, child: Option<&impl IsA<Widget>>) {
887 unsafe {
888 ffi::gtk_menu_button_set_child(
889 self.to_glib_none().0,
890 child.map(|p| p.as_ref()).to_glib_none().0,
891 );
892 }
893 }
894
895 /// Sets @func to be called when a popup is about to be shown.
896 ///
897 /// @func should use one of
898 ///
899 /// - [`set_popover()`][Self::set_popover()]
900 /// - [`set_menu_model()`][Self::set_menu_model()]
901 ///
902 /// to set a popup for @self.
903 /// If @func is non-[`None`], @self will always be sensitive.
904 ///
905 /// Using this function will not reset the menu widget attached to
906 /// @self. Instead, this can be done manually in @func.
907 /// ## `func`
908 /// function
909 /// to call when a popup is about to be shown, but none has been provided via other means,
910 /// or [`None`] to reset to default behavior
911 /// ## `destroy_notify`
912 /// destroy notify for @user_data
913 #[doc(alias = "gtk_menu_button_set_create_popup_func")]
914 pub fn set_create_popup_func<P: Fn(&MenuButton) + 'static>(&self, func: P) {
915 let func_data: Box_<P> = Box_::new(func);
916 unsafe extern "C" fn func_func<P: Fn(&MenuButton) + 'static>(
917 menu_button: *mut ffi::GtkMenuButton,
918 user_data: glib::ffi::gpointer,
919 ) {
920 let menu_button = from_glib_borrow(menu_button);
921 let callback = &*(user_data as *mut P);
922 (*callback)(&menu_button)
923 }
924 let func = Some(func_func::<P> as _);
925 unsafe extern "C" fn destroy_notify_func<P: Fn(&MenuButton) + 'static>(
926 data: glib::ffi::gpointer,
927 ) {
928 let _callback = Box_::from_raw(data as *mut P);
929 }
930 let destroy_call3 = Some(destroy_notify_func::<P> as _);
931 let super_callback0: Box_<P> = func_data;
932 unsafe {
933 ffi::gtk_menu_button_set_create_popup_func(
934 self.to_glib_none().0,
935 func,
936 Box_::into_raw(super_callback0) as *mut _,
937 destroy_call3,
938 );
939 }
940 }
941
942 /// Sets the direction in which the popup will be popped up.
943 ///
944 /// If the button is automatically populated with an arrow icon,
945 /// its direction will be changed to match.
946 ///
947 /// If the does not fit in the available space in the given direction,
948 /// GTK will its best to keep it inside the screen and fully visible.
949 ///
950 /// If you pass [`ArrowType::None`][crate::ArrowType::None] for a @direction, the popup will behave
951 /// as if you passed [`ArrowType::Down`][crate::ArrowType::Down] (although you won’t see any arrows).
952 /// ## `direction`
953 /// a [`ArrowType`][crate::ArrowType]
954 #[doc(alias = "gtk_menu_button_set_direction")]
955 #[doc(alias = "direction")]
956 pub fn set_direction(&self, direction: ArrowType) {
957 unsafe {
958 ffi::gtk_menu_button_set_direction(self.to_glib_none().0, direction.into_glib());
959 }
960 }
961
962 /// Sets the style of the button.
963 /// ## `has_frame`
964 /// whether the button should have a visible frame
965 #[doc(alias = "gtk_menu_button_set_has_frame")]
966 #[doc(alias = "has-frame")]
967 pub fn set_has_frame(&self, has_frame: bool) {
968 unsafe {
969 ffi::gtk_menu_button_set_has_frame(self.to_glib_none().0, has_frame.into_glib());
970 }
971 }
972
973 /// Sets the name of an icon to show inside the menu button.
974 ///
975 /// Setting icon name resets [`label`][struct@crate::MenuButton#label] and
976 /// [`child`][struct@crate::MenuButton#child].
977 ///
978 /// If [`always-show-arrow`][struct@crate::MenuButton#always-show-arrow] is set to `TRUE` and
979 /// [`direction`][struct@crate::MenuButton#direction] is not `GTK_ARROW_NONE`, a dropdown arrow
980 /// will be shown next to the icon.
981 /// ## `icon_name`
982 /// the icon name
983 #[doc(alias = "gtk_menu_button_set_icon_name")]
984 #[doc(alias = "icon-name")]
985 pub fn set_icon_name(&self, icon_name: &str) {
986 unsafe {
987 ffi::gtk_menu_button_set_icon_name(self.to_glib_none().0, icon_name.to_glib_none().0);
988 }
989 }
990
991 /// Sets the label to show inside the menu button.
992 ///
993 /// Setting a label resets [`icon-name`][struct@crate::MenuButton#icon-name] and
994 /// [`child`][struct@crate::MenuButton#child].
995 ///
996 /// If [`direction`][struct@crate::MenuButton#direction] is not `GTK_ARROW_NONE`, a dropdown
997 /// arrow will be shown next to the label.
998 /// ## `label`
999 /// the label
1000 #[doc(alias = "gtk_menu_button_set_label")]
1001 #[doc(alias = "label")]
1002 pub fn set_label(&self, label: &str) {
1003 unsafe {
1004 ffi::gtk_menu_button_set_label(self.to_glib_none().0, label.to_glib_none().0);
1005 }
1006 }
1007
1008 /// Sets the `GMenuModel` from which the popup will be constructed.
1009 ///
1010 /// If @menu_model is [`None`], the button is disabled.
1011 ///
1012 /// A [`Popover`][crate::Popover] will be created from the menu model with
1013 /// [`PopoverMenu::from_model()`][crate::PopoverMenu::from_model()]. Actions will be connected
1014 /// as documented for this function.
1015 ///
1016 /// If [`popover`][struct@crate::MenuButton#popover] is already set, it will be
1017 /// dissociated from the @self, and the property is set to [`None`].
1018 /// ## `menu_model`
1019 /// a `GMenuModel`, or [`None`] to unset and disable the
1020 /// button
1021 #[doc(alias = "gtk_menu_button_set_menu_model")]
1022 #[doc(alias = "menu-model")]
1023 pub fn set_menu_model(&self, menu_model: Option<&impl IsA<gio::MenuModel>>) {
1024 unsafe {
1025 ffi::gtk_menu_button_set_menu_model(
1026 self.to_glib_none().0,
1027 menu_model.map(|p| p.as_ref()).to_glib_none().0,
1028 );
1029 }
1030 }
1031
1032 /// Sets the [`Popover`][crate::Popover] that will be popped up when the @self is clicked.
1033 ///
1034 /// If @popover is [`None`], the button is disabled.
1035 ///
1036 /// If [`menu-model`][struct@crate::MenuButton#menu-model] is set, the menu model is dissociated
1037 /// from the @self, and the property is set to [`None`].
1038 /// ## `popover`
1039 /// a [`Popover`][crate::Popover], or [`None`] to unset and
1040 /// disable the button
1041 #[doc(alias = "gtk_menu_button_set_popover")]
1042 #[doc(alias = "popover")]
1043 pub fn set_popover(&self, popover: Option<&impl IsA<Popover>>) {
1044 unsafe {
1045 ffi::gtk_menu_button_set_popover(
1046 self.to_glib_none().0,
1047 popover.map(|p| p.as_ref()).to_glib_none().0,
1048 );
1049 }
1050 }
1051
1052 /// Sets whether menu button acts as a primary menu.
1053 ///
1054 /// Primary menus can be opened with the <kbd>F10</kbd> key.
1055 /// ## `primary`
1056 /// whether the menubutton should act as a primary menu
1057 #[cfg(feature = "v4_4")]
1058 #[cfg_attr(docsrs, doc(cfg(feature = "v4_4")))]
1059 #[doc(alias = "gtk_menu_button_set_primary")]
1060 #[doc(alias = "primary")]
1061 pub fn set_primary(&self, primary: bool) {
1062 unsafe {
1063 ffi::gtk_menu_button_set_primary(self.to_glib_none().0, primary.into_glib());
1064 }
1065 }
1066
1067 /// If true, an underline in the text indicates a mnemonic.
1068 /// ## `use_underline`
1069 /// [`true`] if underlines in the text indicate mnemonics
1070 #[doc(alias = "gtk_menu_button_set_use_underline")]
1071 #[doc(alias = "use-underline")]
1072 pub fn set_use_underline(&self, use_underline: bool) {
1073 unsafe {
1074 ffi::gtk_menu_button_set_use_underline(
1075 self.to_glib_none().0,
1076 use_underline.into_glib(),
1077 );
1078 }
1079 }
1080
1081 /// Emitted to when the menu button is activated.
1082 ///
1083 /// The `::activate` signal on [`MenuButton`][crate::MenuButton] is an action signal and
1084 /// emitting it causes the button to pop up its menu.
1085 #[cfg(feature = "v4_4")]
1086 #[cfg_attr(docsrs, doc(cfg(feature = "v4_4")))]
1087 #[doc(alias = "activate")]
1088 pub fn connect_activate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1089 unsafe extern "C" fn activate_trampoline<F: Fn(&MenuButton) + 'static>(
1090 this: *mut ffi::GtkMenuButton,
1091 f: glib::ffi::gpointer,
1092 ) {
1093 let f: &F = &*(f as *const F);
1094 f(&from_glib_borrow(this))
1095 }
1096 unsafe {
1097 let f: Box_<F> = Box_::new(f);
1098 connect_raw(
1099 self.as_ptr() as *mut _,
1100 c"activate".as_ptr() as *const _,
1101 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1102 activate_trampoline::<F> as *const (),
1103 )),
1104 Box_::into_raw(f),
1105 )
1106 }
1107 }
1108
1109 #[cfg(feature = "v4_4")]
1110 #[cfg_attr(docsrs, doc(cfg(feature = "v4_4")))]
1111 pub fn emit_activate(&self) {
1112 self.emit_by_name::<()>("activate", &[]);
1113 }
1114
1115 #[cfg(feature = "v4_10")]
1116 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
1117 #[doc(alias = "active")]
1118 pub fn connect_active_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1119 unsafe extern "C" fn notify_active_trampoline<F: Fn(&MenuButton) + 'static>(
1120 this: *mut ffi::GtkMenuButton,
1121 _param_spec: glib::ffi::gpointer,
1122 f: glib::ffi::gpointer,
1123 ) {
1124 let f: &F = &*(f as *const F);
1125 f(&from_glib_borrow(this))
1126 }
1127 unsafe {
1128 let f: Box_<F> = Box_::new(f);
1129 connect_raw(
1130 self.as_ptr() as *mut _,
1131 c"notify::active".as_ptr() as *const _,
1132 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1133 notify_active_trampoline::<F> as *const (),
1134 )),
1135 Box_::into_raw(f),
1136 )
1137 }
1138 }
1139
1140 #[cfg(feature = "v4_4")]
1141 #[cfg_attr(docsrs, doc(cfg(feature = "v4_4")))]
1142 #[doc(alias = "always-show-arrow")]
1143 pub fn connect_always_show_arrow_notify<F: Fn(&Self) + 'static>(
1144 &self,
1145 f: F,
1146 ) -> SignalHandlerId {
1147 unsafe extern "C" fn notify_always_show_arrow_trampoline<F: Fn(&MenuButton) + 'static>(
1148 this: *mut ffi::GtkMenuButton,
1149 _param_spec: glib::ffi::gpointer,
1150 f: glib::ffi::gpointer,
1151 ) {
1152 let f: &F = &*(f as *const F);
1153 f(&from_glib_borrow(this))
1154 }
1155 unsafe {
1156 let f: Box_<F> = Box_::new(f);
1157 connect_raw(
1158 self.as_ptr() as *mut _,
1159 c"notify::always-show-arrow".as_ptr() as *const _,
1160 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1161 notify_always_show_arrow_trampoline::<F> as *const (),
1162 )),
1163 Box_::into_raw(f),
1164 )
1165 }
1166 }
1167
1168 #[cfg(feature = "v4_12")]
1169 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
1170 #[doc(alias = "can-shrink")]
1171 pub fn connect_can_shrink_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1172 unsafe extern "C" fn notify_can_shrink_trampoline<F: Fn(&MenuButton) + 'static>(
1173 this: *mut ffi::GtkMenuButton,
1174 _param_spec: glib::ffi::gpointer,
1175 f: glib::ffi::gpointer,
1176 ) {
1177 let f: &F = &*(f as *const F);
1178 f(&from_glib_borrow(this))
1179 }
1180 unsafe {
1181 let f: Box_<F> = Box_::new(f);
1182 connect_raw(
1183 self.as_ptr() as *mut _,
1184 c"notify::can-shrink".as_ptr() as *const _,
1185 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1186 notify_can_shrink_trampoline::<F> as *const (),
1187 )),
1188 Box_::into_raw(f),
1189 )
1190 }
1191 }
1192
1193 #[cfg(feature = "v4_6")]
1194 #[cfg_attr(docsrs, doc(cfg(feature = "v4_6")))]
1195 #[doc(alias = "child")]
1196 pub fn connect_child_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1197 unsafe extern "C" fn notify_child_trampoline<F: Fn(&MenuButton) + 'static>(
1198 this: *mut ffi::GtkMenuButton,
1199 _param_spec: glib::ffi::gpointer,
1200 f: glib::ffi::gpointer,
1201 ) {
1202 let f: &F = &*(f as *const F);
1203 f(&from_glib_borrow(this))
1204 }
1205 unsafe {
1206 let f: Box_<F> = Box_::new(f);
1207 connect_raw(
1208 self.as_ptr() as *mut _,
1209 c"notify::child".as_ptr() as *const _,
1210 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1211 notify_child_trampoline::<F> as *const (),
1212 )),
1213 Box_::into_raw(f),
1214 )
1215 }
1216 }
1217
1218 #[doc(alias = "direction")]
1219 pub fn connect_direction_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1220 unsafe extern "C" fn notify_direction_trampoline<F: Fn(&MenuButton) + 'static>(
1221 this: *mut ffi::GtkMenuButton,
1222 _param_spec: glib::ffi::gpointer,
1223 f: glib::ffi::gpointer,
1224 ) {
1225 let f: &F = &*(f as *const F);
1226 f(&from_glib_borrow(this))
1227 }
1228 unsafe {
1229 let f: Box_<F> = Box_::new(f);
1230 connect_raw(
1231 self.as_ptr() as *mut _,
1232 c"notify::direction".as_ptr() as *const _,
1233 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1234 notify_direction_trampoline::<F> as *const (),
1235 )),
1236 Box_::into_raw(f),
1237 )
1238 }
1239 }
1240
1241 #[doc(alias = "has-frame")]
1242 pub fn connect_has_frame_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1243 unsafe extern "C" fn notify_has_frame_trampoline<F: Fn(&MenuButton) + 'static>(
1244 this: *mut ffi::GtkMenuButton,
1245 _param_spec: glib::ffi::gpointer,
1246 f: glib::ffi::gpointer,
1247 ) {
1248 let f: &F = &*(f as *const F);
1249 f(&from_glib_borrow(this))
1250 }
1251 unsafe {
1252 let f: Box_<F> = Box_::new(f);
1253 connect_raw(
1254 self.as_ptr() as *mut _,
1255 c"notify::has-frame".as_ptr() as *const _,
1256 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1257 notify_has_frame_trampoline::<F> as *const (),
1258 )),
1259 Box_::into_raw(f),
1260 )
1261 }
1262 }
1263
1264 #[doc(alias = "icon-name")]
1265 pub fn connect_icon_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1266 unsafe extern "C" fn notify_icon_name_trampoline<F: Fn(&MenuButton) + 'static>(
1267 this: *mut ffi::GtkMenuButton,
1268 _param_spec: glib::ffi::gpointer,
1269 f: glib::ffi::gpointer,
1270 ) {
1271 let f: &F = &*(f as *const F);
1272 f(&from_glib_borrow(this))
1273 }
1274 unsafe {
1275 let f: Box_<F> = Box_::new(f);
1276 connect_raw(
1277 self.as_ptr() as *mut _,
1278 c"notify::icon-name".as_ptr() as *const _,
1279 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1280 notify_icon_name_trampoline::<F> as *const (),
1281 )),
1282 Box_::into_raw(f),
1283 )
1284 }
1285 }
1286
1287 #[doc(alias = "label")]
1288 pub fn connect_label_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1289 unsafe extern "C" fn notify_label_trampoline<F: Fn(&MenuButton) + 'static>(
1290 this: *mut ffi::GtkMenuButton,
1291 _param_spec: glib::ffi::gpointer,
1292 f: glib::ffi::gpointer,
1293 ) {
1294 let f: &F = &*(f as *const F);
1295 f(&from_glib_borrow(this))
1296 }
1297 unsafe {
1298 let f: Box_<F> = Box_::new(f);
1299 connect_raw(
1300 self.as_ptr() as *mut _,
1301 c"notify::label".as_ptr() as *const _,
1302 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1303 notify_label_trampoline::<F> as *const (),
1304 )),
1305 Box_::into_raw(f),
1306 )
1307 }
1308 }
1309
1310 #[doc(alias = "menu-model")]
1311 pub fn connect_menu_model_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1312 unsafe extern "C" fn notify_menu_model_trampoline<F: Fn(&MenuButton) + 'static>(
1313 this: *mut ffi::GtkMenuButton,
1314 _param_spec: glib::ffi::gpointer,
1315 f: glib::ffi::gpointer,
1316 ) {
1317 let f: &F = &*(f as *const F);
1318 f(&from_glib_borrow(this))
1319 }
1320 unsafe {
1321 let f: Box_<F> = Box_::new(f);
1322 connect_raw(
1323 self.as_ptr() as *mut _,
1324 c"notify::menu-model".as_ptr() as *const _,
1325 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1326 notify_menu_model_trampoline::<F> as *const (),
1327 )),
1328 Box_::into_raw(f),
1329 )
1330 }
1331 }
1332
1333 #[doc(alias = "popover")]
1334 pub fn connect_popover_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1335 unsafe extern "C" fn notify_popover_trampoline<F: Fn(&MenuButton) + 'static>(
1336 this: *mut ffi::GtkMenuButton,
1337 _param_spec: glib::ffi::gpointer,
1338 f: glib::ffi::gpointer,
1339 ) {
1340 let f: &F = &*(f as *const F);
1341 f(&from_glib_borrow(this))
1342 }
1343 unsafe {
1344 let f: Box_<F> = Box_::new(f);
1345 connect_raw(
1346 self.as_ptr() as *mut _,
1347 c"notify::popover".as_ptr() as *const _,
1348 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1349 notify_popover_trampoline::<F> as *const (),
1350 )),
1351 Box_::into_raw(f),
1352 )
1353 }
1354 }
1355
1356 #[cfg(feature = "v4_4")]
1357 #[cfg_attr(docsrs, doc(cfg(feature = "v4_4")))]
1358 #[doc(alias = "primary")]
1359 pub fn connect_primary_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1360 unsafe extern "C" fn notify_primary_trampoline<F: Fn(&MenuButton) + 'static>(
1361 this: *mut ffi::GtkMenuButton,
1362 _param_spec: glib::ffi::gpointer,
1363 f: glib::ffi::gpointer,
1364 ) {
1365 let f: &F = &*(f as *const F);
1366 f(&from_glib_borrow(this))
1367 }
1368 unsafe {
1369 let f: Box_<F> = Box_::new(f);
1370 connect_raw(
1371 self.as_ptr() as *mut _,
1372 c"notify::primary".as_ptr() as *const _,
1373 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1374 notify_primary_trampoline::<F> as *const (),
1375 )),
1376 Box_::into_raw(f),
1377 )
1378 }
1379 }
1380
1381 #[doc(alias = "use-underline")]
1382 pub fn connect_use_underline_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1383 unsafe extern "C" fn notify_use_underline_trampoline<F: Fn(&MenuButton) + 'static>(
1384 this: *mut ffi::GtkMenuButton,
1385 _param_spec: glib::ffi::gpointer,
1386 f: glib::ffi::gpointer,
1387 ) {
1388 let f: &F = &*(f as *const F);
1389 f(&from_glib_borrow(this))
1390 }
1391 unsafe {
1392 let f: Box_<F> = Box_::new(f);
1393 connect_raw(
1394 self.as_ptr() as *mut _,
1395 c"notify::use-underline".as_ptr() as *const _,
1396 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1397 notify_use_underline_trampoline::<F> as *const (),
1398 )),
1399 Box_::into_raw(f),
1400 )
1401 }
1402 }
1403}
1404
1405impl Default for MenuButton {
1406 fn default() -> Self {
1407 Self::new()
1408 }
1409}
1410
1411// rustdoc-stripper-ignore-next
1412/// A [builder-pattern] type to construct [`MenuButton`] objects.
1413///
1414/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
1415#[must_use = "The builder must be built to be used"]
1416pub struct MenuButtonBuilder {
1417 builder: glib::object::ObjectBuilder<'static, MenuButton>,
1418}
1419
1420impl MenuButtonBuilder {
1421 fn new() -> Self {
1422 Self {
1423 builder: glib::object::Object::builder(),
1424 }
1425 }
1426
1427 /// Whether the menu button is active.
1428 #[cfg(feature = "v4_10")]
1429 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
1430 pub fn active(self, active: bool) -> Self {
1431 Self {
1432 builder: self.builder.property("active", active),
1433 }
1434 }
1435
1436 /// Whether to show a dropdown arrow even when using an icon or a custom child.
1437 #[cfg(feature = "v4_4")]
1438 #[cfg_attr(docsrs, doc(cfg(feature = "v4_4")))]
1439 pub fn always_show_arrow(self, always_show_arrow: bool) -> Self {
1440 Self {
1441 builder: self
1442 .builder
1443 .property("always-show-arrow", always_show_arrow),
1444 }
1445 }
1446
1447 /// Whether the size of the button can be made smaller than the natural
1448 /// size of its contents.
1449 #[cfg(feature = "v4_12")]
1450 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
1451 pub fn can_shrink(self, can_shrink: bool) -> Self {
1452 Self {
1453 builder: self.builder.property("can-shrink", can_shrink),
1454 }
1455 }
1456
1457 /// The child widget.
1458 #[cfg(feature = "v4_6")]
1459 #[cfg_attr(docsrs, doc(cfg(feature = "v4_6")))]
1460 pub fn child(self, child: &impl IsA<Widget>) -> Self {
1461 Self {
1462 builder: self.builder.property("child", child.clone().upcast()),
1463 }
1464 }
1465
1466 /// The [`ArrowType`][crate::ArrowType] representing the direction in which the
1467 /// menu or popover will be popped out.
1468 pub fn direction(self, direction: ArrowType) -> Self {
1469 Self {
1470 builder: self.builder.property("direction", direction),
1471 }
1472 }
1473
1474 /// Whether the button has a frame.
1475 pub fn has_frame(self, has_frame: bool) -> Self {
1476 Self {
1477 builder: self.builder.property("has-frame", has_frame),
1478 }
1479 }
1480
1481 /// The name of the icon used to automatically populate the button.
1482 pub fn icon_name(self, icon_name: impl Into<glib::GString>) -> Self {
1483 Self {
1484 builder: self.builder.property("icon-name", icon_name.into()),
1485 }
1486 }
1487
1488 /// The label for the button.
1489 pub fn label(self, label: impl Into<glib::GString>) -> Self {
1490 Self {
1491 builder: self.builder.property("label", label.into()),
1492 }
1493 }
1494
1495 /// The `GMenuModel` from which the popup will be created.
1496 ///
1497 /// See [`MenuButton::set_menu_model()`][crate::MenuButton::set_menu_model()] for the interaction
1498 /// with the [`popover`][struct@crate::MenuButton#popover] property.
1499 pub fn menu_model(self, menu_model: &impl IsA<gio::MenuModel>) -> Self {
1500 Self {
1501 builder: self
1502 .builder
1503 .property("menu-model", menu_model.clone().upcast()),
1504 }
1505 }
1506
1507 /// The [`Popover`][crate::Popover] that will be popped up when the button is clicked.
1508 pub fn popover(self, popover: &impl IsA<Popover>) -> Self {
1509 Self {
1510 builder: self.builder.property("popover", popover.clone().upcast()),
1511 }
1512 }
1513
1514 /// Whether the menu button acts as a primary menu.
1515 ///
1516 /// Primary menus can be opened using the <kbd>F10</kbd> key
1517 #[cfg(feature = "v4_4")]
1518 #[cfg_attr(docsrs, doc(cfg(feature = "v4_4")))]
1519 pub fn primary(self, primary: bool) -> Self {
1520 Self {
1521 builder: self.builder.property("primary", primary),
1522 }
1523 }
1524
1525 /// If set an underscore in the text indicates a mnemonic.
1526 pub fn use_underline(self, use_underline: bool) -> Self {
1527 Self {
1528 builder: self.builder.property("use-underline", use_underline),
1529 }
1530 }
1531
1532 /// Whether the widget or any of its descendents can accept
1533 /// the input focus.
1534 ///
1535 /// This property is meant to be set by widget implementations,
1536 /// typically in their instance init function.
1537 pub fn can_focus(self, can_focus: bool) -> Self {
1538 Self {
1539 builder: self.builder.property("can-focus", can_focus),
1540 }
1541 }
1542
1543 /// Whether the widget can receive pointer events.
1544 pub fn can_target(self, can_target: bool) -> Self {
1545 Self {
1546 builder: self.builder.property("can-target", can_target),
1547 }
1548 }
1549
1550 /// A list of css classes applied to this widget.
1551 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
1552 Self {
1553 builder: self.builder.property("css-classes", css_classes.into()),
1554 }
1555 }
1556
1557 /// The name of this widget in the CSS tree.
1558 ///
1559 /// This property is meant to be set by widget implementations,
1560 /// typically in their instance init function.
1561 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
1562 Self {
1563 builder: self.builder.property("css-name", css_name.into()),
1564 }
1565 }
1566
1567 /// The cursor used by @widget.
1568 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
1569 Self {
1570 builder: self.builder.property("cursor", cursor.clone()),
1571 }
1572 }
1573
1574 /// Whether the widget should grab focus when it is clicked with the mouse.
1575 ///
1576 /// This property is only relevant for widgets that can take focus.
1577 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
1578 Self {
1579 builder: self.builder.property("focus-on-click", focus_on_click),
1580 }
1581 }
1582
1583 /// Whether this widget itself will accept the input focus.
1584 pub fn focusable(self, focusable: bool) -> Self {
1585 Self {
1586 builder: self.builder.property("focusable", focusable),
1587 }
1588 }
1589
1590 /// How to distribute horizontal space if widget gets extra space.
1591 pub fn halign(self, halign: Align) -> Self {
1592 Self {
1593 builder: self.builder.property("halign", halign),
1594 }
1595 }
1596
1597 /// Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
1598 /// signal on @widget.
1599 ///
1600 /// A true value indicates that @widget can have a tooltip, in this case
1601 /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
1602 /// determine whether it will provide a tooltip or not.
1603 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
1604 Self {
1605 builder: self.builder.property("has-tooltip", has_tooltip),
1606 }
1607 }
1608
1609 /// Overrides for height request of the widget.
1610 ///
1611 /// If this is -1, the natural request will be used.
1612 pub fn height_request(self, height_request: i32) -> Self {
1613 Self {
1614 builder: self.builder.property("height-request", height_request),
1615 }
1616 }
1617
1618 /// Whether to expand horizontally.
1619 pub fn hexpand(self, hexpand: bool) -> Self {
1620 Self {
1621 builder: self.builder.property("hexpand", hexpand),
1622 }
1623 }
1624
1625 /// Whether to use the `hexpand` property.
1626 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
1627 Self {
1628 builder: self.builder.property("hexpand-set", hexpand_set),
1629 }
1630 }
1631
1632 /// The [`LayoutManager`][crate::LayoutManager] instance to use to compute
1633 /// the preferred size of the widget, and allocate its children.
1634 ///
1635 /// This property is meant to be set by widget implementations,
1636 /// typically in their instance init function.
1637 pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
1638 Self {
1639 builder: self
1640 .builder
1641 .property("layout-manager", layout_manager.clone().upcast()),
1642 }
1643 }
1644
1645 /// Makes this widget act like a modal dialog, with respect to
1646 /// event delivery.
1647 ///
1648 /// Global event controllers will not handle events with targets
1649 /// inside the widget, unless they are set up to ignore propagation
1650 /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
1651 #[cfg(feature = "v4_18")]
1652 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
1653 pub fn limit_events(self, limit_events: bool) -> Self {
1654 Self {
1655 builder: self.builder.property("limit-events", limit_events),
1656 }
1657 }
1658
1659 /// Margin on bottom side of widget.
1660 ///
1661 /// This property adds margin outside of the widget's normal size
1662 /// request, the margin will be added in addition to the size from
1663 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1664 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
1665 Self {
1666 builder: self.builder.property("margin-bottom", margin_bottom),
1667 }
1668 }
1669
1670 /// Margin on end of widget, horizontally.
1671 ///
1672 /// This property supports left-to-right and right-to-left text
1673 /// directions.
1674 ///
1675 /// This property adds margin outside of the widget's normal size
1676 /// request, the margin will be added in addition to the size from
1677 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1678 pub fn margin_end(self, margin_end: i32) -> Self {
1679 Self {
1680 builder: self.builder.property("margin-end", margin_end),
1681 }
1682 }
1683
1684 /// Margin on start of widget, horizontally.
1685 ///
1686 /// This property supports left-to-right and right-to-left text
1687 /// directions.
1688 ///
1689 /// This property adds margin outside of the widget's normal size
1690 /// request, the margin will be added in addition to the size from
1691 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1692 pub fn margin_start(self, margin_start: i32) -> Self {
1693 Self {
1694 builder: self.builder.property("margin-start", margin_start),
1695 }
1696 }
1697
1698 /// Margin on top side of widget.
1699 ///
1700 /// This property adds margin outside of the widget's normal size
1701 /// request, the margin will be added in addition to the size from
1702 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1703 pub fn margin_top(self, margin_top: i32) -> Self {
1704 Self {
1705 builder: self.builder.property("margin-top", margin_top),
1706 }
1707 }
1708
1709 /// The name of the widget.
1710 pub fn name(self, name: impl Into<glib::GString>) -> Self {
1711 Self {
1712 builder: self.builder.property("name", name.into()),
1713 }
1714 }
1715
1716 /// The requested opacity of the widget.
1717 pub fn opacity(self, opacity: f64) -> Self {
1718 Self {
1719 builder: self.builder.property("opacity", opacity),
1720 }
1721 }
1722
1723 /// How content outside the widget's content area is treated.
1724 ///
1725 /// This property is meant to be set by widget implementations,
1726 /// typically in their instance init function.
1727 pub fn overflow(self, overflow: Overflow) -> Self {
1728 Self {
1729 builder: self.builder.property("overflow", overflow),
1730 }
1731 }
1732
1733 /// Whether the widget will receive the default action when it is focused.
1734 pub fn receives_default(self, receives_default: bool) -> Self {
1735 Self {
1736 builder: self.builder.property("receives-default", receives_default),
1737 }
1738 }
1739
1740 /// Whether the widget responds to input.
1741 pub fn sensitive(self, sensitive: bool) -> Self {
1742 Self {
1743 builder: self.builder.property("sensitive", sensitive),
1744 }
1745 }
1746
1747 /// Sets the text of tooltip to be the given string, which is marked up
1748 /// with Pango markup.
1749 ///
1750 /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
1751 ///
1752 /// This is a convenience property which will take care of getting the
1753 /// tooltip shown if the given string is not `NULL`:
1754 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
1755 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
1756 /// the default signal handler.
1757 ///
1758 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
1759 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
1760 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
1761 Self {
1762 builder: self
1763 .builder
1764 .property("tooltip-markup", tooltip_markup.into()),
1765 }
1766 }
1767
1768 /// Sets the text of tooltip to be the given string.
1769 ///
1770 /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
1771 ///
1772 /// This is a convenience property which will take care of getting the
1773 /// tooltip shown if the given string is not `NULL`:
1774 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
1775 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
1776 /// the default signal handler.
1777 ///
1778 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
1779 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
1780 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
1781 Self {
1782 builder: self.builder.property("tooltip-text", tooltip_text.into()),
1783 }
1784 }
1785
1786 /// How to distribute vertical space if widget gets extra space.
1787 pub fn valign(self, valign: Align) -> Self {
1788 Self {
1789 builder: self.builder.property("valign", valign),
1790 }
1791 }
1792
1793 /// Whether to expand vertically.
1794 pub fn vexpand(self, vexpand: bool) -> Self {
1795 Self {
1796 builder: self.builder.property("vexpand", vexpand),
1797 }
1798 }
1799
1800 /// Whether to use the `vexpand` property.
1801 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
1802 Self {
1803 builder: self.builder.property("vexpand-set", vexpand_set),
1804 }
1805 }
1806
1807 /// Whether the widget is visible.
1808 pub fn visible(self, visible: bool) -> Self {
1809 Self {
1810 builder: self.builder.property("visible", visible),
1811 }
1812 }
1813
1814 /// Overrides for width request of the widget.
1815 ///
1816 /// If this is -1, the natural request will be used.
1817 pub fn width_request(self, width_request: i32) -> Self {
1818 Self {
1819 builder: self.builder.property("width-request", width_request),
1820 }
1821 }
1822
1823 /// The accessible role of the given [`Accessible`][crate::Accessible] implementation.
1824 ///
1825 /// The accessible role cannot be changed once set.
1826 pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
1827 Self {
1828 builder: self.builder.property("accessible-role", accessible_role),
1829 }
1830 }
1831
1832 // rustdoc-stripper-ignore-next
1833 /// Build the [`MenuButton`].
1834 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
1835 pub fn build(self) -> MenuButton {
1836 assert_initialized_main_thread!();
1837 self.builder.build()
1838 }
1839}