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