gtk4/auto/drop_down.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_12")]
6#[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
7use crate::StringFilterMatchMode;
8use crate::{
9 ffi, Accessible, AccessibleRole, Align, Buildable, ConstraintTarget, Expression, LayoutManager,
10 ListItemFactory, Overflow, Widget,
11};
12#[cfg(feature = "v4_6")]
13#[cfg_attr(docsrs, doc(cfg(feature = "v4_6")))]
14use glib::object::ObjectType as _;
15use glib::{
16 prelude::*,
17 signal::{connect_raw, SignalHandlerId},
18 translate::*,
19};
20use std::boxed::Box as Box_;
21
22glib::wrapper! {
23 /// [`DropDown`][crate::DropDown] is a widget that allows the user to choose an item
24 /// from a list of options.
25 ///
26 /// 
27 ///
28 /// The [`DropDown`][crate::DropDown] displays the [selected][`selected`][struct@crate::DropDown#selected]
29 /// choice.
30 ///
31 /// The options are given to [`DropDown`][crate::DropDown] in the form of `GListModel`
32 /// and how the individual options are represented is determined by
33 /// a [`ListItemFactory`][crate::ListItemFactory]. The default factory displays simple strings,
34 /// and adds a checkmark to the selected item in the popup.
35 ///
36 /// To set your own factory, use [`set_factory()`][Self::set_factory()]. It is
37 /// possible to use a separate factory for the items in the popup, with
38 /// [`set_list_factory()`][Self::set_list_factory()].
39 ///
40 /// [`DropDown`][crate::DropDown] knows how to obtain strings from the items in a
41 /// [`StringList`][crate::StringList]; for other models, you have to provide an expression
42 /// to find the strings via [`set_expression()`][Self::set_expression()].
43 ///
44 /// [`DropDown`][crate::DropDown] can optionally allow search in the popup, which is
45 /// useful if the list of options is long. To enable the search entry,
46 /// use [`set_enable_search()`][Self::set_enable_search()].
47 ///
48 /// Here is a UI definition example for [`DropDown`][crate::DropDown] with a simple model:
49 ///
50 /// ```xml
51 /// <object class="GtkDropDown">
52 /// <property name="model">
53 /// <object class="GtkStringList">
54 /// <items>
55 /// <item translatable="yes">Factory</item>
56 /// <item translatable="yes">Home</item>
57 /// <item translatable="yes">Subway</item>
58 /// </items>
59 /// </object>
60 /// </property>
61 /// </object>
62 /// ```
63 ///
64 /// If a [`DropDown`][crate::DropDown] is created in this manner, or with
65 /// [`from_strings()`][Self::from_strings()], for instance, the object returned from
66 /// [`selected_item()`][Self::selected_item()] will be a [`StringObject`][crate::StringObject].
67 ///
68 /// To learn more about the list widget framework, see the
69 /// [overview](section-list-widget.html).
70 ///
71 /// ## CSS nodes
72 ///
73 /// [`DropDown`][crate::DropDown] has a single CSS node with name dropdown,
74 /// with the button and popover nodes as children.
75 ///
76 /// ## Accessibility
77 ///
78 /// [`DropDown`][crate::DropDown] uses the [`AccessibleRole::ComboBox`][crate::AccessibleRole::ComboBox] role.
79 ///
80 /// ## Properties
81 ///
82 ///
83 /// #### `enable-search`
84 /// Whether to show a search entry in the popup.
85 ///
86 /// Note that search requires [`expression`][struct@crate::DropDown#expression]
87 /// to be set.
88 ///
89 /// Readable | Writeable
90 ///
91 ///
92 /// #### `expression`
93 /// An expression to evaluate to obtain strings to match against the search
94 /// term.
95 ///
96 /// See [`enable-search`][struct@crate::DropDown#enable-search] for how to enable search.
97 /// If [`factory`][struct@crate::DropDown#factory] is not set, the expression is also
98 /// used to bind strings to labels produced by a default factory.
99 ///
100 /// Readable | Writeable
101 ///
102 ///
103 /// #### `factory`
104 /// Factory for populating list items.
105 ///
106 /// Readable | Writeable
107 ///
108 ///
109 /// #### `header-factory`
110 /// The factory for creating header widgets for the popup.
111 ///
112 /// Readable | Writeable
113 ///
114 ///
115 /// #### `list-factory`
116 /// The factory for populating list items in the popup.
117 ///
118 /// If this is not set, [`factory`][struct@crate::DropDown#factory] is used.
119 ///
120 /// Readable | Writeable
121 ///
122 ///
123 /// #### `model`
124 /// Model for the displayed items.
125 ///
126 /// Readable | Writeable
127 ///
128 ///
129 /// #### `search-match-mode`
130 /// The match mode for the search filter.
131 ///
132 /// Readable | Writeable
133 ///
134 ///
135 /// #### `selected`
136 /// The position of the selected item.
137 ///
138 /// If no item is selected, the property has the value
139 /// `GTK_INVALID_LIST_POSITION`.
140 ///
141 /// Readable | Writeable
142 ///
143 ///
144 /// #### `selected-item`
145 /// The selected item.
146 ///
147 /// Readable
148 ///
149 ///
150 /// #### `show-arrow`
151 /// Whether to show an arrow within the GtkDropDown widget.
152 ///
153 /// Readable | Writeable
154 /// <details><summary><h4>Widget</h4></summary>
155 ///
156 ///
157 /// #### `can-focus`
158 /// Whether the widget or any of its descendents can accept
159 /// the input focus.
160 ///
161 /// This property is meant to be set by widget implementations,
162 /// typically in their instance init function.
163 ///
164 /// Readable | Writeable
165 ///
166 ///
167 /// #### `can-target`
168 /// Whether the widget can receive pointer events.
169 ///
170 /// Readable | Writeable
171 ///
172 ///
173 /// #### `css-classes`
174 /// A list of css classes applied to this widget.
175 ///
176 /// Readable | Writeable
177 ///
178 ///
179 /// #### `css-name`
180 /// The name of this widget in the CSS tree.
181 ///
182 /// This property is meant to be set by widget implementations,
183 /// typically in their instance init function.
184 ///
185 /// Readable | Writeable | Construct Only
186 ///
187 ///
188 /// #### `cursor`
189 /// The cursor used by @widget.
190 ///
191 /// Readable | Writeable
192 ///
193 ///
194 /// #### `focus-on-click`
195 /// Whether the widget should grab focus when it is clicked with the mouse.
196 ///
197 /// This property is only relevant for widgets that can take focus.
198 ///
199 /// Readable | Writeable
200 ///
201 ///
202 /// #### `focusable`
203 /// Whether this widget itself will accept the input focus.
204 ///
205 /// Readable | Writeable
206 ///
207 ///
208 /// #### `halign`
209 /// How to distribute horizontal space if widget gets extra space.
210 ///
211 /// Readable | Writeable
212 ///
213 ///
214 /// #### `has-default`
215 /// Whether the widget is the default widget.
216 ///
217 /// Readable
218 ///
219 ///
220 /// #### `has-focus`
221 /// Whether the widget has the input focus.
222 ///
223 /// Readable
224 ///
225 ///
226 /// #### `has-tooltip`
227 /// Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
228 /// signal on @widget.
229 ///
230 /// A true value indicates that @widget can have a tooltip, in this case
231 /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
232 /// determine whether it will provide a tooltip or not.
233 ///
234 /// Readable | Writeable
235 ///
236 ///
237 /// #### `height-request`
238 /// Overrides for height request of the widget.
239 ///
240 /// If this is -1, the natural request will be used.
241 ///
242 /// Readable | Writeable
243 ///
244 ///
245 /// #### `hexpand`
246 /// Whether to expand horizontally.
247 ///
248 /// Readable | Writeable
249 ///
250 ///
251 /// #### `hexpand-set`
252 /// Whether to use the `hexpand` property.
253 ///
254 /// Readable | Writeable
255 ///
256 ///
257 /// #### `layout-manager`
258 /// The [`LayoutManager`][crate::LayoutManager] instance to use to compute
259 /// the preferred size of the widget, and allocate its children.
260 ///
261 /// This property is meant to be set by widget implementations,
262 /// typically in their instance init function.
263 ///
264 /// Readable | Writeable
265 ///
266 ///
267 /// #### `limit-events`
268 /// Makes this widget act like a modal dialog, with respect to
269 /// event delivery.
270 ///
271 /// Global event controllers will not handle events with targets
272 /// inside the widget, unless they are set up to ignore propagation
273 /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
274 ///
275 /// Readable | Writeable
276 ///
277 ///
278 /// #### `margin-bottom`
279 /// Margin on bottom 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 | Writeable
286 ///
287 ///
288 /// #### `margin-end`
289 /// Margin on end of widget, horizontally.
290 ///
291 /// This property supports left-to-right and right-to-left text
292 /// directions.
293 ///
294 /// This property adds margin outside of the widget's normal size
295 /// request, the margin will be added in addition to the size from
296 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
297 ///
298 /// Readable | Writeable
299 ///
300 ///
301 /// #### `margin-start`
302 /// Margin on start of widget, horizontally.
303 ///
304 /// This property supports left-to-right and right-to-left text
305 /// directions.
306 ///
307 /// This property adds margin outside of the widget's normal size
308 /// request, the margin will be added in addition to the size from
309 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
310 ///
311 /// Readable | Writeable
312 ///
313 ///
314 /// #### `margin-top`
315 /// Margin on top side of widget.
316 ///
317 /// This property adds margin outside of the widget's normal size
318 /// request, the margin will be added in addition to the size from
319 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
320 ///
321 /// Readable | Writeable
322 ///
323 ///
324 /// #### `name`
325 /// The name of the widget.
326 ///
327 /// Readable | Writeable
328 ///
329 ///
330 /// #### `opacity`
331 /// The requested opacity of the widget.
332 ///
333 /// Readable | Writeable
334 ///
335 ///
336 /// #### `overflow`
337 /// How content outside the widget's content area is treated.
338 ///
339 /// This property is meant to be set by widget implementations,
340 /// typically in their instance init function.
341 ///
342 /// Readable | Writeable
343 ///
344 ///
345 /// #### `parent`
346 /// The parent widget of this widget.
347 ///
348 /// Readable
349 ///
350 ///
351 /// #### `receives-default`
352 /// Whether the widget will receive the default action when it is focused.
353 ///
354 /// Readable | Writeable
355 ///
356 ///
357 /// #### `root`
358 /// The [`Root`][crate::Root] widget of the widget tree containing this widget.
359 ///
360 /// This will be `NULL` if the widget is not contained in a root widget.
361 ///
362 /// Readable
363 ///
364 ///
365 /// #### `scale-factor`
366 /// The scale factor of the widget.
367 ///
368 /// Readable
369 ///
370 ///
371 /// #### `sensitive`
372 /// Whether the widget responds to input.
373 ///
374 /// Readable | Writeable
375 ///
376 ///
377 /// #### `tooltip-markup`
378 /// Sets the text of tooltip to be the given string, which is marked up
379 /// with Pango markup.
380 ///
381 /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
382 ///
383 /// This is a convenience property which will take care of getting the
384 /// tooltip shown if the given string is not `NULL`:
385 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
386 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
387 /// the default signal handler.
388 ///
389 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
390 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
391 ///
392 /// Readable | Writeable
393 ///
394 ///
395 /// #### `tooltip-text`
396 /// Sets the text of tooltip to be the given string.
397 ///
398 /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
399 ///
400 /// This is a convenience property which will take care of getting the
401 /// tooltip shown if the given string is not `NULL`:
402 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
403 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
404 /// the default signal handler.
405 ///
406 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
407 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
408 ///
409 /// Readable | Writeable
410 ///
411 ///
412 /// #### `valign`
413 /// How to distribute vertical space if widget gets extra space.
414 ///
415 /// Readable | Writeable
416 ///
417 ///
418 /// #### `vexpand`
419 /// Whether to expand vertically.
420 ///
421 /// Readable | Writeable
422 ///
423 ///
424 /// #### `vexpand-set`
425 /// Whether to use the `vexpand` property.
426 ///
427 /// Readable | Writeable
428 ///
429 ///
430 /// #### `visible`
431 /// Whether the widget is visible.
432 ///
433 /// Readable | Writeable
434 ///
435 ///
436 /// #### `width-request`
437 /// Overrides for width request of the widget.
438 ///
439 /// If this is -1, the natural request will be used.
440 ///
441 /// Readable | Writeable
442 /// </details>
443 /// <details><summary><h4>Accessible</h4></summary>
444 ///
445 ///
446 /// #### `accessible-role`
447 /// The accessible role of the given [`Accessible`][crate::Accessible] implementation.
448 ///
449 /// The accessible role cannot be changed once set.
450 ///
451 /// Readable | Writeable
452 /// </details>
453 ///
454 /// ## Signals
455 ///
456 ///
457 /// #### `activate`
458 /// Emitted to when the drop down is activated.
459 ///
460 /// The `::activate` signal on [`DropDown`][crate::DropDown] is an action signal and
461 /// emitting it causes the drop down to pop up its dropdown.
462 ///
463 /// Action
464 /// <details><summary><h4>Widget</h4></summary>
465 ///
466 ///
467 /// #### `destroy`
468 /// Signals that all holders of a reference to the widget should release
469 /// the reference that they hold.
470 ///
471 /// May result in finalization of the widget if all references are released.
472 ///
473 /// This signal is not suitable for saving widget state.
474 ///
475 ///
476 ///
477 ///
478 /// #### `direction-changed`
479 /// Emitted when the text direction of a widget changes.
480 ///
481 ///
482 ///
483 ///
484 /// #### `hide`
485 /// Emitted when @widget is hidden.
486 ///
487 ///
488 ///
489 ///
490 /// #### `keynav-failed`
491 /// Emitted if keyboard navigation fails.
492 ///
493 /// See [`WidgetExt::keynav_failed()`][crate::prelude::WidgetExt::keynav_failed()] for details.
494 ///
495 ///
496 ///
497 ///
498 /// #### `map`
499 /// Emitted when @widget is going to be mapped.
500 ///
501 /// A widget is mapped when the widget is visible (which is controlled with
502 /// [`visible`][struct@crate::Widget#visible]) and all its parents up to the toplevel widget
503 /// are also visible.
504 ///
505 /// The `::map` signal can be used to determine whether a widget will be drawn,
506 /// for instance it can resume an animation that was stopped during the
507 /// emission of [`unmap`][struct@crate::Widget#unmap].
508 ///
509 ///
510 ///
511 ///
512 /// #### `mnemonic-activate`
513 /// Emitted when a widget is activated via a mnemonic.
514 ///
515 /// The default handler for this signal activates @widget if @group_cycling
516 /// is false, or just makes @widget grab focus if @group_cycling is true.
517 ///
518 ///
519 ///
520 ///
521 /// #### `move-focus`
522 /// Emitted when the focus is moved.
523 ///
524 /// The `::move-focus` signal is a [keybinding signal](class.SignalAction.html).
525 ///
526 /// The default bindings for this signal are <kbd>Tab</kbd> to move forward,
527 /// and <kbd>Shift</kbd>+<kbd>Tab</kbd> to move backward.
528 ///
529 /// Action
530 ///
531 ///
532 /// #### `query-tooltip`
533 /// Emitted when the widget’s tooltip is about to be shown.
534 ///
535 /// This happens when the [`has-tooltip`][struct@crate::Widget#has-tooltip] property
536 /// is true and the hover timeout has expired with the cursor hovering
537 /// above @widget; or emitted when @widget got focus in keyboard mode.
538 ///
539 /// Using the given coordinates, the signal handler should determine
540 /// whether a tooltip should be shown for @widget. If this is the case
541 /// true should be returned, false otherwise. Note that if @keyboard_mode
542 /// is true, the values of @x and @y are undefined and should not be used.
543 ///
544 /// The signal handler is free to manipulate @tooltip with the therefore
545 /// destined function calls.
546 ///
547 ///
548 ///
549 ///
550 /// #### `realize`
551 /// Emitted when @widget is associated with a [`gdk::Surface`][crate::gdk::Surface].
552 ///
553 /// This means that [`WidgetExt::realize()`][crate::prelude::WidgetExt::realize()] has been called
554 /// or the widget has been mapped (that is, it is going to be drawn).
555 ///
556 ///
557 ///
558 ///
559 /// #### `show`
560 /// Emitted when @widget is shown.
561 ///
562 ///
563 ///
564 ///
565 /// #### `state-flags-changed`
566 /// Emitted when the widget state changes.
567 ///
568 /// See [`WidgetExt::state_flags()`][crate::prelude::WidgetExt::state_flags()].
569 ///
570 ///
571 ///
572 ///
573 /// #### `unmap`
574 /// Emitted when @widget is going to be unmapped.
575 ///
576 /// A widget is unmapped when either it or any of its parents up to the
577 /// toplevel widget have been set as hidden.
578 ///
579 /// As `::unmap` indicates that a widget will not be shown any longer,
580 /// it can be used to, for example, stop an animation on the widget.
581 ///
582 ///
583 ///
584 ///
585 /// #### `unrealize`
586 /// Emitted when the [`gdk::Surface`][crate::gdk::Surface] associated with @widget is destroyed.
587 ///
588 /// This means that [`WidgetExt::unrealize()`][crate::prelude::WidgetExt::unrealize()] has been called
589 /// or the widget has been unmapped (that is, it is going to be hidden).
590 ///
591 ///
592 /// </details>
593 ///
594 /// # Implements
595 ///
596 /// [`WidgetExt`][trait@crate::prelude::WidgetExt], [`trait@glib::ObjectExt`], [`AccessibleExt`][trait@crate::prelude::AccessibleExt], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`ConstraintTargetExt`][trait@crate::prelude::ConstraintTargetExt], [`WidgetExtManual`][trait@crate::prelude::WidgetExtManual], [`AccessibleExtManual`][trait@crate::prelude::AccessibleExtManual]
597 #[doc(alias = "GtkDropDown")]
598 pub struct DropDown(Object<ffi::GtkDropDown, ffi::GtkDropDownClass>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget;
599
600 match fn {
601 type_ => || ffi::gtk_drop_down_get_type(),
602 }
603}
604
605impl DropDown {
606 /// Creates a new [`DropDown`][crate::DropDown].
607 ///
608 /// You may want to call [`set_factory()`][Self::set_factory()]
609 /// to set up a way to map its items to widgets.
610 /// ## `model`
611 /// the model to use
612 /// ## `expression`
613 /// the expression to use
614 ///
615 /// # Returns
616 ///
617 /// a new [`DropDown`][crate::DropDown]
618 #[doc(alias = "gtk_drop_down_new")]
619 pub fn new(
620 model: Option<impl IsA<gio::ListModel>>,
621 expression: Option<impl AsRef<Expression>>,
622 ) -> DropDown {
623 assert_initialized_main_thread!();
624 unsafe {
625 Widget::from_glib_none(ffi::gtk_drop_down_new(
626 model.map(|p| p.upcast()).into_glib_ptr(),
627 expression
628 .map(|p| p.as_ref().clone().upcast())
629 .into_glib_ptr(),
630 ))
631 .unsafe_cast()
632 }
633 }
634
635 /// Creates a new [`DropDown`][crate::DropDown] that is populated with
636 /// the strings.
637 /// ## `strings`
638 /// The strings to put in the dropdown
639 ///
640 /// # Returns
641 ///
642 /// a new [`DropDown`][crate::DropDown]
643 #[doc(alias = "gtk_drop_down_new_from_strings")]
644 #[doc(alias = "new_from_strings")]
645 pub fn from_strings(strings: &[&str]) -> DropDown {
646 assert_initialized_main_thread!();
647 unsafe {
648 Widget::from_glib_none(ffi::gtk_drop_down_new_from_strings(
649 strings.to_glib_none().0,
650 ))
651 .unsafe_cast()
652 }
653 }
654
655 // rustdoc-stripper-ignore-next
656 /// Creates a new builder-pattern struct instance to construct [`DropDown`] objects.
657 ///
658 /// This method returns an instance of [`DropDownBuilder`](crate::builders::DropDownBuilder) which can be used to create [`DropDown`] objects.
659 pub fn builder() -> DropDownBuilder {
660 DropDownBuilder::new()
661 }
662
663 /// Returns whether search is enabled.
664 ///
665 /// # Returns
666 ///
667 /// [`true`] if the popup includes a search entry
668 #[doc(alias = "gtk_drop_down_get_enable_search")]
669 #[doc(alias = "get_enable_search")]
670 #[doc(alias = "enable-search")]
671 pub fn enables_search(&self) -> bool {
672 unsafe { from_glib(ffi::gtk_drop_down_get_enable_search(self.to_glib_none().0)) }
673 }
674
675 /// Gets the expression set that is used to obtain strings from items.
676 ///
677 /// See [`set_expression()`][Self::set_expression()].
678 ///
679 /// # Returns
680 ///
681 /// a [`Expression`][crate::Expression]
682 #[doc(alias = "gtk_drop_down_get_expression")]
683 #[doc(alias = "get_expression")]
684 pub fn expression(&self) -> Option<Expression> {
685 unsafe { from_glib_none(ffi::gtk_drop_down_get_expression(self.to_glib_none().0)) }
686 }
687
688 /// Gets the factory that's currently used to populate list items.
689 ///
690 /// The factory returned by this function is always used for the
691 /// item in the button. It is also used for items in the popup
692 /// if [`list-factory`][struct@crate::DropDown#list-factory] is not set.
693 ///
694 /// # Returns
695 ///
696 /// The factory in use
697 #[doc(alias = "gtk_drop_down_get_factory")]
698 #[doc(alias = "get_factory")]
699 pub fn factory(&self) -> Option<ListItemFactory> {
700 unsafe { from_glib_none(ffi::gtk_drop_down_get_factory(self.to_glib_none().0)) }
701 }
702
703 /// Gets the factory that's currently used to create header widgets for the popup.
704 ///
705 /// # Returns
706 ///
707 /// The factory in use
708 #[cfg(feature = "v4_12")]
709 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
710 #[doc(alias = "gtk_drop_down_get_header_factory")]
711 #[doc(alias = "get_header_factory")]
712 #[doc(alias = "header-factory")]
713 pub fn header_factory(&self) -> Option<ListItemFactory> {
714 unsafe { from_glib_none(ffi::gtk_drop_down_get_header_factory(self.to_glib_none().0)) }
715 }
716
717 /// Gets the factory that's currently used to populate list items in the popup.
718 ///
719 /// # Returns
720 ///
721 /// The factory in use
722 #[doc(alias = "gtk_drop_down_get_list_factory")]
723 #[doc(alias = "get_list_factory")]
724 #[doc(alias = "list-factory")]
725 pub fn list_factory(&self) -> Option<ListItemFactory> {
726 unsafe { from_glib_none(ffi::gtk_drop_down_get_list_factory(self.to_glib_none().0)) }
727 }
728
729 /// Gets the model that provides the displayed items.
730 ///
731 /// # Returns
732 ///
733 /// The model in use
734 #[doc(alias = "gtk_drop_down_get_model")]
735 #[doc(alias = "get_model")]
736 pub fn model(&self) -> Option<gio::ListModel> {
737 unsafe { from_glib_none(ffi::gtk_drop_down_get_model(self.to_glib_none().0)) }
738 }
739
740 /// Returns the match mode that the search filter is using.
741 ///
742 /// # Returns
743 ///
744 /// the match mode of the search filter
745 #[cfg(feature = "v4_12")]
746 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
747 #[doc(alias = "gtk_drop_down_get_search_match_mode")]
748 #[doc(alias = "get_search_match_mode")]
749 #[doc(alias = "search-match-mode")]
750 pub fn search_match_mode(&self) -> StringFilterMatchMode {
751 unsafe {
752 from_glib(ffi::gtk_drop_down_get_search_match_mode(
753 self.to_glib_none().0,
754 ))
755 }
756 }
757
758 /// Gets the position of the selected item.
759 ///
760 /// # Returns
761 ///
762 /// the position of the selected item, or `GTK_INVALID_LIST_POSITION`
763 /// if no item is selected
764 #[doc(alias = "gtk_drop_down_get_selected")]
765 #[doc(alias = "get_selected")]
766 pub fn selected(&self) -> u32 {
767 unsafe { ffi::gtk_drop_down_get_selected(self.to_glib_none().0) }
768 }
769
770 /// Gets the selected item. If no item is selected, [`None`] is returned.
771 ///
772 /// # Returns
773 ///
774 /// The selected item
775 #[doc(alias = "gtk_drop_down_get_selected_item")]
776 #[doc(alias = "get_selected_item")]
777 #[doc(alias = "selected-item")]
778 pub fn selected_item(&self) -> Option<glib::Object> {
779 unsafe { from_glib_none(ffi::gtk_drop_down_get_selected_item(self.to_glib_none().0)) }
780 }
781
782 /// Returns whether to show an arrow within the widget.
783 ///
784 /// # Returns
785 ///
786 /// [`true`] if an arrow will be shown.
787 #[cfg(feature = "v4_6")]
788 #[cfg_attr(docsrs, doc(cfg(feature = "v4_6")))]
789 #[doc(alias = "gtk_drop_down_get_show_arrow")]
790 #[doc(alias = "get_show_arrow")]
791 #[doc(alias = "show-arrow")]
792 pub fn shows_arrow(&self) -> bool {
793 unsafe { from_glib(ffi::gtk_drop_down_get_show_arrow(self.to_glib_none().0)) }
794 }
795
796 /// Sets whether a search entry will be shown in the popup that
797 /// allows to search for items in the list.
798 ///
799 /// Note that [`expression`][struct@crate::DropDown#expression] must be set for
800 /// search to work.
801 /// ## `enable_search`
802 /// whether to enable search
803 #[doc(alias = "gtk_drop_down_set_enable_search")]
804 #[doc(alias = "enable-search")]
805 pub fn set_enable_search(&self, enable_search: bool) {
806 unsafe {
807 ffi::gtk_drop_down_set_enable_search(self.to_glib_none().0, enable_search.into_glib());
808 }
809 }
810
811 /// Sets the expression that gets evaluated to obtain strings from items.
812 ///
813 /// This is used for search in the popup. The expression must have
814 /// a value type of `G_TYPE_STRING`.
815 /// ## `expression`
816 /// a [`Expression`][crate::Expression]
817 #[doc(alias = "gtk_drop_down_set_expression")]
818 #[doc(alias = "expression")]
819 pub fn set_expression(&self, expression: Option<impl AsRef<Expression>>) {
820 unsafe {
821 ffi::gtk_drop_down_set_expression(
822 self.to_glib_none().0,
823 expression.as_ref().map(|p| p.as_ref()).to_glib_none().0,
824 );
825 }
826 }
827
828 /// Sets the [`ListItemFactory`][crate::ListItemFactory] to use for populating list items.
829 /// ## `factory`
830 /// the factory to use
831 #[doc(alias = "gtk_drop_down_set_factory")]
832 #[doc(alias = "factory")]
833 pub fn set_factory(&self, factory: Option<&impl IsA<ListItemFactory>>) {
834 unsafe {
835 ffi::gtk_drop_down_set_factory(
836 self.to_glib_none().0,
837 factory.map(|p| p.as_ref()).to_glib_none().0,
838 );
839 }
840 }
841
842 /// Sets the [`ListItemFactory`][crate::ListItemFactory] to use for creating header widgets for the popup.
843 /// ## `factory`
844 /// the factory to use
845 #[cfg(feature = "v4_12")]
846 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
847 #[doc(alias = "gtk_drop_down_set_header_factory")]
848 #[doc(alias = "header-factory")]
849 pub fn set_header_factory(&self, factory: Option<&impl IsA<ListItemFactory>>) {
850 unsafe {
851 ffi::gtk_drop_down_set_header_factory(
852 self.to_glib_none().0,
853 factory.map(|p| p.as_ref()).to_glib_none().0,
854 );
855 }
856 }
857
858 /// Sets the [`ListItemFactory`][crate::ListItemFactory] to use for populating list items in the popup.
859 /// ## `factory`
860 /// the factory to use
861 #[doc(alias = "gtk_drop_down_set_list_factory")]
862 #[doc(alias = "list-factory")]
863 pub fn set_list_factory(&self, factory: Option<&impl IsA<ListItemFactory>>) {
864 unsafe {
865 ffi::gtk_drop_down_set_list_factory(
866 self.to_glib_none().0,
867 factory.map(|p| p.as_ref()).to_glib_none().0,
868 );
869 }
870 }
871
872 /// Sets the `GListModel` to use.
873 /// ## `model`
874 /// the model to use
875 #[doc(alias = "gtk_drop_down_set_model")]
876 #[doc(alias = "model")]
877 pub fn set_model(&self, model: Option<&impl IsA<gio::ListModel>>) {
878 unsafe {
879 ffi::gtk_drop_down_set_model(
880 self.to_glib_none().0,
881 model.map(|p| p.as_ref()).to_glib_none().0,
882 );
883 }
884 }
885
886 /// Sets the match mode for the search filter.
887 /// ## `search_match_mode`
888 /// the new match mode
889 #[cfg(feature = "v4_12")]
890 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
891 #[doc(alias = "gtk_drop_down_set_search_match_mode")]
892 #[doc(alias = "search-match-mode")]
893 pub fn set_search_match_mode(&self, search_match_mode: StringFilterMatchMode) {
894 unsafe {
895 ffi::gtk_drop_down_set_search_match_mode(
896 self.to_glib_none().0,
897 search_match_mode.into_glib(),
898 );
899 }
900 }
901
902 /// Selects the item at the given position.
903 /// ## `position`
904 /// the position of the item to select, or `GTK_INVALID_LIST_POSITION`
905 #[doc(alias = "gtk_drop_down_set_selected")]
906 #[doc(alias = "selected")]
907 pub fn set_selected(&self, position: u32) {
908 unsafe {
909 ffi::gtk_drop_down_set_selected(self.to_glib_none().0, position);
910 }
911 }
912
913 /// Sets whether an arrow will be displayed within the widget.
914 /// ## `show_arrow`
915 /// whether to show an arrow within the widget
916 #[cfg(feature = "v4_6")]
917 #[cfg_attr(docsrs, doc(cfg(feature = "v4_6")))]
918 #[doc(alias = "gtk_drop_down_set_show_arrow")]
919 #[doc(alias = "show-arrow")]
920 pub fn set_show_arrow(&self, show_arrow: bool) {
921 unsafe {
922 ffi::gtk_drop_down_set_show_arrow(self.to_glib_none().0, show_arrow.into_glib());
923 }
924 }
925
926 /// Emitted to when the drop down is activated.
927 ///
928 /// The `::activate` signal on [`DropDown`][crate::DropDown] is an action signal and
929 /// emitting it causes the drop down to pop up its dropdown.
930 #[cfg(feature = "v4_6")]
931 #[cfg_attr(docsrs, doc(cfg(feature = "v4_6")))]
932 #[doc(alias = "activate")]
933 pub fn connect_activate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
934 unsafe extern "C" fn activate_trampoline<F: Fn(&DropDown) + 'static>(
935 this: *mut ffi::GtkDropDown,
936 f: glib::ffi::gpointer,
937 ) {
938 let f: &F = &*(f as *const F);
939 f(&from_glib_borrow(this))
940 }
941 unsafe {
942 let f: Box_<F> = Box_::new(f);
943 connect_raw(
944 self.as_ptr() as *mut _,
945 b"activate\0".as_ptr() as *const _,
946 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
947 activate_trampoline::<F> as *const (),
948 )),
949 Box_::into_raw(f),
950 )
951 }
952 }
953
954 #[cfg(feature = "v4_6")]
955 #[cfg_attr(docsrs, doc(cfg(feature = "v4_6")))]
956 pub fn emit_activate(&self) {
957 self.emit_by_name::<()>("activate", &[]);
958 }
959
960 #[doc(alias = "enable-search")]
961 pub fn connect_enable_search_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
962 unsafe extern "C" fn notify_enable_search_trampoline<F: Fn(&DropDown) + 'static>(
963 this: *mut ffi::GtkDropDown,
964 _param_spec: glib::ffi::gpointer,
965 f: glib::ffi::gpointer,
966 ) {
967 let f: &F = &*(f as *const F);
968 f(&from_glib_borrow(this))
969 }
970 unsafe {
971 let f: Box_<F> = Box_::new(f);
972 connect_raw(
973 self.as_ptr() as *mut _,
974 b"notify::enable-search\0".as_ptr() as *const _,
975 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
976 notify_enable_search_trampoline::<F> as *const (),
977 )),
978 Box_::into_raw(f),
979 )
980 }
981 }
982
983 #[doc(alias = "expression")]
984 pub fn connect_expression_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
985 unsafe extern "C" fn notify_expression_trampoline<F: Fn(&DropDown) + 'static>(
986 this: *mut ffi::GtkDropDown,
987 _param_spec: glib::ffi::gpointer,
988 f: glib::ffi::gpointer,
989 ) {
990 let f: &F = &*(f as *const F);
991 f(&from_glib_borrow(this))
992 }
993 unsafe {
994 let f: Box_<F> = Box_::new(f);
995 connect_raw(
996 self.as_ptr() as *mut _,
997 b"notify::expression\0".as_ptr() as *const _,
998 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
999 notify_expression_trampoline::<F> as *const (),
1000 )),
1001 Box_::into_raw(f),
1002 )
1003 }
1004 }
1005
1006 #[doc(alias = "factory")]
1007 pub fn connect_factory_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1008 unsafe extern "C" fn notify_factory_trampoline<F: Fn(&DropDown) + 'static>(
1009 this: *mut ffi::GtkDropDown,
1010 _param_spec: glib::ffi::gpointer,
1011 f: glib::ffi::gpointer,
1012 ) {
1013 let f: &F = &*(f as *const F);
1014 f(&from_glib_borrow(this))
1015 }
1016 unsafe {
1017 let f: Box_<F> = Box_::new(f);
1018 connect_raw(
1019 self.as_ptr() as *mut _,
1020 b"notify::factory\0".as_ptr() as *const _,
1021 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1022 notify_factory_trampoline::<F> as *const (),
1023 )),
1024 Box_::into_raw(f),
1025 )
1026 }
1027 }
1028
1029 #[cfg(feature = "v4_12")]
1030 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
1031 #[doc(alias = "header-factory")]
1032 pub fn connect_header_factory_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1033 unsafe extern "C" fn notify_header_factory_trampoline<F: Fn(&DropDown) + 'static>(
1034 this: *mut ffi::GtkDropDown,
1035 _param_spec: glib::ffi::gpointer,
1036 f: glib::ffi::gpointer,
1037 ) {
1038 let f: &F = &*(f as *const F);
1039 f(&from_glib_borrow(this))
1040 }
1041 unsafe {
1042 let f: Box_<F> = Box_::new(f);
1043 connect_raw(
1044 self.as_ptr() as *mut _,
1045 b"notify::header-factory\0".as_ptr() as *const _,
1046 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1047 notify_header_factory_trampoline::<F> as *const (),
1048 )),
1049 Box_::into_raw(f),
1050 )
1051 }
1052 }
1053
1054 #[doc(alias = "list-factory")]
1055 pub fn connect_list_factory_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1056 unsafe extern "C" fn notify_list_factory_trampoline<F: Fn(&DropDown) + 'static>(
1057 this: *mut ffi::GtkDropDown,
1058 _param_spec: glib::ffi::gpointer,
1059 f: glib::ffi::gpointer,
1060 ) {
1061 let f: &F = &*(f as *const F);
1062 f(&from_glib_borrow(this))
1063 }
1064 unsafe {
1065 let f: Box_<F> = Box_::new(f);
1066 connect_raw(
1067 self.as_ptr() as *mut _,
1068 b"notify::list-factory\0".as_ptr() as *const _,
1069 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1070 notify_list_factory_trampoline::<F> as *const (),
1071 )),
1072 Box_::into_raw(f),
1073 )
1074 }
1075 }
1076
1077 #[doc(alias = "model")]
1078 pub fn connect_model_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1079 unsafe extern "C" fn notify_model_trampoline<F: Fn(&DropDown) + 'static>(
1080 this: *mut ffi::GtkDropDown,
1081 _param_spec: glib::ffi::gpointer,
1082 f: glib::ffi::gpointer,
1083 ) {
1084 let f: &F = &*(f as *const F);
1085 f(&from_glib_borrow(this))
1086 }
1087 unsafe {
1088 let f: Box_<F> = Box_::new(f);
1089 connect_raw(
1090 self.as_ptr() as *mut _,
1091 b"notify::model\0".as_ptr() as *const _,
1092 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1093 notify_model_trampoline::<F> as *const (),
1094 )),
1095 Box_::into_raw(f),
1096 )
1097 }
1098 }
1099
1100 #[cfg(feature = "v4_12")]
1101 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
1102 #[doc(alias = "search-match-mode")]
1103 pub fn connect_search_match_mode_notify<F: Fn(&Self) + 'static>(
1104 &self,
1105 f: F,
1106 ) -> SignalHandlerId {
1107 unsafe extern "C" fn notify_search_match_mode_trampoline<F: Fn(&DropDown) + 'static>(
1108 this: *mut ffi::GtkDropDown,
1109 _param_spec: glib::ffi::gpointer,
1110 f: glib::ffi::gpointer,
1111 ) {
1112 let f: &F = &*(f as *const F);
1113 f(&from_glib_borrow(this))
1114 }
1115 unsafe {
1116 let f: Box_<F> = Box_::new(f);
1117 connect_raw(
1118 self.as_ptr() as *mut _,
1119 b"notify::search-match-mode\0".as_ptr() as *const _,
1120 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1121 notify_search_match_mode_trampoline::<F> as *const (),
1122 )),
1123 Box_::into_raw(f),
1124 )
1125 }
1126 }
1127
1128 #[doc(alias = "selected")]
1129 pub fn connect_selected_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1130 unsafe extern "C" fn notify_selected_trampoline<F: Fn(&DropDown) + 'static>(
1131 this: *mut ffi::GtkDropDown,
1132 _param_spec: glib::ffi::gpointer,
1133 f: glib::ffi::gpointer,
1134 ) {
1135 let f: &F = &*(f as *const F);
1136 f(&from_glib_borrow(this))
1137 }
1138 unsafe {
1139 let f: Box_<F> = Box_::new(f);
1140 connect_raw(
1141 self.as_ptr() as *mut _,
1142 b"notify::selected\0".as_ptr() as *const _,
1143 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1144 notify_selected_trampoline::<F> as *const (),
1145 )),
1146 Box_::into_raw(f),
1147 )
1148 }
1149 }
1150
1151 #[doc(alias = "selected-item")]
1152 pub fn connect_selected_item_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1153 unsafe extern "C" fn notify_selected_item_trampoline<F: Fn(&DropDown) + 'static>(
1154 this: *mut ffi::GtkDropDown,
1155 _param_spec: glib::ffi::gpointer,
1156 f: glib::ffi::gpointer,
1157 ) {
1158 let f: &F = &*(f as *const F);
1159 f(&from_glib_borrow(this))
1160 }
1161 unsafe {
1162 let f: Box_<F> = Box_::new(f);
1163 connect_raw(
1164 self.as_ptr() as *mut _,
1165 b"notify::selected-item\0".as_ptr() as *const _,
1166 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1167 notify_selected_item_trampoline::<F> as *const (),
1168 )),
1169 Box_::into_raw(f),
1170 )
1171 }
1172 }
1173
1174 #[cfg(feature = "v4_6")]
1175 #[cfg_attr(docsrs, doc(cfg(feature = "v4_6")))]
1176 #[doc(alias = "show-arrow")]
1177 pub fn connect_show_arrow_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1178 unsafe extern "C" fn notify_show_arrow_trampoline<F: Fn(&DropDown) + 'static>(
1179 this: *mut ffi::GtkDropDown,
1180 _param_spec: glib::ffi::gpointer,
1181 f: glib::ffi::gpointer,
1182 ) {
1183 let f: &F = &*(f as *const F);
1184 f(&from_glib_borrow(this))
1185 }
1186 unsafe {
1187 let f: Box_<F> = Box_::new(f);
1188 connect_raw(
1189 self.as_ptr() as *mut _,
1190 b"notify::show-arrow\0".as_ptr() as *const _,
1191 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1192 notify_show_arrow_trampoline::<F> as *const (),
1193 )),
1194 Box_::into_raw(f),
1195 )
1196 }
1197 }
1198}
1199
1200impl Default for DropDown {
1201 fn default() -> Self {
1202 glib::object::Object::new::<Self>()
1203 }
1204}
1205
1206// rustdoc-stripper-ignore-next
1207/// A [builder-pattern] type to construct [`DropDown`] objects.
1208///
1209/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
1210#[must_use = "The builder must be built to be used"]
1211pub struct DropDownBuilder {
1212 builder: glib::object::ObjectBuilder<'static, DropDown>,
1213}
1214
1215impl DropDownBuilder {
1216 fn new() -> Self {
1217 Self {
1218 builder: glib::object::Object::builder(),
1219 }
1220 }
1221
1222 /// Whether to show a search entry in the popup.
1223 ///
1224 /// Note that search requires [`expression`][struct@crate::DropDown#expression]
1225 /// to be set.
1226 pub fn enable_search(self, enable_search: bool) -> Self {
1227 Self {
1228 builder: self.builder.property("enable-search", enable_search),
1229 }
1230 }
1231
1232 /// An expression to evaluate to obtain strings to match against the search
1233 /// term.
1234 ///
1235 /// See [`enable-search`][struct@crate::DropDown#enable-search] for how to enable search.
1236 /// If [`factory`][struct@crate::DropDown#factory] is not set, the expression is also
1237 /// used to bind strings to labels produced by a default factory.
1238 pub fn expression(self, expression: impl AsRef<Expression>) -> Self {
1239 Self {
1240 builder: self
1241 .builder
1242 .property("expression", expression.as_ref().clone()),
1243 }
1244 }
1245
1246 /// Factory for populating list items.
1247 pub fn factory(self, factory: &impl IsA<ListItemFactory>) -> Self {
1248 Self {
1249 builder: self.builder.property("factory", factory.clone().upcast()),
1250 }
1251 }
1252
1253 /// The factory for creating header widgets for the popup.
1254 #[cfg(feature = "v4_12")]
1255 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
1256 pub fn header_factory(self, header_factory: &impl IsA<ListItemFactory>) -> Self {
1257 Self {
1258 builder: self
1259 .builder
1260 .property("header-factory", header_factory.clone().upcast()),
1261 }
1262 }
1263
1264 /// The factory for populating list items in the popup.
1265 ///
1266 /// If this is not set, [`factory`][struct@crate::DropDown#factory] is used.
1267 pub fn list_factory(self, list_factory: &impl IsA<ListItemFactory>) -> Self {
1268 Self {
1269 builder: self
1270 .builder
1271 .property("list-factory", list_factory.clone().upcast()),
1272 }
1273 }
1274
1275 /// Model for the displayed items.
1276 pub fn model(self, model: &impl IsA<gio::ListModel>) -> Self {
1277 Self {
1278 builder: self.builder.property("model", model.clone().upcast()),
1279 }
1280 }
1281
1282 /// The match mode for the search filter.
1283 #[cfg(feature = "v4_12")]
1284 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
1285 pub fn search_match_mode(self, search_match_mode: StringFilterMatchMode) -> Self {
1286 Self {
1287 builder: self
1288 .builder
1289 .property("search-match-mode", search_match_mode),
1290 }
1291 }
1292
1293 /// The position of the selected item.
1294 ///
1295 /// If no item is selected, the property has the value
1296 /// `GTK_INVALID_LIST_POSITION`.
1297 pub fn selected(self, selected: u32) -> Self {
1298 Self {
1299 builder: self.builder.property("selected", selected),
1300 }
1301 }
1302
1303 /// Whether to show an arrow within the GtkDropDown widget.
1304 #[cfg(feature = "v4_6")]
1305 #[cfg_attr(docsrs, doc(cfg(feature = "v4_6")))]
1306 pub fn show_arrow(self, show_arrow: bool) -> Self {
1307 Self {
1308 builder: self.builder.property("show-arrow", show_arrow),
1309 }
1310 }
1311
1312 /// Whether the widget or any of its descendents can accept
1313 /// the input focus.
1314 ///
1315 /// This property is meant to be set by widget implementations,
1316 /// typically in their instance init function.
1317 pub fn can_focus(self, can_focus: bool) -> Self {
1318 Self {
1319 builder: self.builder.property("can-focus", can_focus),
1320 }
1321 }
1322
1323 /// Whether the widget can receive pointer events.
1324 pub fn can_target(self, can_target: bool) -> Self {
1325 Self {
1326 builder: self.builder.property("can-target", can_target),
1327 }
1328 }
1329
1330 /// A list of css classes applied to this widget.
1331 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
1332 Self {
1333 builder: self.builder.property("css-classes", css_classes.into()),
1334 }
1335 }
1336
1337 /// The name of this widget in the CSS tree.
1338 ///
1339 /// This property is meant to be set by widget implementations,
1340 /// typically in their instance init function.
1341 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
1342 Self {
1343 builder: self.builder.property("css-name", css_name.into()),
1344 }
1345 }
1346
1347 /// The cursor used by @widget.
1348 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
1349 Self {
1350 builder: self.builder.property("cursor", cursor.clone()),
1351 }
1352 }
1353
1354 /// Whether the widget should grab focus when it is clicked with the mouse.
1355 ///
1356 /// This property is only relevant for widgets that can take focus.
1357 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
1358 Self {
1359 builder: self.builder.property("focus-on-click", focus_on_click),
1360 }
1361 }
1362
1363 /// Whether this widget itself will accept the input focus.
1364 pub fn focusable(self, focusable: bool) -> Self {
1365 Self {
1366 builder: self.builder.property("focusable", focusable),
1367 }
1368 }
1369
1370 /// How to distribute horizontal space if widget gets extra space.
1371 pub fn halign(self, halign: Align) -> Self {
1372 Self {
1373 builder: self.builder.property("halign", halign),
1374 }
1375 }
1376
1377 /// Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
1378 /// signal on @widget.
1379 ///
1380 /// A true value indicates that @widget can have a tooltip, in this case
1381 /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
1382 /// determine whether it will provide a tooltip or not.
1383 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
1384 Self {
1385 builder: self.builder.property("has-tooltip", has_tooltip),
1386 }
1387 }
1388
1389 /// Overrides for height request of the widget.
1390 ///
1391 /// If this is -1, the natural request will be used.
1392 pub fn height_request(self, height_request: i32) -> Self {
1393 Self {
1394 builder: self.builder.property("height-request", height_request),
1395 }
1396 }
1397
1398 /// Whether to expand horizontally.
1399 pub fn hexpand(self, hexpand: bool) -> Self {
1400 Self {
1401 builder: self.builder.property("hexpand", hexpand),
1402 }
1403 }
1404
1405 /// Whether to use the `hexpand` property.
1406 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
1407 Self {
1408 builder: self.builder.property("hexpand-set", hexpand_set),
1409 }
1410 }
1411
1412 /// The [`LayoutManager`][crate::LayoutManager] instance to use to compute
1413 /// the preferred size of the widget, and allocate its children.
1414 ///
1415 /// This property is meant to be set by widget implementations,
1416 /// typically in their instance init function.
1417 pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
1418 Self {
1419 builder: self
1420 .builder
1421 .property("layout-manager", layout_manager.clone().upcast()),
1422 }
1423 }
1424
1425 /// Makes this widget act like a modal dialog, with respect to
1426 /// event delivery.
1427 ///
1428 /// Global event controllers will not handle events with targets
1429 /// inside the widget, unless they are set up to ignore propagation
1430 /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
1431 #[cfg(feature = "v4_18")]
1432 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
1433 pub fn limit_events(self, limit_events: bool) -> Self {
1434 Self {
1435 builder: self.builder.property("limit-events", limit_events),
1436 }
1437 }
1438
1439 /// Margin on bottom side of widget.
1440 ///
1441 /// This property adds margin outside of the widget's normal size
1442 /// request, the margin will be added in addition to the size from
1443 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1444 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
1445 Self {
1446 builder: self.builder.property("margin-bottom", margin_bottom),
1447 }
1448 }
1449
1450 /// Margin on end of widget, horizontally.
1451 ///
1452 /// This property supports left-to-right and right-to-left text
1453 /// directions.
1454 ///
1455 /// This property adds margin outside of the widget's normal size
1456 /// request, the margin will be added in addition to the size from
1457 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1458 pub fn margin_end(self, margin_end: i32) -> Self {
1459 Self {
1460 builder: self.builder.property("margin-end", margin_end),
1461 }
1462 }
1463
1464 /// Margin on start of widget, horizontally.
1465 ///
1466 /// This property supports left-to-right and right-to-left text
1467 /// directions.
1468 ///
1469 /// This property adds margin outside of the widget's normal size
1470 /// request, the margin will be added in addition to the size from
1471 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1472 pub fn margin_start(self, margin_start: i32) -> Self {
1473 Self {
1474 builder: self.builder.property("margin-start", margin_start),
1475 }
1476 }
1477
1478 /// Margin on top side of widget.
1479 ///
1480 /// This property adds margin outside of the widget's normal size
1481 /// request, the margin will be added in addition to the size from
1482 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1483 pub fn margin_top(self, margin_top: i32) -> Self {
1484 Self {
1485 builder: self.builder.property("margin-top", margin_top),
1486 }
1487 }
1488
1489 /// The name of the widget.
1490 pub fn name(self, name: impl Into<glib::GString>) -> Self {
1491 Self {
1492 builder: self.builder.property("name", name.into()),
1493 }
1494 }
1495
1496 /// The requested opacity of the widget.
1497 pub fn opacity(self, opacity: f64) -> Self {
1498 Self {
1499 builder: self.builder.property("opacity", opacity),
1500 }
1501 }
1502
1503 /// How content outside the widget's content area is treated.
1504 ///
1505 /// This property is meant to be set by widget implementations,
1506 /// typically in their instance init function.
1507 pub fn overflow(self, overflow: Overflow) -> Self {
1508 Self {
1509 builder: self.builder.property("overflow", overflow),
1510 }
1511 }
1512
1513 /// Whether the widget will receive the default action when it is focused.
1514 pub fn receives_default(self, receives_default: bool) -> Self {
1515 Self {
1516 builder: self.builder.property("receives-default", receives_default),
1517 }
1518 }
1519
1520 /// Whether the widget responds to input.
1521 pub fn sensitive(self, sensitive: bool) -> Self {
1522 Self {
1523 builder: self.builder.property("sensitive", sensitive),
1524 }
1525 }
1526
1527 /// Sets the text of tooltip to be the given string, which is marked up
1528 /// with Pango markup.
1529 ///
1530 /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
1531 ///
1532 /// This is a convenience property which will take care of getting the
1533 /// tooltip shown if the given string is not `NULL`:
1534 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
1535 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
1536 /// the default signal handler.
1537 ///
1538 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
1539 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
1540 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
1541 Self {
1542 builder: self
1543 .builder
1544 .property("tooltip-markup", tooltip_markup.into()),
1545 }
1546 }
1547
1548 /// Sets the text of tooltip to be the given string.
1549 ///
1550 /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
1551 ///
1552 /// This is a convenience property which will take care of getting the
1553 /// tooltip shown if the given string is not `NULL`:
1554 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
1555 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
1556 /// the default signal handler.
1557 ///
1558 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
1559 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
1560 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
1561 Self {
1562 builder: self.builder.property("tooltip-text", tooltip_text.into()),
1563 }
1564 }
1565
1566 /// How to distribute vertical space if widget gets extra space.
1567 pub fn valign(self, valign: Align) -> Self {
1568 Self {
1569 builder: self.builder.property("valign", valign),
1570 }
1571 }
1572
1573 /// Whether to expand vertically.
1574 pub fn vexpand(self, vexpand: bool) -> Self {
1575 Self {
1576 builder: self.builder.property("vexpand", vexpand),
1577 }
1578 }
1579
1580 /// Whether to use the `vexpand` property.
1581 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
1582 Self {
1583 builder: self.builder.property("vexpand-set", vexpand_set),
1584 }
1585 }
1586
1587 /// Whether the widget is visible.
1588 pub fn visible(self, visible: bool) -> Self {
1589 Self {
1590 builder: self.builder.property("visible", visible),
1591 }
1592 }
1593
1594 /// Overrides for width request of the widget.
1595 ///
1596 /// If this is -1, the natural request will be used.
1597 pub fn width_request(self, width_request: i32) -> Self {
1598 Self {
1599 builder: self.builder.property("width-request", width_request),
1600 }
1601 }
1602
1603 /// The accessible role of the given [`Accessible`][crate::Accessible] implementation.
1604 ///
1605 /// The accessible role cannot be changed once set.
1606 pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
1607 Self {
1608 builder: self.builder.property("accessible-role", accessible_role),
1609 }
1610 }
1611
1612 // rustdoc-stripper-ignore-next
1613 /// Build the [`DropDown`].
1614 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
1615 pub fn build(self) -> DropDown {
1616 assert_initialized_main_thread!();
1617 self.builder.build()
1618 }
1619}