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 disable the button
1040 #[doc(alias = "gtk_menu_button_set_popover")]
1041 #[doc(alias = "popover")]
1042 pub fn set_popover(&self, popover: Option<&impl IsA<Widget>>) {
1043 unsafe {
1044 ffi::gtk_menu_button_set_popover(
1045 self.to_glib_none().0,
1046 popover.map(|p| p.as_ref()).to_glib_none().0,
1047 );
1048 }
1049 }
1050
1051 /// Sets whether menu button acts as a primary menu.
1052 ///
1053 /// Primary menus can be opened with the <kbd>F10</kbd> key.
1054 /// ## `primary`
1055 /// whether the menubutton should act as a primary menu
1056 #[cfg(feature = "v4_4")]
1057 #[cfg_attr(docsrs, doc(cfg(feature = "v4_4")))]
1058 #[doc(alias = "gtk_menu_button_set_primary")]
1059 #[doc(alias = "primary")]
1060 pub fn set_primary(&self, primary: bool) {
1061 unsafe {
1062 ffi::gtk_menu_button_set_primary(self.to_glib_none().0, primary.into_glib());
1063 }
1064 }
1065
1066 /// If true, an underline in the text indicates a mnemonic.
1067 /// ## `use_underline`
1068 /// [`true`] if underlines in the text indicate mnemonics
1069 #[doc(alias = "gtk_menu_button_set_use_underline")]
1070 #[doc(alias = "use-underline")]
1071 pub fn set_use_underline(&self, use_underline: bool) {
1072 unsafe {
1073 ffi::gtk_menu_button_set_use_underline(
1074 self.to_glib_none().0,
1075 use_underline.into_glib(),
1076 );
1077 }
1078 }
1079
1080 /// Emitted to when the menu button is activated.
1081 ///
1082 /// The `::activate` signal on [`MenuButton`][crate::MenuButton] is an action signal and
1083 /// emitting it causes the button to pop up its menu.
1084 #[cfg(feature = "v4_4")]
1085 #[cfg_attr(docsrs, doc(cfg(feature = "v4_4")))]
1086 #[doc(alias = "activate")]
1087 pub fn connect_activate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1088 unsafe extern "C" fn activate_trampoline<F: Fn(&MenuButton) + 'static>(
1089 this: *mut ffi::GtkMenuButton,
1090 f: glib::ffi::gpointer,
1091 ) {
1092 let f: &F = &*(f as *const F);
1093 f(&from_glib_borrow(this))
1094 }
1095 unsafe {
1096 let f: Box_<F> = Box_::new(f);
1097 connect_raw(
1098 self.as_ptr() as *mut _,
1099 c"activate".as_ptr() as *const _,
1100 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1101 activate_trampoline::<F> as *const (),
1102 )),
1103 Box_::into_raw(f),
1104 )
1105 }
1106 }
1107
1108 #[cfg(feature = "v4_4")]
1109 #[cfg_attr(docsrs, doc(cfg(feature = "v4_4")))]
1110 pub fn emit_activate(&self) {
1111 self.emit_by_name::<()>("activate", &[]);
1112 }
1113
1114 #[cfg(feature = "v4_10")]
1115 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
1116 #[doc(alias = "active")]
1117 pub fn connect_active_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1118 unsafe extern "C" fn notify_active_trampoline<F: Fn(&MenuButton) + 'static>(
1119 this: *mut ffi::GtkMenuButton,
1120 _param_spec: glib::ffi::gpointer,
1121 f: glib::ffi::gpointer,
1122 ) {
1123 let f: &F = &*(f as *const F);
1124 f(&from_glib_borrow(this))
1125 }
1126 unsafe {
1127 let f: Box_<F> = Box_::new(f);
1128 connect_raw(
1129 self.as_ptr() as *mut _,
1130 c"notify::active".as_ptr() as *const _,
1131 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1132 notify_active_trampoline::<F> as *const (),
1133 )),
1134 Box_::into_raw(f),
1135 )
1136 }
1137 }
1138
1139 #[cfg(feature = "v4_4")]
1140 #[cfg_attr(docsrs, doc(cfg(feature = "v4_4")))]
1141 #[doc(alias = "always-show-arrow")]
1142 pub fn connect_always_show_arrow_notify<F: Fn(&Self) + 'static>(
1143 &self,
1144 f: F,
1145 ) -> SignalHandlerId {
1146 unsafe extern "C" fn notify_always_show_arrow_trampoline<F: Fn(&MenuButton) + 'static>(
1147 this: *mut ffi::GtkMenuButton,
1148 _param_spec: glib::ffi::gpointer,
1149 f: glib::ffi::gpointer,
1150 ) {
1151 let f: &F = &*(f as *const F);
1152 f(&from_glib_borrow(this))
1153 }
1154 unsafe {
1155 let f: Box_<F> = Box_::new(f);
1156 connect_raw(
1157 self.as_ptr() as *mut _,
1158 c"notify::always-show-arrow".as_ptr() as *const _,
1159 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1160 notify_always_show_arrow_trampoline::<F> as *const (),
1161 )),
1162 Box_::into_raw(f),
1163 )
1164 }
1165 }
1166
1167 #[cfg(feature = "v4_12")]
1168 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
1169 #[doc(alias = "can-shrink")]
1170 pub fn connect_can_shrink_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1171 unsafe extern "C" fn notify_can_shrink_trampoline<F: Fn(&MenuButton) + 'static>(
1172 this: *mut ffi::GtkMenuButton,
1173 _param_spec: glib::ffi::gpointer,
1174 f: glib::ffi::gpointer,
1175 ) {
1176 let f: &F = &*(f as *const F);
1177 f(&from_glib_borrow(this))
1178 }
1179 unsafe {
1180 let f: Box_<F> = Box_::new(f);
1181 connect_raw(
1182 self.as_ptr() as *mut _,
1183 c"notify::can-shrink".as_ptr() as *const _,
1184 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1185 notify_can_shrink_trampoline::<F> as *const (),
1186 )),
1187 Box_::into_raw(f),
1188 )
1189 }
1190 }
1191
1192 #[cfg(feature = "v4_6")]
1193 #[cfg_attr(docsrs, doc(cfg(feature = "v4_6")))]
1194 #[doc(alias = "child")]
1195 pub fn connect_child_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1196 unsafe extern "C" fn notify_child_trampoline<F: Fn(&MenuButton) + 'static>(
1197 this: *mut ffi::GtkMenuButton,
1198 _param_spec: glib::ffi::gpointer,
1199 f: glib::ffi::gpointer,
1200 ) {
1201 let f: &F = &*(f as *const F);
1202 f(&from_glib_borrow(this))
1203 }
1204 unsafe {
1205 let f: Box_<F> = Box_::new(f);
1206 connect_raw(
1207 self.as_ptr() as *mut _,
1208 c"notify::child".as_ptr() as *const _,
1209 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1210 notify_child_trampoline::<F> as *const (),
1211 )),
1212 Box_::into_raw(f),
1213 )
1214 }
1215 }
1216
1217 #[doc(alias = "direction")]
1218 pub fn connect_direction_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1219 unsafe extern "C" fn notify_direction_trampoline<F: Fn(&MenuButton) + 'static>(
1220 this: *mut ffi::GtkMenuButton,
1221 _param_spec: glib::ffi::gpointer,
1222 f: glib::ffi::gpointer,
1223 ) {
1224 let f: &F = &*(f as *const F);
1225 f(&from_glib_borrow(this))
1226 }
1227 unsafe {
1228 let f: Box_<F> = Box_::new(f);
1229 connect_raw(
1230 self.as_ptr() as *mut _,
1231 c"notify::direction".as_ptr() as *const _,
1232 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1233 notify_direction_trampoline::<F> as *const (),
1234 )),
1235 Box_::into_raw(f),
1236 )
1237 }
1238 }
1239
1240 #[doc(alias = "has-frame")]
1241 pub fn connect_has_frame_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1242 unsafe extern "C" fn notify_has_frame_trampoline<F: Fn(&MenuButton) + 'static>(
1243 this: *mut ffi::GtkMenuButton,
1244 _param_spec: glib::ffi::gpointer,
1245 f: glib::ffi::gpointer,
1246 ) {
1247 let f: &F = &*(f as *const F);
1248 f(&from_glib_borrow(this))
1249 }
1250 unsafe {
1251 let f: Box_<F> = Box_::new(f);
1252 connect_raw(
1253 self.as_ptr() as *mut _,
1254 c"notify::has-frame".as_ptr() as *const _,
1255 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1256 notify_has_frame_trampoline::<F> as *const (),
1257 )),
1258 Box_::into_raw(f),
1259 )
1260 }
1261 }
1262
1263 #[doc(alias = "icon-name")]
1264 pub fn connect_icon_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1265 unsafe extern "C" fn notify_icon_name_trampoline<F: Fn(&MenuButton) + 'static>(
1266 this: *mut ffi::GtkMenuButton,
1267 _param_spec: glib::ffi::gpointer,
1268 f: glib::ffi::gpointer,
1269 ) {
1270 let f: &F = &*(f as *const F);
1271 f(&from_glib_borrow(this))
1272 }
1273 unsafe {
1274 let f: Box_<F> = Box_::new(f);
1275 connect_raw(
1276 self.as_ptr() as *mut _,
1277 c"notify::icon-name".as_ptr() as *const _,
1278 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1279 notify_icon_name_trampoline::<F> as *const (),
1280 )),
1281 Box_::into_raw(f),
1282 )
1283 }
1284 }
1285
1286 #[doc(alias = "label")]
1287 pub fn connect_label_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1288 unsafe extern "C" fn notify_label_trampoline<F: Fn(&MenuButton) + 'static>(
1289 this: *mut ffi::GtkMenuButton,
1290 _param_spec: glib::ffi::gpointer,
1291 f: glib::ffi::gpointer,
1292 ) {
1293 let f: &F = &*(f as *const F);
1294 f(&from_glib_borrow(this))
1295 }
1296 unsafe {
1297 let f: Box_<F> = Box_::new(f);
1298 connect_raw(
1299 self.as_ptr() as *mut _,
1300 c"notify::label".as_ptr() as *const _,
1301 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1302 notify_label_trampoline::<F> as *const (),
1303 )),
1304 Box_::into_raw(f),
1305 )
1306 }
1307 }
1308
1309 #[doc(alias = "menu-model")]
1310 pub fn connect_menu_model_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1311 unsafe extern "C" fn notify_menu_model_trampoline<F: Fn(&MenuButton) + 'static>(
1312 this: *mut ffi::GtkMenuButton,
1313 _param_spec: glib::ffi::gpointer,
1314 f: glib::ffi::gpointer,
1315 ) {
1316 let f: &F = &*(f as *const F);
1317 f(&from_glib_borrow(this))
1318 }
1319 unsafe {
1320 let f: Box_<F> = Box_::new(f);
1321 connect_raw(
1322 self.as_ptr() as *mut _,
1323 c"notify::menu-model".as_ptr() as *const _,
1324 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1325 notify_menu_model_trampoline::<F> as *const (),
1326 )),
1327 Box_::into_raw(f),
1328 )
1329 }
1330 }
1331
1332 #[doc(alias = "popover")]
1333 pub fn connect_popover_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1334 unsafe extern "C" fn notify_popover_trampoline<F: Fn(&MenuButton) + 'static>(
1335 this: *mut ffi::GtkMenuButton,
1336 _param_spec: glib::ffi::gpointer,
1337 f: glib::ffi::gpointer,
1338 ) {
1339 let f: &F = &*(f as *const F);
1340 f(&from_glib_borrow(this))
1341 }
1342 unsafe {
1343 let f: Box_<F> = Box_::new(f);
1344 connect_raw(
1345 self.as_ptr() as *mut _,
1346 c"notify::popover".as_ptr() as *const _,
1347 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1348 notify_popover_trampoline::<F> as *const (),
1349 )),
1350 Box_::into_raw(f),
1351 )
1352 }
1353 }
1354
1355 #[cfg(feature = "v4_4")]
1356 #[cfg_attr(docsrs, doc(cfg(feature = "v4_4")))]
1357 #[doc(alias = "primary")]
1358 pub fn connect_primary_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1359 unsafe extern "C" fn notify_primary_trampoline<F: Fn(&MenuButton) + 'static>(
1360 this: *mut ffi::GtkMenuButton,
1361 _param_spec: glib::ffi::gpointer,
1362 f: glib::ffi::gpointer,
1363 ) {
1364 let f: &F = &*(f as *const F);
1365 f(&from_glib_borrow(this))
1366 }
1367 unsafe {
1368 let f: Box_<F> = Box_::new(f);
1369 connect_raw(
1370 self.as_ptr() as *mut _,
1371 c"notify::primary".as_ptr() as *const _,
1372 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1373 notify_primary_trampoline::<F> as *const (),
1374 )),
1375 Box_::into_raw(f),
1376 )
1377 }
1378 }
1379
1380 #[doc(alias = "use-underline")]
1381 pub fn connect_use_underline_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1382 unsafe extern "C" fn notify_use_underline_trampoline<F: Fn(&MenuButton) + 'static>(
1383 this: *mut ffi::GtkMenuButton,
1384 _param_spec: glib::ffi::gpointer,
1385 f: glib::ffi::gpointer,
1386 ) {
1387 let f: &F = &*(f as *const F);
1388 f(&from_glib_borrow(this))
1389 }
1390 unsafe {
1391 let f: Box_<F> = Box_::new(f);
1392 connect_raw(
1393 self.as_ptr() as *mut _,
1394 c"notify::use-underline".as_ptr() as *const _,
1395 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1396 notify_use_underline_trampoline::<F> as *const (),
1397 )),
1398 Box_::into_raw(f),
1399 )
1400 }
1401 }
1402}
1403
1404impl Default for MenuButton {
1405 fn default() -> Self {
1406 Self::new()
1407 }
1408}
1409
1410// rustdoc-stripper-ignore-next
1411/// A [builder-pattern] type to construct [`MenuButton`] objects.
1412///
1413/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
1414#[must_use = "The builder must be built to be used"]
1415pub struct MenuButtonBuilder {
1416 builder: glib::object::ObjectBuilder<'static, MenuButton>,
1417}
1418
1419impl MenuButtonBuilder {
1420 fn new() -> Self {
1421 Self {
1422 builder: glib::object::Object::builder(),
1423 }
1424 }
1425
1426 /// Whether the menu button is active.
1427 #[cfg(feature = "v4_10")]
1428 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
1429 pub fn active(self, active: bool) -> Self {
1430 Self {
1431 builder: self.builder.property("active", active),
1432 }
1433 }
1434
1435 /// Whether to show a dropdown arrow even when using an icon or a custom child.
1436 #[cfg(feature = "v4_4")]
1437 #[cfg_attr(docsrs, doc(cfg(feature = "v4_4")))]
1438 pub fn always_show_arrow(self, always_show_arrow: bool) -> Self {
1439 Self {
1440 builder: self
1441 .builder
1442 .property("always-show-arrow", always_show_arrow),
1443 }
1444 }
1445
1446 /// Whether the size of the button can be made smaller than the natural
1447 /// size of its contents.
1448 #[cfg(feature = "v4_12")]
1449 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
1450 pub fn can_shrink(self, can_shrink: bool) -> Self {
1451 Self {
1452 builder: self.builder.property("can-shrink", can_shrink),
1453 }
1454 }
1455
1456 /// The child widget.
1457 #[cfg(feature = "v4_6")]
1458 #[cfg_attr(docsrs, doc(cfg(feature = "v4_6")))]
1459 pub fn child(self, child: &impl IsA<Widget>) -> Self {
1460 Self {
1461 builder: self.builder.property("child", child.clone().upcast()),
1462 }
1463 }
1464
1465 /// The [`ArrowType`][crate::ArrowType] representing the direction in which the
1466 /// menu or popover will be popped out.
1467 pub fn direction(self, direction: ArrowType) -> Self {
1468 Self {
1469 builder: self.builder.property("direction", direction),
1470 }
1471 }
1472
1473 /// Whether the button has a frame.
1474 pub fn has_frame(self, has_frame: bool) -> Self {
1475 Self {
1476 builder: self.builder.property("has-frame", has_frame),
1477 }
1478 }
1479
1480 /// The name of the icon used to automatically populate the button.
1481 pub fn icon_name(self, icon_name: impl Into<glib::GString>) -> Self {
1482 Self {
1483 builder: self.builder.property("icon-name", icon_name.into()),
1484 }
1485 }
1486
1487 /// The label for the button.
1488 pub fn label(self, label: impl Into<glib::GString>) -> Self {
1489 Self {
1490 builder: self.builder.property("label", label.into()),
1491 }
1492 }
1493
1494 /// The `GMenuModel` from which the popup will be created.
1495 ///
1496 /// See [`MenuButton::set_menu_model()`][crate::MenuButton::set_menu_model()] for the interaction
1497 /// with the [`popover`][struct@crate::MenuButton#popover] property.
1498 pub fn menu_model(self, menu_model: &impl IsA<gio::MenuModel>) -> Self {
1499 Self {
1500 builder: self
1501 .builder
1502 .property("menu-model", menu_model.clone().upcast()),
1503 }
1504 }
1505
1506 /// The [`Popover`][crate::Popover] that will be popped up when the button is clicked.
1507 pub fn popover(self, popover: &impl IsA<Popover>) -> Self {
1508 Self {
1509 builder: self.builder.property("popover", popover.clone().upcast()),
1510 }
1511 }
1512
1513 /// Whether the menu button acts as a primary menu.
1514 ///
1515 /// Primary menus can be opened using the <kbd>F10</kbd> key
1516 #[cfg(feature = "v4_4")]
1517 #[cfg_attr(docsrs, doc(cfg(feature = "v4_4")))]
1518 pub fn primary(self, primary: bool) -> Self {
1519 Self {
1520 builder: self.builder.property("primary", primary),
1521 }
1522 }
1523
1524 /// If set an underscore in the text indicates a mnemonic.
1525 pub fn use_underline(self, use_underline: bool) -> Self {
1526 Self {
1527 builder: self.builder.property("use-underline", use_underline),
1528 }
1529 }
1530
1531 /// Whether the widget or any of its descendents can accept
1532 /// the input focus.
1533 ///
1534 /// This property is meant to be set by widget implementations,
1535 /// typically in their instance init function.
1536 pub fn can_focus(self, can_focus: bool) -> Self {
1537 Self {
1538 builder: self.builder.property("can-focus", can_focus),
1539 }
1540 }
1541
1542 /// Whether the widget can receive pointer events.
1543 pub fn can_target(self, can_target: bool) -> Self {
1544 Self {
1545 builder: self.builder.property("can-target", can_target),
1546 }
1547 }
1548
1549 /// A list of css classes applied to this widget.
1550 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
1551 Self {
1552 builder: self.builder.property("css-classes", css_classes.into()),
1553 }
1554 }
1555
1556 /// The name of this widget in the CSS tree.
1557 ///
1558 /// This property is meant to be set by widget implementations,
1559 /// typically in their instance init function.
1560 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
1561 Self {
1562 builder: self.builder.property("css-name", css_name.into()),
1563 }
1564 }
1565
1566 /// The cursor used by @widget.
1567 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
1568 Self {
1569 builder: self.builder.property("cursor", cursor.clone()),
1570 }
1571 }
1572
1573 /// Whether the widget should grab focus when it is clicked with the mouse.
1574 ///
1575 /// This property is only relevant for widgets that can take focus.
1576 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
1577 Self {
1578 builder: self.builder.property("focus-on-click", focus_on_click),
1579 }
1580 }
1581
1582 /// Whether this widget itself will accept the input focus.
1583 pub fn focusable(self, focusable: bool) -> Self {
1584 Self {
1585 builder: self.builder.property("focusable", focusable),
1586 }
1587 }
1588
1589 /// How to distribute horizontal space if widget gets extra space.
1590 pub fn halign(self, halign: Align) -> Self {
1591 Self {
1592 builder: self.builder.property("halign", halign),
1593 }
1594 }
1595
1596 /// Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
1597 /// signal on @widget.
1598 ///
1599 /// A true value indicates that @widget can have a tooltip, in this case
1600 /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
1601 /// determine whether it will provide a tooltip or not.
1602 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
1603 Self {
1604 builder: self.builder.property("has-tooltip", has_tooltip),
1605 }
1606 }
1607
1608 /// Overrides for height request of the widget.
1609 ///
1610 /// If this is -1, the natural request will be used.
1611 pub fn height_request(self, height_request: i32) -> Self {
1612 Self {
1613 builder: self.builder.property("height-request", height_request),
1614 }
1615 }
1616
1617 /// Whether to expand horizontally.
1618 pub fn hexpand(self, hexpand: bool) -> Self {
1619 Self {
1620 builder: self.builder.property("hexpand", hexpand),
1621 }
1622 }
1623
1624 /// Whether to use the `hexpand` property.
1625 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
1626 Self {
1627 builder: self.builder.property("hexpand-set", hexpand_set),
1628 }
1629 }
1630
1631 /// The [`LayoutManager`][crate::LayoutManager] instance to use to compute
1632 /// the preferred size of the widget, and allocate its children.
1633 ///
1634 /// This property is meant to be set by widget implementations,
1635 /// typically in their instance init function.
1636 pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
1637 Self {
1638 builder: self
1639 .builder
1640 .property("layout-manager", layout_manager.clone().upcast()),
1641 }
1642 }
1643
1644 /// Makes this widget act like a modal dialog, with respect to
1645 /// event delivery.
1646 ///
1647 /// Global event controllers will not handle events with targets
1648 /// inside the widget, unless they are set up to ignore propagation
1649 /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
1650 #[cfg(feature = "v4_18")]
1651 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
1652 pub fn limit_events(self, limit_events: bool) -> Self {
1653 Self {
1654 builder: self.builder.property("limit-events", limit_events),
1655 }
1656 }
1657
1658 /// Margin on bottom side of widget.
1659 ///
1660 /// This property adds margin outside of the widget's normal size
1661 /// request, the margin will be added in addition to the size from
1662 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1663 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
1664 Self {
1665 builder: self.builder.property("margin-bottom", margin_bottom),
1666 }
1667 }
1668
1669 /// Margin on end of widget, horizontally.
1670 ///
1671 /// This property supports left-to-right and right-to-left text
1672 /// directions.
1673 ///
1674 /// This property adds margin outside of the widget's normal size
1675 /// request, the margin will be added in addition to the size from
1676 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1677 pub fn margin_end(self, margin_end: i32) -> Self {
1678 Self {
1679 builder: self.builder.property("margin-end", margin_end),
1680 }
1681 }
1682
1683 /// Margin on start of widget, horizontally.
1684 ///
1685 /// This property supports left-to-right and right-to-left text
1686 /// directions.
1687 ///
1688 /// This property adds margin outside of the widget's normal size
1689 /// request, the margin will be added in addition to the size from
1690 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1691 pub fn margin_start(self, margin_start: i32) -> Self {
1692 Self {
1693 builder: self.builder.property("margin-start", margin_start),
1694 }
1695 }
1696
1697 /// Margin on top side of widget.
1698 ///
1699 /// This property adds margin outside of the widget's normal size
1700 /// request, the margin will be added in addition to the size from
1701 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1702 pub fn margin_top(self, margin_top: i32) -> Self {
1703 Self {
1704 builder: self.builder.property("margin-top", margin_top),
1705 }
1706 }
1707
1708 /// The name of the widget.
1709 pub fn name(self, name: impl Into<glib::GString>) -> Self {
1710 Self {
1711 builder: self.builder.property("name", name.into()),
1712 }
1713 }
1714
1715 /// The requested opacity of the widget.
1716 pub fn opacity(self, opacity: f64) -> Self {
1717 Self {
1718 builder: self.builder.property("opacity", opacity),
1719 }
1720 }
1721
1722 /// How content outside the widget's content area is treated.
1723 ///
1724 /// This property is meant to be set by widget implementations,
1725 /// typically in their instance init function.
1726 pub fn overflow(self, overflow: Overflow) -> Self {
1727 Self {
1728 builder: self.builder.property("overflow", overflow),
1729 }
1730 }
1731
1732 /// Whether the widget will receive the default action when it is focused.
1733 pub fn receives_default(self, receives_default: bool) -> Self {
1734 Self {
1735 builder: self.builder.property("receives-default", receives_default),
1736 }
1737 }
1738
1739 /// Whether the widget responds to input.
1740 pub fn sensitive(self, sensitive: bool) -> Self {
1741 Self {
1742 builder: self.builder.property("sensitive", sensitive),
1743 }
1744 }
1745
1746 /// Sets the text of tooltip to be the given string, which is marked up
1747 /// with Pango markup.
1748 ///
1749 /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
1750 ///
1751 /// This is a convenience property which will take care of getting the
1752 /// tooltip shown if the given string is not `NULL`:
1753 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
1754 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
1755 /// the default signal handler.
1756 ///
1757 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
1758 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
1759 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
1760 Self {
1761 builder: self
1762 .builder
1763 .property("tooltip-markup", tooltip_markup.into()),
1764 }
1765 }
1766
1767 /// Sets the text of tooltip to be the given string.
1768 ///
1769 /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
1770 ///
1771 /// This is a convenience property which will take care of getting the
1772 /// tooltip shown if the given string is not `NULL`:
1773 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
1774 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
1775 /// the default signal handler.
1776 ///
1777 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
1778 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
1779 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
1780 Self {
1781 builder: self.builder.property("tooltip-text", tooltip_text.into()),
1782 }
1783 }
1784
1785 /// How to distribute vertical space if widget gets extra space.
1786 pub fn valign(self, valign: Align) -> Self {
1787 Self {
1788 builder: self.builder.property("valign", valign),
1789 }
1790 }
1791
1792 /// Whether to expand vertically.
1793 pub fn vexpand(self, vexpand: bool) -> Self {
1794 Self {
1795 builder: self.builder.property("vexpand", vexpand),
1796 }
1797 }
1798
1799 /// Whether to use the `vexpand` property.
1800 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
1801 Self {
1802 builder: self.builder.property("vexpand-set", vexpand_set),
1803 }
1804 }
1805
1806 /// Whether the widget is visible.
1807 pub fn visible(self, visible: bool) -> Self {
1808 Self {
1809 builder: self.builder.property("visible", visible),
1810 }
1811 }
1812
1813 /// Overrides for width request of the widget.
1814 ///
1815 /// If this is -1, the natural request will be used.
1816 pub fn width_request(self, width_request: i32) -> Self {
1817 Self {
1818 builder: self.builder.property("width-request", width_request),
1819 }
1820 }
1821
1822 /// The accessible role of the given [`Accessible`][crate::Accessible] implementation.
1823 ///
1824 /// The accessible role cannot be changed once set.
1825 pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
1826 Self {
1827 builder: self.builder.property("accessible-role", accessible_role),
1828 }
1829 }
1830
1831 // rustdoc-stripper-ignore-next
1832 /// Build the [`MenuButton`].
1833 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
1834 pub fn build(self) -> MenuButton {
1835 assert_initialized_main_thread!();
1836 self.builder.build()
1837 }
1838}