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