gtk4/auto/
tree_list_row_sorter.rs1use 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 #[doc(alias = "GtkTreeListRowSorter")]
15 pub struct TreeListRowSorter(Object<ffi::GtkTreeListRowSorter, ffi::GtkTreeListRowSorterClass>) @extends Sorter;
16
17 match fn {
18 type_ => || ffi::gtk_tree_list_row_sorter_get_type(),
19 }
20}
21
22impl TreeListRowSorter {
23 #[doc(alias = "gtk_tree_list_row_sorter_new")]
24 pub fn new(sorter: Option<impl IsA<Sorter>>) -> TreeListRowSorter {
25 assert_initialized_main_thread!();
26 unsafe {
27 from_glib_full(ffi::gtk_tree_list_row_sorter_new(
28 sorter.map(|p| p.upcast()).into_glib_ptr(),
29 ))
30 }
31 }
32
33 #[doc(alias = "gtk_tree_list_row_sorter_get_sorter")]
34 #[doc(alias = "get_sorter")]
35 pub fn sorter(&self) -> Option<Sorter> {
36 unsafe {
37 from_glib_none(ffi::gtk_tree_list_row_sorter_get_sorter(
38 self.to_glib_none().0,
39 ))
40 }
41 }
42
43 #[doc(alias = "gtk_tree_list_row_sorter_set_sorter")]
44 #[doc(alias = "sorter")]
45 pub fn set_sorter(&self, sorter: Option<&impl IsA<Sorter>>) {
46 unsafe {
47 ffi::gtk_tree_list_row_sorter_set_sorter(
48 self.to_glib_none().0,
49 sorter.map(|p| p.as_ref()).to_glib_none().0,
50 );
51 }
52 }
53
54 #[doc(alias = "sorter")]
55 pub fn connect_sorter_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
56 unsafe extern "C" fn notify_sorter_trampoline<F: Fn(&TreeListRowSorter) + 'static>(
57 this: *mut ffi::GtkTreeListRowSorter,
58 _param_spec: glib::ffi::gpointer,
59 f: glib::ffi::gpointer,
60 ) {
61 let f: &F = &*(f as *const F);
62 f(&from_glib_borrow(this))
63 }
64 unsafe {
65 let f: Box_<F> = Box_::new(f);
66 connect_raw(
67 self.as_ptr() as *mut _,
68 c"notify::sorter".as_ptr() as *const _,
69 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
70 notify_sorter_trampoline::<F> as *const (),
71 )),
72 Box_::into_raw(f),
73 )
74 }
75 }
76}