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