1use crate::{
6 ffi, Accessible, AccessibleRole, Adjustment, Align, Buildable, ConstraintTarget, LayoutManager,
7 ListBase, ListItemFactory, Orientable, Orientation, Overflow, Scrollable, ScrollablePolicy,
8 SelectionModel, Widget,
9};
10#[cfg(feature = "v4_12")]
11#[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
12use crate::{ListScrollFlags, ListTabBehavior, ScrollInfo};
13use glib::{
14 object::ObjectType as _,
15 prelude::*,
16 signal::{connect_raw, SignalHandlerId},
17 translate::*,
18};
19use std::boxed::Box as Box_;
20
21glib::wrapper! {
22 #[doc(alias = "GtkListView")]
23 pub struct ListView(Object<ffi::GtkListView, ffi::GtkListViewClass>) @extends ListBase, Widget, @implements Accessible, Buildable, ConstraintTarget, Orientable, Scrollable;
24
25 match fn {
26 type_ => || ffi::gtk_list_view_get_type(),
27 }
28}
29
30impl ListView {
31 #[doc(alias = "gtk_list_view_new")]
32 pub fn new(
33 model: Option<impl IsA<SelectionModel>>,
34 factory: Option<impl IsA<ListItemFactory>>,
35 ) -> ListView {
36 assert_initialized_main_thread!();
37 unsafe {
38 Widget::from_glib_none(ffi::gtk_list_view_new(
39 model.map(|p| p.upcast()).into_glib_ptr(),
40 factory.map(|p| p.upcast()).into_glib_ptr(),
41 ))
42 .unsafe_cast()
43 }
44 }
45
46 pub fn builder() -> ListViewBuilder {
51 ListViewBuilder::new()
52 }
53
54 #[doc(alias = "gtk_list_view_get_enable_rubberband")]
55 #[doc(alias = "get_enable_rubberband")]
56 #[doc(alias = "enable-rubberband")]
57 pub fn enables_rubberband(&self) -> bool {
58 unsafe {
59 from_glib(ffi::gtk_list_view_get_enable_rubberband(
60 self.to_glib_none().0,
61 ))
62 }
63 }
64
65 #[doc(alias = "gtk_list_view_get_factory")]
66 #[doc(alias = "get_factory")]
67 pub fn factory(&self) -> Option<ListItemFactory> {
68 unsafe { from_glib_none(ffi::gtk_list_view_get_factory(self.to_glib_none().0)) }
69 }
70
71 #[cfg(feature = "v4_12")]
72 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
73 #[doc(alias = "gtk_list_view_get_header_factory")]
74 #[doc(alias = "get_header_factory")]
75 #[doc(alias = "header-factory")]
76 pub fn header_factory(&self) -> Option<ListItemFactory> {
77 unsafe { from_glib_none(ffi::gtk_list_view_get_header_factory(self.to_glib_none().0)) }
78 }
79
80 #[doc(alias = "gtk_list_view_get_model")]
81 #[doc(alias = "get_model")]
82 pub fn model(&self) -> Option<SelectionModel> {
83 unsafe { from_glib_none(ffi::gtk_list_view_get_model(self.to_glib_none().0)) }
84 }
85
86 #[doc(alias = "gtk_list_view_get_show_separators")]
87 #[doc(alias = "get_show_separators")]
88 #[doc(alias = "show-separators")]
89 pub fn shows_separators(&self) -> bool {
90 unsafe {
91 from_glib(ffi::gtk_list_view_get_show_separators(
92 self.to_glib_none().0,
93 ))
94 }
95 }
96
97 #[doc(alias = "gtk_list_view_get_single_click_activate")]
98 #[doc(alias = "get_single_click_activate")]
99 #[doc(alias = "single-click-activate")]
100 pub fn is_single_click_activate(&self) -> bool {
101 unsafe {
102 from_glib(ffi::gtk_list_view_get_single_click_activate(
103 self.to_glib_none().0,
104 ))
105 }
106 }
107
108 #[cfg(feature = "v4_12")]
109 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
110 #[doc(alias = "gtk_list_view_get_tab_behavior")]
111 #[doc(alias = "get_tab_behavior")]
112 #[doc(alias = "tab-behavior")]
113 pub fn tab_behavior(&self) -> ListTabBehavior {
114 unsafe { from_glib(ffi::gtk_list_view_get_tab_behavior(self.to_glib_none().0)) }
115 }
116
117 #[cfg(feature = "v4_12")]
118 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
119 #[doc(alias = "gtk_list_view_scroll_to")]
120 pub fn scroll_to(&self, pos: u32, flags: ListScrollFlags, scroll: Option<ScrollInfo>) {
121 unsafe {
122 ffi::gtk_list_view_scroll_to(
123 self.to_glib_none().0,
124 pos,
125 flags.into_glib(),
126 scroll.into_glib_ptr(),
127 );
128 }
129 }
130
131 #[doc(alias = "gtk_list_view_set_enable_rubberband")]
132 #[doc(alias = "enable-rubberband")]
133 pub fn set_enable_rubberband(&self, enable_rubberband: bool) {
134 unsafe {
135 ffi::gtk_list_view_set_enable_rubberband(
136 self.to_glib_none().0,
137 enable_rubberband.into_glib(),
138 );
139 }
140 }
141
142 #[doc(alias = "gtk_list_view_set_factory")]
143 #[doc(alias = "factory")]
144 pub fn set_factory(&self, factory: Option<&impl IsA<ListItemFactory>>) {
145 unsafe {
146 ffi::gtk_list_view_set_factory(
147 self.to_glib_none().0,
148 factory.map(|p| p.as_ref()).to_glib_none().0,
149 );
150 }
151 }
152
153 #[cfg(feature = "v4_12")]
154 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
155 #[doc(alias = "gtk_list_view_set_header_factory")]
156 #[doc(alias = "header-factory")]
157 pub fn set_header_factory(&self, factory: Option<&impl IsA<ListItemFactory>>) {
158 unsafe {
159 ffi::gtk_list_view_set_header_factory(
160 self.to_glib_none().0,
161 factory.map(|p| p.as_ref()).to_glib_none().0,
162 );
163 }
164 }
165
166 #[doc(alias = "gtk_list_view_set_model")]
167 #[doc(alias = "model")]
168 pub fn set_model(&self, model: Option<&impl IsA<SelectionModel>>) {
169 unsafe {
170 ffi::gtk_list_view_set_model(
171 self.to_glib_none().0,
172 model.map(|p| p.as_ref()).to_glib_none().0,
173 );
174 }
175 }
176
177 #[doc(alias = "gtk_list_view_set_show_separators")]
178 #[doc(alias = "show-separators")]
179 pub fn set_show_separators(&self, show_separators: bool) {
180 unsafe {
181 ffi::gtk_list_view_set_show_separators(
182 self.to_glib_none().0,
183 show_separators.into_glib(),
184 );
185 }
186 }
187
188 #[doc(alias = "gtk_list_view_set_single_click_activate")]
189 #[doc(alias = "single-click-activate")]
190 pub fn set_single_click_activate(&self, single_click_activate: bool) {
191 unsafe {
192 ffi::gtk_list_view_set_single_click_activate(
193 self.to_glib_none().0,
194 single_click_activate.into_glib(),
195 );
196 }
197 }
198
199 #[cfg(feature = "v4_12")]
200 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
201 #[doc(alias = "gtk_list_view_set_tab_behavior")]
202 #[doc(alias = "tab-behavior")]
203 pub fn set_tab_behavior(&self, tab_behavior: ListTabBehavior) {
204 unsafe {
205 ffi::gtk_list_view_set_tab_behavior(self.to_glib_none().0, tab_behavior.into_glib());
206 }
207 }
208
209 #[doc(alias = "activate")]
210 pub fn connect_activate<F: Fn(&Self, u32) + 'static>(&self, f: F) -> SignalHandlerId {
211 unsafe extern "C" fn activate_trampoline<F: Fn(&ListView, u32) + 'static>(
212 this: *mut ffi::GtkListView,
213 position: std::ffi::c_uint,
214 f: glib::ffi::gpointer,
215 ) {
216 let f: &F = &*(f as *const F);
217 f(&from_glib_borrow(this), position)
218 }
219 unsafe {
220 let f: Box_<F> = Box_::new(f);
221 connect_raw(
222 self.as_ptr() as *mut _,
223 b"activate\0".as_ptr() as *const _,
224 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
225 activate_trampoline::<F> as *const (),
226 )),
227 Box_::into_raw(f),
228 )
229 }
230 }
231
232 #[doc(alias = "enable-rubberband")]
233 pub fn connect_enable_rubberband_notify<F: Fn(&Self) + 'static>(
234 &self,
235 f: F,
236 ) -> SignalHandlerId {
237 unsafe extern "C" fn notify_enable_rubberband_trampoline<F: Fn(&ListView) + 'static>(
238 this: *mut ffi::GtkListView,
239 _param_spec: glib::ffi::gpointer,
240 f: glib::ffi::gpointer,
241 ) {
242 let f: &F = &*(f as *const F);
243 f(&from_glib_borrow(this))
244 }
245 unsafe {
246 let f: Box_<F> = Box_::new(f);
247 connect_raw(
248 self.as_ptr() as *mut _,
249 b"notify::enable-rubberband\0".as_ptr() as *const _,
250 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
251 notify_enable_rubberband_trampoline::<F> as *const (),
252 )),
253 Box_::into_raw(f),
254 )
255 }
256 }
257
258 #[doc(alias = "factory")]
259 pub fn connect_factory_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
260 unsafe extern "C" fn notify_factory_trampoline<F: Fn(&ListView) + 'static>(
261 this: *mut ffi::GtkListView,
262 _param_spec: glib::ffi::gpointer,
263 f: glib::ffi::gpointer,
264 ) {
265 let f: &F = &*(f as *const F);
266 f(&from_glib_borrow(this))
267 }
268 unsafe {
269 let f: Box_<F> = Box_::new(f);
270 connect_raw(
271 self.as_ptr() as *mut _,
272 b"notify::factory\0".as_ptr() as *const _,
273 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
274 notify_factory_trampoline::<F> as *const (),
275 )),
276 Box_::into_raw(f),
277 )
278 }
279 }
280
281 #[cfg(feature = "v4_12")]
282 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
283 #[doc(alias = "header-factory")]
284 pub fn connect_header_factory_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
285 unsafe extern "C" fn notify_header_factory_trampoline<F: Fn(&ListView) + 'static>(
286 this: *mut ffi::GtkListView,
287 _param_spec: glib::ffi::gpointer,
288 f: glib::ffi::gpointer,
289 ) {
290 let f: &F = &*(f as *const F);
291 f(&from_glib_borrow(this))
292 }
293 unsafe {
294 let f: Box_<F> = Box_::new(f);
295 connect_raw(
296 self.as_ptr() as *mut _,
297 b"notify::header-factory\0".as_ptr() as *const _,
298 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
299 notify_header_factory_trampoline::<F> as *const (),
300 )),
301 Box_::into_raw(f),
302 )
303 }
304 }
305
306 #[doc(alias = "model")]
307 pub fn connect_model_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
308 unsafe extern "C" fn notify_model_trampoline<F: Fn(&ListView) + 'static>(
309 this: *mut ffi::GtkListView,
310 _param_spec: glib::ffi::gpointer,
311 f: glib::ffi::gpointer,
312 ) {
313 let f: &F = &*(f as *const F);
314 f(&from_glib_borrow(this))
315 }
316 unsafe {
317 let f: Box_<F> = Box_::new(f);
318 connect_raw(
319 self.as_ptr() as *mut _,
320 b"notify::model\0".as_ptr() as *const _,
321 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
322 notify_model_trampoline::<F> as *const (),
323 )),
324 Box_::into_raw(f),
325 )
326 }
327 }
328
329 #[doc(alias = "show-separators")]
330 pub fn connect_show_separators_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
331 unsafe extern "C" fn notify_show_separators_trampoline<F: Fn(&ListView) + 'static>(
332 this: *mut ffi::GtkListView,
333 _param_spec: glib::ffi::gpointer,
334 f: glib::ffi::gpointer,
335 ) {
336 let f: &F = &*(f as *const F);
337 f(&from_glib_borrow(this))
338 }
339 unsafe {
340 let f: Box_<F> = Box_::new(f);
341 connect_raw(
342 self.as_ptr() as *mut _,
343 b"notify::show-separators\0".as_ptr() as *const _,
344 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
345 notify_show_separators_trampoline::<F> as *const (),
346 )),
347 Box_::into_raw(f),
348 )
349 }
350 }
351
352 #[doc(alias = "single-click-activate")]
353 pub fn connect_single_click_activate_notify<F: Fn(&Self) + 'static>(
354 &self,
355 f: F,
356 ) -> SignalHandlerId {
357 unsafe extern "C" fn notify_single_click_activate_trampoline<F: Fn(&ListView) + 'static>(
358 this: *mut ffi::GtkListView,
359 _param_spec: glib::ffi::gpointer,
360 f: glib::ffi::gpointer,
361 ) {
362 let f: &F = &*(f as *const F);
363 f(&from_glib_borrow(this))
364 }
365 unsafe {
366 let f: Box_<F> = Box_::new(f);
367 connect_raw(
368 self.as_ptr() as *mut _,
369 b"notify::single-click-activate\0".as_ptr() as *const _,
370 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
371 notify_single_click_activate_trampoline::<F> as *const (),
372 )),
373 Box_::into_raw(f),
374 )
375 }
376 }
377
378 #[cfg(feature = "v4_12")]
379 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
380 #[doc(alias = "tab-behavior")]
381 pub fn connect_tab_behavior_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
382 unsafe extern "C" fn notify_tab_behavior_trampoline<F: Fn(&ListView) + 'static>(
383 this: *mut ffi::GtkListView,
384 _param_spec: glib::ffi::gpointer,
385 f: glib::ffi::gpointer,
386 ) {
387 let f: &F = &*(f as *const F);
388 f(&from_glib_borrow(this))
389 }
390 unsafe {
391 let f: Box_<F> = Box_::new(f);
392 connect_raw(
393 self.as_ptr() as *mut _,
394 b"notify::tab-behavior\0".as_ptr() as *const _,
395 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
396 notify_tab_behavior_trampoline::<F> as *const (),
397 )),
398 Box_::into_raw(f),
399 )
400 }
401 }
402}
403
404impl Default for ListView {
405 fn default() -> Self {
406 glib::object::Object::new::<Self>()
407 }
408}
409
410#[must_use = "The builder must be built to be used"]
415pub struct ListViewBuilder {
416 builder: glib::object::ObjectBuilder<'static, ListView>,
417}
418
419impl ListViewBuilder {
420 fn new() -> Self {
421 Self {
422 builder: glib::object::Object::builder(),
423 }
424 }
425
426 pub fn enable_rubberband(self, enable_rubberband: bool) -> Self {
427 Self {
428 builder: self
429 .builder
430 .property("enable-rubberband", enable_rubberband),
431 }
432 }
433
434 pub fn factory(self, factory: &impl IsA<ListItemFactory>) -> Self {
435 Self {
436 builder: self.builder.property("factory", factory.clone().upcast()),
437 }
438 }
439
440 #[cfg(feature = "v4_12")]
441 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
442 pub fn header_factory(self, header_factory: &impl IsA<ListItemFactory>) -> Self {
443 Self {
444 builder: self
445 .builder
446 .property("header-factory", header_factory.clone().upcast()),
447 }
448 }
449
450 pub fn model(self, model: &impl IsA<SelectionModel>) -> Self {
451 Self {
452 builder: self.builder.property("model", model.clone().upcast()),
453 }
454 }
455
456 pub fn show_separators(self, show_separators: bool) -> Self {
457 Self {
458 builder: self.builder.property("show-separators", show_separators),
459 }
460 }
461
462 pub fn single_click_activate(self, single_click_activate: bool) -> Self {
463 Self {
464 builder: self
465 .builder
466 .property("single-click-activate", single_click_activate),
467 }
468 }
469
470 #[cfg(feature = "v4_12")]
471 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
472 pub fn tab_behavior(self, tab_behavior: ListTabBehavior) -> Self {
473 Self {
474 builder: self.builder.property("tab-behavior", tab_behavior),
475 }
476 }
477
478 pub fn orientation(self, orientation: Orientation) -> Self {
479 Self {
480 builder: self.builder.property("orientation", orientation),
481 }
482 }
483
484 pub fn can_focus(self, can_focus: bool) -> Self {
485 Self {
486 builder: self.builder.property("can-focus", can_focus),
487 }
488 }
489
490 pub fn can_target(self, can_target: bool) -> Self {
491 Self {
492 builder: self.builder.property("can-target", can_target),
493 }
494 }
495
496 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
497 Self {
498 builder: self.builder.property("css-classes", css_classes.into()),
499 }
500 }
501
502 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
503 Self {
504 builder: self.builder.property("css-name", css_name.into()),
505 }
506 }
507
508 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
509 Self {
510 builder: self.builder.property("cursor", cursor.clone()),
511 }
512 }
513
514 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
515 Self {
516 builder: self.builder.property("focus-on-click", focus_on_click),
517 }
518 }
519
520 pub fn focusable(self, focusable: bool) -> Self {
521 Self {
522 builder: self.builder.property("focusable", focusable),
523 }
524 }
525
526 pub fn halign(self, halign: Align) -> Self {
527 Self {
528 builder: self.builder.property("halign", halign),
529 }
530 }
531
532 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
533 Self {
534 builder: self.builder.property("has-tooltip", has_tooltip),
535 }
536 }
537
538 pub fn height_request(self, height_request: i32) -> Self {
539 Self {
540 builder: self.builder.property("height-request", height_request),
541 }
542 }
543
544 pub fn hexpand(self, hexpand: bool) -> Self {
545 Self {
546 builder: self.builder.property("hexpand", hexpand),
547 }
548 }
549
550 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
551 Self {
552 builder: self.builder.property("hexpand-set", hexpand_set),
553 }
554 }
555
556 pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
557 Self {
558 builder: self
559 .builder
560 .property("layout-manager", layout_manager.clone().upcast()),
561 }
562 }
563
564 #[cfg(feature = "v4_18")]
565 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
566 pub fn limit_events(self, limit_events: bool) -> Self {
567 Self {
568 builder: self.builder.property("limit-events", limit_events),
569 }
570 }
571
572 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
573 Self {
574 builder: self.builder.property("margin-bottom", margin_bottom),
575 }
576 }
577
578 pub fn margin_end(self, margin_end: i32) -> Self {
579 Self {
580 builder: self.builder.property("margin-end", margin_end),
581 }
582 }
583
584 pub fn margin_start(self, margin_start: i32) -> Self {
585 Self {
586 builder: self.builder.property("margin-start", margin_start),
587 }
588 }
589
590 pub fn margin_top(self, margin_top: i32) -> Self {
591 Self {
592 builder: self.builder.property("margin-top", margin_top),
593 }
594 }
595
596 pub fn name(self, name: impl Into<glib::GString>) -> Self {
597 Self {
598 builder: self.builder.property("name", name.into()),
599 }
600 }
601
602 pub fn opacity(self, opacity: f64) -> Self {
603 Self {
604 builder: self.builder.property("opacity", opacity),
605 }
606 }
607
608 pub fn overflow(self, overflow: Overflow) -> Self {
609 Self {
610 builder: self.builder.property("overflow", overflow),
611 }
612 }
613
614 pub fn receives_default(self, receives_default: bool) -> Self {
615 Self {
616 builder: self.builder.property("receives-default", receives_default),
617 }
618 }
619
620 pub fn sensitive(self, sensitive: bool) -> Self {
621 Self {
622 builder: self.builder.property("sensitive", sensitive),
623 }
624 }
625
626 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
627 Self {
628 builder: self
629 .builder
630 .property("tooltip-markup", tooltip_markup.into()),
631 }
632 }
633
634 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
635 Self {
636 builder: self.builder.property("tooltip-text", tooltip_text.into()),
637 }
638 }
639
640 pub fn valign(self, valign: Align) -> Self {
641 Self {
642 builder: self.builder.property("valign", valign),
643 }
644 }
645
646 pub fn vexpand(self, vexpand: bool) -> Self {
647 Self {
648 builder: self.builder.property("vexpand", vexpand),
649 }
650 }
651
652 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
653 Self {
654 builder: self.builder.property("vexpand-set", vexpand_set),
655 }
656 }
657
658 pub fn visible(self, visible: bool) -> Self {
659 Self {
660 builder: self.builder.property("visible", visible),
661 }
662 }
663
664 pub fn width_request(self, width_request: i32) -> Self {
665 Self {
666 builder: self.builder.property("width-request", width_request),
667 }
668 }
669
670 pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
671 Self {
672 builder: self.builder.property("accessible-role", accessible_role),
673 }
674 }
675
676 pub fn hadjustment(self, hadjustment: &impl IsA<Adjustment>) -> Self {
677 Self {
678 builder: self
679 .builder
680 .property("hadjustment", hadjustment.clone().upcast()),
681 }
682 }
683
684 pub fn hscroll_policy(self, hscroll_policy: ScrollablePolicy) -> Self {
685 Self {
686 builder: self.builder.property("hscroll-policy", hscroll_policy),
687 }
688 }
689
690 pub fn vadjustment(self, vadjustment: &impl IsA<Adjustment>) -> Self {
691 Self {
692 builder: self
693 .builder
694 .property("vadjustment", vadjustment.clone().upcast()),
695 }
696 }
697
698 pub fn vscroll_policy(self, vscroll_policy: ScrollablePolicy) -> Self {
699 Self {
700 builder: self.builder.property("vscroll-policy", vscroll_policy),
701 }
702 }
703
704 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
707 pub fn build(self) -> ListView {
708 assert_initialized_main_thread!();
709 self.builder.build()
710 }
711}