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