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