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