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