gtk4/auto/
flatten_list_model.rs
1use crate::ffi;
6#[cfg(feature = "v4_12")]
7#[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
8use crate::SectionModel;
9use glib::{
10 prelude::*,
11 signal::{connect_raw, SignalHandlerId},
12 translate::*,
13};
14use std::boxed::Box as Box_;
15
16#[cfg(feature = "v4_12")]
17#[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
18glib::wrapper! {
19 #[doc(alias = "GtkFlattenListModel")]
48 pub struct FlattenListModel(Object<ffi::GtkFlattenListModel, ffi::GtkFlattenListModelClass>) @implements gio::ListModel, SectionModel;
49
50 match fn {
51 type_ => || ffi::gtk_flatten_list_model_get_type(),
52 }
53}
54
55#[cfg(not(any(feature = "v4_12")))]
56glib::wrapper! {
57 #[doc(alias = "GtkFlattenListModel")]
58 pub struct FlattenListModel(Object<ffi::GtkFlattenListModel, ffi::GtkFlattenListModelClass>) @implements gio::ListModel;
59
60 match fn {
61 type_ => || ffi::gtk_flatten_list_model_get_type(),
62 }
63}
64
65impl FlattenListModel {
66 #[doc(alias = "gtk_flatten_list_model_new")]
74 pub fn new(model: Option<impl IsA<gio::ListModel>>) -> FlattenListModel {
75 assert_initialized_main_thread!();
76 unsafe {
77 from_glib_full(ffi::gtk_flatten_list_model_new(
78 model.map(|p| p.upcast()).into_glib_ptr(),
79 ))
80 }
81 }
82
83 #[doc(alias = "gtk_flatten_list_model_get_model")]
89 #[doc(alias = "get_model")]
90 pub fn model(&self) -> Option<gio::ListModel> {
91 unsafe { from_glib_none(ffi::gtk_flatten_list_model_get_model(self.to_glib_none().0)) }
92 }
93
94 #[doc(alias = "gtk_flatten_list_model_get_model_for_item")]
102 #[doc(alias = "get_model_for_item")]
103 pub fn model_for_item(&self, position: u32) -> Option<gio::ListModel> {
104 unsafe {
105 from_glib_none(ffi::gtk_flatten_list_model_get_model_for_item(
106 self.to_glib_none().0,
107 position,
108 ))
109 }
110 }
111
112 #[doc(alias = "gtk_flatten_list_model_set_model")]
116 #[doc(alias = "model")]
117 pub fn set_model(&self, model: Option<&impl IsA<gio::ListModel>>) {
118 unsafe {
119 ffi::gtk_flatten_list_model_set_model(
120 self.to_glib_none().0,
121 model.map(|p| p.as_ref()).to_glib_none().0,
122 );
123 }
124 }
125
126 #[doc(alias = "model")]
127 pub fn connect_model_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
128 unsafe extern "C" fn notify_model_trampoline<F: Fn(&FlattenListModel) + 'static>(
129 this: *mut ffi::GtkFlattenListModel,
130 _param_spec: glib::ffi::gpointer,
131 f: glib::ffi::gpointer,
132 ) {
133 let f: &F = &*(f as *const F);
134 f(&from_glib_borrow(this))
135 }
136 unsafe {
137 let f: Box_<F> = Box_::new(f);
138 connect_raw(
139 self.as_ptr() as *mut _,
140 b"notify::model\0".as_ptr() as *const _,
141 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
142 notify_model_trampoline::<F> as *const (),
143 )),
144 Box_::into_raw(f),
145 )
146 }
147 }
148}