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