gtk4/auto/
tree_list_row_sorter.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
5use crate::{ffi, Sorter};
6use glib::{
7    prelude::*,
8    signal::{connect_raw, SignalHandlerId},
9    translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14    /// [`TreeListRowSorter`][crate::TreeListRowSorter] is a special-purpose sorter that will apply a given
15    /// sorter to the levels in a tree.
16    ///
17    /// Here is an example for setting up a column view with a tree model and
18    /// a `GtkTreeListSorter`:
19    ///
20    /// **⚠️ The following code is in c ⚠️**
21    ///
22    /// ```c
23    /// column_sorter = gtk_column_view_get_sorter (view);
24    /// sorter = gtk_tree_list_row_sorter_new (g_object_ref (column_sorter));
25    /// sort_model = gtk_sort_list_model_new (tree_model, sorter);
26    /// selection = gtk_single_selection_new (sort_model);
27    /// gtk_column_view_set_model (view, G_LIST_MODEL (selection));
28    /// ```
29    ///
30    /// ## Properties
31    ///
32    ///
33    /// #### `sorter`
34    ///  The underlying sorter
35    ///
36    /// Readable | Writeable
37    ///
38    /// # Implements
39    ///
40    /// [`SorterExt`][trait@crate::prelude::SorterExt], [`trait@glib::ObjectExt`]
41    #[doc(alias = "GtkTreeListRowSorter")]
42    pub struct TreeListRowSorter(Object<ffi::GtkTreeListRowSorter, ffi::GtkTreeListRowSorterClass>) @extends Sorter;
43
44    match fn {
45        type_ => || ffi::gtk_tree_list_row_sorter_get_type(),
46    }
47}
48
49impl TreeListRowSorter {
50    /// Create a special-purpose sorter that applies the sorting
51    /// of @sorter to the levels of a [`TreeListModel`][crate::TreeListModel].
52    ///
53    /// Note that this sorter relies on [`passthrough`][struct@crate::TreeListModel#passthrough]
54    /// being [`false`] as it can only sort [`TreeListRow`][crate::TreeListRow]s.
55    /// ## `sorter`
56    /// a [`Sorter`][crate::Sorter]
57    ///
58    /// # Returns
59    ///
60    /// a new [`TreeListRowSorter`][crate::TreeListRowSorter]
61    #[doc(alias = "gtk_tree_list_row_sorter_new")]
62    pub fn new(sorter: Option<impl IsA<Sorter>>) -> TreeListRowSorter {
63        assert_initialized_main_thread!();
64        unsafe {
65            from_glib_full(ffi::gtk_tree_list_row_sorter_new(
66                sorter.map(|p| p.upcast()).into_glib_ptr(),
67            ))
68        }
69    }
70
71    /// Returns the sorter used by @self.
72    ///
73    /// # Returns
74    ///
75    /// the sorter used
76    #[doc(alias = "gtk_tree_list_row_sorter_get_sorter")]
77    #[doc(alias = "get_sorter")]
78    pub fn sorter(&self) -> Option<Sorter> {
79        unsafe {
80            from_glib_none(ffi::gtk_tree_list_row_sorter_get_sorter(
81                self.to_glib_none().0,
82            ))
83        }
84    }
85
86    /// Sets the sorter to use for items with the same parent.
87    ///
88    /// This sorter will be passed the [`item`][struct@crate::TreeListRow#item] of
89    /// the tree list rows passed to @self.
90    /// ## `sorter`
91    /// The sorter to use
92    #[doc(alias = "gtk_tree_list_row_sorter_set_sorter")]
93    #[doc(alias = "sorter")]
94    pub fn set_sorter(&self, sorter: Option<&impl IsA<Sorter>>) {
95        unsafe {
96            ffi::gtk_tree_list_row_sorter_set_sorter(
97                self.to_glib_none().0,
98                sorter.map(|p| p.as_ref()).to_glib_none().0,
99            );
100        }
101    }
102
103    #[doc(alias = "sorter")]
104    pub fn connect_sorter_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
105        unsafe extern "C" fn notify_sorter_trampoline<F: Fn(&TreeListRowSorter) + 'static>(
106            this: *mut ffi::GtkTreeListRowSorter,
107            _param_spec: glib::ffi::gpointer,
108            f: glib::ffi::gpointer,
109        ) {
110            let f: &F = &*(f as *const F);
111            f(&from_glib_borrow(this))
112        }
113        unsafe {
114            let f: Box_<F> = Box_::new(f);
115            connect_raw(
116                self.as_ptr() as *mut _,
117                b"notify::sorter\0".as_ptr() as *const _,
118                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
119                    notify_sorter_trampoline::<F> as *const (),
120                )),
121                Box_::into_raw(f),
122            )
123        }
124    }
125}