gtk4/auto/popover_menu.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, Buildable, ConstraintTarget, LayoutManager, Native,
7 Overflow, Popover, PopoverMenuFlags, PositionType, ShortcutManager, Widget,
8};
9use glib::{
10 prelude::*,
11 signal::{connect_raw, SignalHandlerId},
12 translate::*,
13};
14use std::boxed::Box as Box_;
15
16glib::wrapper! {
17 /// A subclass of [`Popover`][crate::Popover] that implements menu behavior.
18 ///
19 /// <picture>
20 /// <source srcset="menu-dark.png" media="(prefers-color-scheme: dark)">
21 /// <img alt="An example GtkPopoverMenu" src="menu.png">
22 /// </picture>
23 ///
24 /// [`PopoverMenu`][crate::PopoverMenu] treats its children like menus and allows switching
25 /// between them. It can open submenus as traditional, nested submenus,
26 /// or in a more touch-friendly sliding fashion.
27 /// The property [`flags`][struct@crate::PopoverMenu#flags] controls this appearance.
28 ///
29 /// [`PopoverMenu`][crate::PopoverMenu] is meant to be used primarily with menu models,
30 /// using [`from_model()`][Self::from_model()]. If you need to put
31 /// other widgets such as a [`SpinButton`][crate::SpinButton] or a [`Switch`][crate::Switch] into a popover,
32 /// you can use [`add_child()`][Self::add_child()].
33 ///
34 /// For more dialog-like behavior, use a plain [`Popover`][crate::Popover].
35 ///
36 /// ## Menu models
37 ///
38 /// The XML format understood by [`Builder`][crate::Builder] for `GMenuModel` consists
39 /// of a toplevel `<menu>` element, which contains one or more `<item>`
40 /// elements. Each `<item>` element contains `<attribute>` and `<link>`
41 /// elements with a mandatory name attribute. `<link>` elements have the
42 /// same content model as `<menu>`. Instead of `<link name="submenu">`
43 /// or `<link name="section">`, you can use `<submenu>` or `<section>`
44 /// elements.
45 ///
46 /// ```xml
47 /// <menu id='app-menu'>
48 /// <section>
49 /// <item>
50 /// <attribute name='label' translatable='yes'>_New Window</attribute>
51 /// <attribute name='action'>app.new</attribute>
52 /// </item>
53 /// <item>
54 /// <attribute name='label' translatable='yes'>_About Sunny</attribute>
55 /// <attribute name='action'>app.about</attribute>
56 /// </item>
57 /// <item>
58 /// <attribute name='label' translatable='yes'>_Quit</attribute>
59 /// <attribute name='action'>app.quit</attribute>
60 /// </item>
61 /// </section>
62 /// </menu>
63 /// ```
64 ///
65 /// Attribute values can be translated using gettext, like other [`Builder`][crate::Builder]
66 /// content. `<attribute>` elements can be marked for translation with a
67 /// `translatable="yes"` attribute. It is also possible to specify message
68 /// context and translator comments, using the context and comments attributes.
69 /// To make use of this, the [`Builder`][crate::Builder] must have been given the gettext
70 /// domain to use.
71 ///
72 /// The following attributes are used when constructing menu items:
73 ///
74 /// - "label": a user-visible string to display
75 /// - "use-markup": whether the text in the menu item includes [Pango markup](https://docs.gtk.org/Pango/pango_markup.html)
76 /// - "action": the prefixed name of the action to trigger
77 /// - "target": the parameter to use when activating the action
78 /// - "icon" and "verb-icon": names of icons that may be displayed
79 /// - "submenu-action": name of an action that may be used to track
80 /// whether a submenu is open
81 /// - "hidden-when": a string used to determine when the item will be hidden.
82 /// Possible values include "action-disabled", "action-missing", "macos-menubar".
83 /// This is mainly useful for exported menus, see [`GtkApplicationExt::set_menubar()`][crate::prelude::GtkApplicationExt::set_menubar()].
84 /// - "custom": a string used to match against the ID of a custom child added with
85 /// [`add_child()`][Self::add_child()], [`PopoverMenuBar::add_child()`][crate::PopoverMenuBar::add_child()],
86 /// or in the ui file with `<child type="ID">`.
87 ///
88 /// The following attributes are used when constructing sections:
89 ///
90 /// - "label": a user-visible string to use as section heading
91 /// - "display-hint": a string used to determine special formatting for the section.
92 /// Possible values include "horizontal-buttons", "circular-buttons" and
93 /// "inline-buttons". They all indicate that section should be
94 /// displayed as a horizontal row of buttons.
95 /// - "text-direction": a string used to determine the [`TextDirection`][crate::TextDirection] to use
96 /// when "display-hint" is set to "horizontal-buttons". Possible values
97 /// include "rtl", "ltr", and "none".
98 ///
99 /// The following attributes are used when constructing submenus:
100 ///
101 /// - "label": a user-visible string to display
102 /// - "icon": icon name to display
103 /// - "gtk-macos-special": (macOS only, ignored by others) Add special meaning to a menu
104 /// in the macOS menu bar. See [Using GTK on Apple macOS](osx.html).
105 ///
106 /// Menu items will also show accelerators, which are usually associated
107 /// with actions via [`GtkApplicationExt::set_accels_for_action()`][crate::prelude::GtkApplicationExt::set_accels_for_action()],
108 /// [`WidgetClassExt::add_binding_action()`][crate::subclass::prelude::WidgetClassExt::add_binding_action()] or
109 /// [`ShortcutController::add_shortcut()`][crate::ShortcutController::add_shortcut()].
110 ///
111 /// # Shortcuts and Gestures
112 ///
113 /// [`PopoverMenu`][crate::PopoverMenu] supports the following keyboard shortcuts:
114 ///
115 /// - <kbd>Space</kbd> activates the default widget.
116 ///
117 /// # CSS Nodes
118 ///
119 /// [`PopoverMenu`][crate::PopoverMenu] is just a subclass of [`Popover`][crate::Popover] that adds custom content
120 /// to it, therefore it has the same CSS nodes. It is one of the cases that add
121 /// a `.menu` style class to the main `popover` node.
122 ///
123 /// Menu items have nodes with name `button` and class `.model`. If a section
124 /// display-hint is set, the section gets a node `box` with class `horizontal`
125 /// plus a class with the same text as the display hint. Note that said box may
126 /// not be the direct ancestor of the item `button`s. Thus, for example, to style
127 /// items in an `inline-buttons` section, select `.inline-buttons button.model`.
128 /// Other things that may be of interest to style in menus include `label` nodes.
129 ///
130 /// # Accessibility
131 ///
132 /// [`PopoverMenu`][crate::PopoverMenu] uses the [enum@Gtk.AccessibleRole.menu] role, and its
133 /// items use the [enum@Gtk.AccessibleRole.menu_item],
134 /// [enum@Gtk.AccessibleRole.checkbox] or [enum@Gtk.AccessibleRole.menu_item_radio]
135 /// roles, depending on the action they are connected to.
136 ///
137 /// ## Properties
138 ///
139 ///
140 /// #### `flags`
141 /// The flags that @popover uses to create/display a menu from its model.
142 ///
143 /// If a model is set and the flags change, contents are rebuilt, so if setting
144 /// properties individually, set flags before model to avoid a redundant rebuild.
145 ///
146 /// Readable | Writeable
147 ///
148 ///
149 /// #### `menu-model`
150 /// The model from which the menu is made.
151 ///
152 /// Readable | Writeable
153 ///
154 ///
155 /// #### `visible-submenu`
156 /// The name of the visible submenu.
157 ///
158 /// Readable | Writeable
159 /// <details><summary><h4>Popover</h4></summary>
160 ///
161 ///
162 /// #### `autohide`
163 /// Whether to dismiss the popover on outside clicks.
164 ///
165 /// Readable | Writeable
166 ///
167 ///
168 /// #### `cascade-popdown`
169 /// Whether the popover pops down after a child popover.
170 ///
171 /// This is used to implement the expected behavior of submenus.
172 ///
173 /// Readable | Writeable
174 ///
175 ///
176 /// #### `child`
177 /// The child widget.
178 ///
179 /// Readable | Writeable
180 ///
181 ///
182 /// #### `default-widget`
183 /// The default widget inside the popover.
184 ///
185 /// Readable | Writeable
186 ///
187 ///
188 /// #### `has-arrow`
189 /// Whether to draw an arrow.
190 ///
191 /// Readable | Writeable
192 ///
193 ///
194 /// #### `mnemonics-visible`
195 /// Whether mnemonics are currently visible in this popover.
196 ///
197 /// Readable | Writeable
198 ///
199 ///
200 /// #### `pointing-to`
201 /// Rectangle in the parent widget that the popover points to.
202 ///
203 /// Readable | Writeable
204 ///
205 ///
206 /// #### `position`
207 /// How to place the popover, relative to its parent.
208 ///
209 /// Readable | Writeable
210 /// </details>
211 /// <details><summary><h4>Widget</h4></summary>
212 ///
213 ///
214 /// #### `can-focus`
215 /// Whether the widget or any of its descendents can accept
216 /// the input focus.
217 ///
218 /// This property is meant to be set by widget implementations,
219 /// typically in their instance init function.
220 ///
221 /// Readable | Writeable
222 ///
223 ///
224 /// #### `can-target`
225 /// Whether the widget can receive pointer events.
226 ///
227 /// Readable | Writeable
228 ///
229 ///
230 /// #### `css-classes`
231 /// A list of css classes applied to this widget.
232 ///
233 /// Readable | Writeable
234 ///
235 ///
236 /// #### `css-name`
237 /// The name of this widget in the CSS tree.
238 ///
239 /// This property is meant to be set by widget implementations,
240 /// typically in their instance init function.
241 ///
242 /// Readable | Writeable | Construct Only
243 ///
244 ///
245 /// #### `cursor`
246 /// The cursor used by @widget.
247 ///
248 /// Readable | Writeable
249 ///
250 ///
251 /// #### `focus-on-click`
252 /// Whether the widget should grab focus when it is clicked with the mouse.
253 ///
254 /// This property is only relevant for widgets that can take focus.
255 ///
256 /// Readable | Writeable
257 ///
258 ///
259 /// #### `focusable`
260 /// Whether this widget itself will accept the input focus.
261 ///
262 /// Readable | Writeable
263 ///
264 ///
265 /// #### `halign`
266 /// How to distribute horizontal space if widget gets extra space.
267 ///
268 /// Readable | Writeable
269 ///
270 ///
271 /// #### `has-default`
272 /// Whether the widget is the default widget.
273 ///
274 /// Readable
275 ///
276 ///
277 /// #### `has-focus`
278 /// Whether the widget has the input focus.
279 ///
280 /// Readable
281 ///
282 ///
283 /// #### `has-tooltip`
284 /// Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
285 /// signal on @widget.
286 ///
287 /// A true value indicates that @widget can have a tooltip, in this case
288 /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
289 /// determine whether it will provide a tooltip or not.
290 ///
291 /// Readable | Writeable
292 ///
293 ///
294 /// #### `height-request`
295 /// Overrides for height request of the widget.
296 ///
297 /// If this is -1, the natural request will be used.
298 ///
299 /// Readable | Writeable
300 ///
301 ///
302 /// #### `hexpand`
303 /// Whether to expand horizontally.
304 ///
305 /// Readable | Writeable
306 ///
307 ///
308 /// #### `hexpand-set`
309 /// Whether to use the `hexpand` property.
310 ///
311 /// Readable | Writeable
312 ///
313 ///
314 /// #### `layout-manager`
315 /// The [`LayoutManager`][crate::LayoutManager] instance to use to compute
316 /// the preferred size of the widget, and allocate its children.
317 ///
318 /// This property is meant to be set by widget implementations,
319 /// typically in their instance init function.
320 ///
321 /// Readable | Writeable
322 ///
323 ///
324 /// #### `limit-events`
325 /// Makes this widget act like a modal dialog, with respect to
326 /// event delivery.
327 ///
328 /// Global event controllers will not handle events with targets
329 /// inside the widget, unless they are set up to ignore propagation
330 /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
331 ///
332 /// Readable | Writeable
333 ///
334 ///
335 /// #### `margin-bottom`
336 /// Margin on bottom side of widget.
337 ///
338 /// This property adds margin outside of the widget's normal size
339 /// request, the margin will be added in addition to the size from
340 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
341 ///
342 /// Readable | Writeable
343 ///
344 ///
345 /// #### `margin-end`
346 /// Margin on end of widget, horizontally.
347 ///
348 /// This property supports left-to-right and right-to-left text
349 /// directions.
350 ///
351 /// This property adds margin outside of the widget's normal size
352 /// request, the margin will be added in addition to the size from
353 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
354 ///
355 /// Readable | Writeable
356 ///
357 ///
358 /// #### `margin-start`
359 /// Margin on start of widget, horizontally.
360 ///
361 /// This property supports left-to-right and right-to-left text
362 /// directions.
363 ///
364 /// This property adds margin outside of the widget's normal size
365 /// request, the margin will be added in addition to the size from
366 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
367 ///
368 /// Readable | Writeable
369 ///
370 ///
371 /// #### `margin-top`
372 /// Margin on top side of widget.
373 ///
374 /// This property adds margin outside of the widget's normal size
375 /// request, the margin will be added in addition to the size from
376 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
377 ///
378 /// Readable | Writeable
379 ///
380 ///
381 /// #### `name`
382 /// The name of the widget.
383 ///
384 /// Readable | Writeable
385 ///
386 ///
387 /// #### `opacity`
388 /// The requested opacity of the widget.
389 ///
390 /// Readable | Writeable
391 ///
392 ///
393 /// #### `overflow`
394 /// How content outside the widget's content area is treated.
395 ///
396 /// This property is meant to be set by widget implementations,
397 /// typically in their instance init function.
398 ///
399 /// Readable | Writeable
400 ///
401 ///
402 /// #### `parent`
403 /// The parent widget of this widget.
404 ///
405 /// Readable
406 ///
407 ///
408 /// #### `receives-default`
409 /// Whether the widget will receive the default action when it is focused.
410 ///
411 /// Readable | Writeable
412 ///
413 ///
414 /// #### `root`
415 /// The [`Root`][crate::Root] widget of the widget tree containing this widget.
416 ///
417 /// This will be `NULL` if the widget is not contained in a root widget.
418 ///
419 /// Readable
420 ///
421 ///
422 /// #### `scale-factor`
423 /// The scale factor of the widget.
424 ///
425 /// Readable
426 ///
427 ///
428 /// #### `sensitive`
429 /// Whether the widget responds to input.
430 ///
431 /// Readable | Writeable
432 ///
433 ///
434 /// #### `tooltip-markup`
435 /// Sets the text of tooltip to be the given string, which is marked up
436 /// with Pango markup.
437 ///
438 /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
439 ///
440 /// This is a convenience property which will take care of getting the
441 /// tooltip shown if the given string is not `NULL`:
442 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
443 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
444 /// the default signal handler.
445 ///
446 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
447 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
448 ///
449 /// Readable | Writeable
450 ///
451 ///
452 /// #### `tooltip-text`
453 /// Sets the text of tooltip to be the given string.
454 ///
455 /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
456 ///
457 /// This is a convenience property which will take care of getting the
458 /// tooltip shown if the given string is not `NULL`:
459 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
460 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
461 /// the default signal handler.
462 ///
463 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
464 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
465 ///
466 /// Readable | Writeable
467 ///
468 ///
469 /// #### `valign`
470 /// How to distribute vertical space if widget gets extra space.
471 ///
472 /// Readable | Writeable
473 ///
474 ///
475 /// #### `vexpand`
476 /// Whether to expand vertically.
477 ///
478 /// Readable | Writeable
479 ///
480 ///
481 /// #### `vexpand-set`
482 /// Whether to use the `vexpand` property.
483 ///
484 /// Readable | Writeable
485 ///
486 ///
487 /// #### `visible`
488 /// Whether the widget is visible.
489 ///
490 /// Readable | Writeable
491 ///
492 ///
493 /// #### `width-request`
494 /// Overrides for width request of the widget.
495 ///
496 /// If this is -1, the natural request will be used.
497 ///
498 /// Readable | Writeable
499 /// </details>
500 /// <details><summary><h4>Accessible</h4></summary>
501 ///
502 ///
503 /// #### `accessible-role`
504 /// The accessible role of the given [`Accessible`][crate::Accessible] implementation.
505 ///
506 /// The accessible role cannot be changed once set.
507 ///
508 /// Readable | Writeable
509 /// </details>
510 ///
511 /// # Implements
512 ///
513 /// [`PopoverExt`][trait@crate::prelude::PopoverExt], [`WidgetExt`][trait@crate::prelude::WidgetExt], [`trait@glib::ObjectExt`], [`AccessibleExt`][trait@crate::prelude::AccessibleExt], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`ConstraintTargetExt`][trait@crate::prelude::ConstraintTargetExt], [`NativeExt`][trait@crate::prelude::NativeExt], [`ShortcutManagerExt`][trait@crate::prelude::ShortcutManagerExt], [`WidgetExtManual`][trait@crate::prelude::WidgetExtManual], [`AccessibleExtManual`][trait@crate::prelude::AccessibleExtManual]
514 #[doc(alias = "GtkPopoverMenu")]
515 pub struct PopoverMenu(Object<ffi::GtkPopoverMenu>) @extends Popover, Widget, @implements Accessible, Buildable, ConstraintTarget, Native, ShortcutManager;
516
517 match fn {
518 type_ => || ffi::gtk_popover_menu_get_type(),
519 }
520}
521
522impl PopoverMenu {
523 /// Creates a [`PopoverMenu`][crate::PopoverMenu] and populates it according to @model.
524 ///
525 /// The created buttons are connected to actions found in the
526 /// [`ApplicationWindow`][crate::ApplicationWindow] to which the popover belongs - typically
527 /// by means of being attached to a widget that is contained within
528 /// the [`ApplicationWindow`][crate::ApplicationWindow]s widget hierarchy.
529 ///
530 /// Actions can also be added using [`WidgetExt::insert_action_group()`][crate::prelude::WidgetExt::insert_action_group()]
531 /// on the menus attach widget or on any of its parent widgets.
532 ///
533 /// This function creates menus with sliding submenus.
534 /// See [`from_model_full()`][Self::from_model_full()] for a way
535 /// to control this.
536 /// ## `model`
537 /// a `GMenuModel`
538 ///
539 /// # Returns
540 ///
541 /// the new [`PopoverMenu`][crate::PopoverMenu]
542 #[doc(alias = "gtk_popover_menu_new_from_model")]
543 #[doc(alias = "new_from_model")]
544 pub fn from_model(model: Option<&impl IsA<gio::MenuModel>>) -> PopoverMenu {
545 assert_initialized_main_thread!();
546 unsafe {
547 Widget::from_glib_none(ffi::gtk_popover_menu_new_from_model(
548 model.map(|p| p.as_ref()).to_glib_none().0,
549 ))
550 .unsafe_cast()
551 }
552 }
553
554 /// Creates a [`PopoverMenu`][crate::PopoverMenu] and populates it according to @model.
555 ///
556 /// The created buttons are connected to actions found in the
557 /// action groups that are accessible from the parent widget.
558 /// This includes the [`ApplicationWindow`][crate::ApplicationWindow] to which the popover
559 /// belongs. Actions can also be added using [`WidgetExt::insert_action_group()`][crate::prelude::WidgetExt::insert_action_group()]
560 /// on the parent widget or on any of its parent widgets.
561 /// ## `model`
562 /// a `GMenuModel`
563 /// ## `flags`
564 /// flags that affect how the menu is created
565 ///
566 /// # Returns
567 ///
568 /// the new [`PopoverMenu`][crate::PopoverMenu]
569 #[doc(alias = "gtk_popover_menu_new_from_model_full")]
570 #[doc(alias = "new_from_model_full")]
571 pub fn from_model_full(
572 model: &impl IsA<gio::MenuModel>,
573 flags: PopoverMenuFlags,
574 ) -> PopoverMenu {
575 assert_initialized_main_thread!();
576 unsafe {
577 Widget::from_glib_none(ffi::gtk_popover_menu_new_from_model_full(
578 model.as_ref().to_glib_none().0,
579 flags.into_glib(),
580 ))
581 .unsafe_cast()
582 }
583 }
584
585 // rustdoc-stripper-ignore-next
586 /// Creates a new builder-pattern struct instance to construct [`PopoverMenu`] objects.
587 ///
588 /// This method returns an instance of [`PopoverMenuBuilder`](crate::builders::PopoverMenuBuilder) which can be used to create [`PopoverMenu`] objects.
589 pub fn builder() -> PopoverMenuBuilder {
590 PopoverMenuBuilder::new()
591 }
592
593 /// Adds a custom widget to a generated menu.
594 ///
595 /// For this to work, the menu model of @self must have
596 /// an item with a `custom` attribute that matches @id.
597 /// ## `child`
598 /// the [`Widget`][crate::Widget] to add
599 /// ## `id`
600 /// the ID to insert @child at
601 ///
602 /// # Returns
603 ///
604 /// [`true`] if @id was found and the widget added
605 #[doc(alias = "gtk_popover_menu_add_child")]
606 pub fn add_child(&self, child: &impl IsA<Widget>, id: &str) -> bool {
607 unsafe {
608 from_glib(ffi::gtk_popover_menu_add_child(
609 self.to_glib_none().0,
610 child.as_ref().to_glib_none().0,
611 id.to_glib_none().0,
612 ))
613 }
614 }
615
616 /// Returns the flags that @self uses to create/display a menu from its model.
617 ///
618 /// # Returns
619 ///
620 /// the [`PopoverMenuFlags`][crate::PopoverMenuFlags]
621 #[cfg(feature = "v4_14")]
622 #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
623 #[doc(alias = "gtk_popover_menu_get_flags")]
624 #[doc(alias = "get_flags")]
625 pub fn flags(&self) -> PopoverMenuFlags {
626 unsafe { from_glib(ffi::gtk_popover_menu_get_flags(self.to_glib_none().0)) }
627 }
628
629 /// Returns the menu model used to populate the popover.
630 ///
631 /// # Returns
632 ///
633 /// the menu model of @self
634 #[doc(alias = "gtk_popover_menu_get_menu_model")]
635 #[doc(alias = "get_menu_model")]
636 #[doc(alias = "menu-model")]
637 pub fn menu_model(&self) -> Option<gio::MenuModel> {
638 unsafe { from_glib_none(ffi::gtk_popover_menu_get_menu_model(self.to_glib_none().0)) }
639 }
640
641 /// Removes a widget that has previously been added with
642 /// [`add_child()`][Self::add_child()]()]
643 /// ## `child`
644 /// the [`Widget`][crate::Widget] to remove
645 ///
646 /// # Returns
647 ///
648 /// [`true`] if the widget was removed
649 #[doc(alias = "gtk_popover_menu_remove_child")]
650 pub fn remove_child(&self, child: &impl IsA<Widget>) -> bool {
651 unsafe {
652 from_glib(ffi::gtk_popover_menu_remove_child(
653 self.to_glib_none().0,
654 child.as_ref().to_glib_none().0,
655 ))
656 }
657 }
658
659 /// Sets the flags that @self uses to create/display a menu from its model.
660 ///
661 /// If a model is set and the flags change, contents are rebuilt, so if setting
662 /// properties individually, set flags before model to avoid a redundant rebuild.
663 /// ## `flags`
664 /// a set of [`PopoverMenuFlags`][crate::PopoverMenuFlags]
665 #[cfg(feature = "v4_14")]
666 #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
667 #[doc(alias = "gtk_popover_menu_set_flags")]
668 #[doc(alias = "flags")]
669 pub fn set_flags(&self, flags: PopoverMenuFlags) {
670 unsafe {
671 ffi::gtk_popover_menu_set_flags(self.to_glib_none().0, flags.into_glib());
672 }
673 }
674
675 /// Sets a new menu model on @self.
676 ///
677 /// The existing contents of @self are removed, and
678 /// the @self is populated with new contents according
679 /// to @model.
680 /// ## `model`
681 /// a `GMenuModel`
682 #[doc(alias = "gtk_popover_menu_set_menu_model")]
683 #[doc(alias = "menu-model")]
684 pub fn set_menu_model(&self, model: Option<&impl IsA<gio::MenuModel>>) {
685 unsafe {
686 ffi::gtk_popover_menu_set_menu_model(
687 self.to_glib_none().0,
688 model.map(|p| p.as_ref()).to_glib_none().0,
689 );
690 }
691 }
692
693 /// The name of the visible submenu.
694 #[doc(alias = "visible-submenu")]
695 pub fn visible_submenu(&self) -> Option<glib::GString> {
696 ObjectExt::property(self, "visible-submenu")
697 }
698
699 /// The name of the visible submenu.
700 #[doc(alias = "visible-submenu")]
701 pub fn set_visible_submenu(&self, visible_submenu: Option<&str>) {
702 ObjectExt::set_property(self, "visible-submenu", visible_submenu)
703 }
704
705 #[cfg(feature = "v4_14")]
706 #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
707 #[doc(alias = "flags")]
708 pub fn connect_flags_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
709 unsafe extern "C" fn notify_flags_trampoline<F: Fn(&PopoverMenu) + 'static>(
710 this: *mut ffi::GtkPopoverMenu,
711 _param_spec: glib::ffi::gpointer,
712 f: glib::ffi::gpointer,
713 ) {
714 let f: &F = &*(f as *const F);
715 f(&from_glib_borrow(this))
716 }
717 unsafe {
718 let f: Box_<F> = Box_::new(f);
719 connect_raw(
720 self.as_ptr() as *mut _,
721 c"notify::flags".as_ptr() as *const _,
722 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
723 notify_flags_trampoline::<F> as *const (),
724 )),
725 Box_::into_raw(f),
726 )
727 }
728 }
729
730 #[doc(alias = "menu-model")]
731 pub fn connect_menu_model_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
732 unsafe extern "C" fn notify_menu_model_trampoline<F: Fn(&PopoverMenu) + 'static>(
733 this: *mut ffi::GtkPopoverMenu,
734 _param_spec: glib::ffi::gpointer,
735 f: glib::ffi::gpointer,
736 ) {
737 let f: &F = &*(f as *const F);
738 f(&from_glib_borrow(this))
739 }
740 unsafe {
741 let f: Box_<F> = Box_::new(f);
742 connect_raw(
743 self.as_ptr() as *mut _,
744 c"notify::menu-model".as_ptr() as *const _,
745 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
746 notify_menu_model_trampoline::<F> as *const (),
747 )),
748 Box_::into_raw(f),
749 )
750 }
751 }
752
753 #[doc(alias = "visible-submenu")]
754 pub fn connect_visible_submenu_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
755 unsafe extern "C" fn notify_visible_submenu_trampoline<F: Fn(&PopoverMenu) + 'static>(
756 this: *mut ffi::GtkPopoverMenu,
757 _param_spec: glib::ffi::gpointer,
758 f: glib::ffi::gpointer,
759 ) {
760 let f: &F = &*(f as *const F);
761 f(&from_glib_borrow(this))
762 }
763 unsafe {
764 let f: Box_<F> = Box_::new(f);
765 connect_raw(
766 self.as_ptr() as *mut _,
767 c"notify::visible-submenu".as_ptr() as *const _,
768 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
769 notify_visible_submenu_trampoline::<F> as *const (),
770 )),
771 Box_::into_raw(f),
772 )
773 }
774 }
775}
776
777// rustdoc-stripper-ignore-next
778/// A [builder-pattern] type to construct [`PopoverMenu`] objects.
779///
780/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
781#[must_use = "The builder must be built to be used"]
782pub struct PopoverMenuBuilder {
783 builder: glib::object::ObjectBuilder<'static, PopoverMenu>,
784}
785
786impl PopoverMenuBuilder {
787 fn new() -> Self {
788 Self {
789 builder: glib::object::Object::builder(),
790 }
791 }
792
793 /// The flags that @popover uses to create/display a menu from its model.
794 ///
795 /// If a model is set and the flags change, contents are rebuilt, so if setting
796 /// properties individually, set flags before model to avoid a redundant rebuild.
797 #[cfg(feature = "v4_14")]
798 #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
799 pub fn flags(self, flags: PopoverMenuFlags) -> Self {
800 Self {
801 builder: self.builder.property("flags", flags),
802 }
803 }
804
805 /// The model from which the menu is made.
806 pub fn menu_model(self, menu_model: &impl IsA<gio::MenuModel>) -> Self {
807 Self {
808 builder: self
809 .builder
810 .property("menu-model", menu_model.clone().upcast()),
811 }
812 }
813
814 /// The name of the visible submenu.
815 pub fn visible_submenu(self, visible_submenu: impl Into<glib::GString>) -> Self {
816 Self {
817 builder: self
818 .builder
819 .property("visible-submenu", visible_submenu.into()),
820 }
821 }
822
823 /// Whether to dismiss the popover on outside clicks.
824 pub fn autohide(self, autohide: bool) -> Self {
825 Self {
826 builder: self.builder.property("autohide", autohide),
827 }
828 }
829
830 /// Whether the popover pops down after a child popover.
831 ///
832 /// This is used to implement the expected behavior of submenus.
833 pub fn cascade_popdown(self, cascade_popdown: bool) -> Self {
834 Self {
835 builder: self.builder.property("cascade-popdown", cascade_popdown),
836 }
837 }
838
839 /// The child widget.
840 pub fn child(self, child: &impl IsA<Widget>) -> Self {
841 Self {
842 builder: self.builder.property("child", child.clone().upcast()),
843 }
844 }
845
846 /// The default widget inside the popover.
847 pub fn default_widget(self, default_widget: &impl IsA<Widget>) -> Self {
848 Self {
849 builder: self
850 .builder
851 .property("default-widget", default_widget.clone().upcast()),
852 }
853 }
854
855 /// Whether to draw an arrow.
856 pub fn has_arrow(self, has_arrow: bool) -> Self {
857 Self {
858 builder: self.builder.property("has-arrow", has_arrow),
859 }
860 }
861
862 /// Whether mnemonics are currently visible in this popover.
863 pub fn mnemonics_visible(self, mnemonics_visible: bool) -> Self {
864 Self {
865 builder: self
866 .builder
867 .property("mnemonics-visible", mnemonics_visible),
868 }
869 }
870
871 /// Rectangle in the parent widget that the popover points to.
872 pub fn pointing_to(self, pointing_to: &gdk::Rectangle) -> Self {
873 Self {
874 builder: self.builder.property("pointing-to", pointing_to),
875 }
876 }
877
878 /// How to place the popover, relative to its parent.
879 pub fn position(self, position: PositionType) -> Self {
880 Self {
881 builder: self.builder.property("position", position),
882 }
883 }
884
885 /// Whether the widget or any of its descendents can accept
886 /// the input focus.
887 ///
888 /// This property is meant to be set by widget implementations,
889 /// typically in their instance init function.
890 pub fn can_focus(self, can_focus: bool) -> Self {
891 Self {
892 builder: self.builder.property("can-focus", can_focus),
893 }
894 }
895
896 /// Whether the widget can receive pointer events.
897 pub fn can_target(self, can_target: bool) -> Self {
898 Self {
899 builder: self.builder.property("can-target", can_target),
900 }
901 }
902
903 /// A list of css classes applied to this widget.
904 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
905 Self {
906 builder: self.builder.property("css-classes", css_classes.into()),
907 }
908 }
909
910 /// The name of this widget in the CSS tree.
911 ///
912 /// This property is meant to be set by widget implementations,
913 /// typically in their instance init function.
914 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
915 Self {
916 builder: self.builder.property("css-name", css_name.into()),
917 }
918 }
919
920 /// The cursor used by @widget.
921 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
922 Self {
923 builder: self.builder.property("cursor", cursor.clone()),
924 }
925 }
926
927 /// Whether the widget should grab focus when it is clicked with the mouse.
928 ///
929 /// This property is only relevant for widgets that can take focus.
930 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
931 Self {
932 builder: self.builder.property("focus-on-click", focus_on_click),
933 }
934 }
935
936 /// Whether this widget itself will accept the input focus.
937 pub fn focusable(self, focusable: bool) -> Self {
938 Self {
939 builder: self.builder.property("focusable", focusable),
940 }
941 }
942
943 /// How to distribute horizontal space if widget gets extra space.
944 pub fn halign(self, halign: Align) -> Self {
945 Self {
946 builder: self.builder.property("halign", halign),
947 }
948 }
949
950 /// Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
951 /// signal on @widget.
952 ///
953 /// A true value indicates that @widget can have a tooltip, in this case
954 /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
955 /// determine whether it will provide a tooltip or not.
956 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
957 Self {
958 builder: self.builder.property("has-tooltip", has_tooltip),
959 }
960 }
961
962 /// Overrides for height request of the widget.
963 ///
964 /// If this is -1, the natural request will be used.
965 pub fn height_request(self, height_request: i32) -> Self {
966 Self {
967 builder: self.builder.property("height-request", height_request),
968 }
969 }
970
971 /// Whether to expand horizontally.
972 pub fn hexpand(self, hexpand: bool) -> Self {
973 Self {
974 builder: self.builder.property("hexpand", hexpand),
975 }
976 }
977
978 /// Whether to use the `hexpand` property.
979 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
980 Self {
981 builder: self.builder.property("hexpand-set", hexpand_set),
982 }
983 }
984
985 /// The [`LayoutManager`][crate::LayoutManager] instance to use to compute
986 /// the preferred size of the widget, and allocate its children.
987 ///
988 /// This property is meant to be set by widget implementations,
989 /// typically in their instance init function.
990 pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
991 Self {
992 builder: self
993 .builder
994 .property("layout-manager", layout_manager.clone().upcast()),
995 }
996 }
997
998 /// Makes this widget act like a modal dialog, with respect to
999 /// event delivery.
1000 ///
1001 /// Global event controllers will not handle events with targets
1002 /// inside the widget, unless they are set up to ignore propagation
1003 /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
1004 #[cfg(feature = "v4_18")]
1005 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
1006 pub fn limit_events(self, limit_events: bool) -> Self {
1007 Self {
1008 builder: self.builder.property("limit-events", limit_events),
1009 }
1010 }
1011
1012 /// Margin on bottom side of widget.
1013 ///
1014 /// This property adds margin outside of the widget's normal size
1015 /// request, the margin will be added in addition to the size from
1016 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1017 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
1018 Self {
1019 builder: self.builder.property("margin-bottom", margin_bottom),
1020 }
1021 }
1022
1023 /// Margin on end of widget, horizontally.
1024 ///
1025 /// This property supports left-to-right and right-to-left text
1026 /// directions.
1027 ///
1028 /// This property adds margin outside of the widget's normal size
1029 /// request, the margin will be added in addition to the size from
1030 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1031 pub fn margin_end(self, margin_end: i32) -> Self {
1032 Self {
1033 builder: self.builder.property("margin-end", margin_end),
1034 }
1035 }
1036
1037 /// Margin on start of widget, horizontally.
1038 ///
1039 /// This property supports left-to-right and right-to-left text
1040 /// directions.
1041 ///
1042 /// This property adds margin outside of the widget's normal size
1043 /// request, the margin will be added in addition to the size from
1044 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1045 pub fn margin_start(self, margin_start: i32) -> Self {
1046 Self {
1047 builder: self.builder.property("margin-start", margin_start),
1048 }
1049 }
1050
1051 /// Margin on top side of widget.
1052 ///
1053 /// This property adds margin outside of the widget's normal size
1054 /// request, the margin will be added in addition to the size from
1055 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1056 pub fn margin_top(self, margin_top: i32) -> Self {
1057 Self {
1058 builder: self.builder.property("margin-top", margin_top),
1059 }
1060 }
1061
1062 /// The name of the widget.
1063 pub fn name(self, name: impl Into<glib::GString>) -> Self {
1064 Self {
1065 builder: self.builder.property("name", name.into()),
1066 }
1067 }
1068
1069 /// The requested opacity of the widget.
1070 pub fn opacity(self, opacity: f64) -> Self {
1071 Self {
1072 builder: self.builder.property("opacity", opacity),
1073 }
1074 }
1075
1076 /// How content outside the widget's content area is treated.
1077 ///
1078 /// This property is meant to be set by widget implementations,
1079 /// typically in their instance init function.
1080 pub fn overflow(self, overflow: Overflow) -> Self {
1081 Self {
1082 builder: self.builder.property("overflow", overflow),
1083 }
1084 }
1085
1086 /// Whether the widget will receive the default action when it is focused.
1087 pub fn receives_default(self, receives_default: bool) -> Self {
1088 Self {
1089 builder: self.builder.property("receives-default", receives_default),
1090 }
1091 }
1092
1093 /// Whether the widget responds to input.
1094 pub fn sensitive(self, sensitive: bool) -> Self {
1095 Self {
1096 builder: self.builder.property("sensitive", sensitive),
1097 }
1098 }
1099
1100 /// Sets the text of tooltip to be the given string, which is marked up
1101 /// with Pango markup.
1102 ///
1103 /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
1104 ///
1105 /// This is a convenience property which will take care of getting the
1106 /// tooltip shown if the given string is not `NULL`:
1107 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
1108 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
1109 /// the default signal handler.
1110 ///
1111 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
1112 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
1113 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
1114 Self {
1115 builder: self
1116 .builder
1117 .property("tooltip-markup", tooltip_markup.into()),
1118 }
1119 }
1120
1121 /// Sets the text of tooltip to be the given string.
1122 ///
1123 /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
1124 ///
1125 /// This is a convenience property which will take care of getting the
1126 /// tooltip shown if the given string is not `NULL`:
1127 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
1128 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
1129 /// the default signal handler.
1130 ///
1131 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
1132 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
1133 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
1134 Self {
1135 builder: self.builder.property("tooltip-text", tooltip_text.into()),
1136 }
1137 }
1138
1139 /// How to distribute vertical space if widget gets extra space.
1140 pub fn valign(self, valign: Align) -> Self {
1141 Self {
1142 builder: self.builder.property("valign", valign),
1143 }
1144 }
1145
1146 /// Whether to expand vertically.
1147 pub fn vexpand(self, vexpand: bool) -> Self {
1148 Self {
1149 builder: self.builder.property("vexpand", vexpand),
1150 }
1151 }
1152
1153 /// Whether to use the `vexpand` property.
1154 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
1155 Self {
1156 builder: self.builder.property("vexpand-set", vexpand_set),
1157 }
1158 }
1159
1160 /// Whether the widget is visible.
1161 pub fn visible(self, visible: bool) -> Self {
1162 Self {
1163 builder: self.builder.property("visible", visible),
1164 }
1165 }
1166
1167 /// Overrides for width request of the widget.
1168 ///
1169 /// If this is -1, the natural request will be used.
1170 pub fn width_request(self, width_request: i32) -> Self {
1171 Self {
1172 builder: self.builder.property("width-request", width_request),
1173 }
1174 }
1175
1176 /// The accessible role of the given [`Accessible`][crate::Accessible] implementation.
1177 ///
1178 /// The accessible role cannot be changed once set.
1179 pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
1180 Self {
1181 builder: self.builder.property("accessible-role", accessible_role),
1182 }
1183 }
1184
1185 // rustdoc-stripper-ignore-next
1186 /// Build the [`PopoverMenu`].
1187 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
1188 pub fn build(self) -> PopoverMenu {
1189 assert_initialized_main_thread!();
1190 self.builder.build()
1191 }
1192}