gtk4/auto/
slice_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 = "GtkSliceListModel")]
63 pub struct SliceListModel(Object<ffi::GtkSliceListModel, ffi::GtkSliceListModelClass>) @implements gio::ListModel, SectionModel;
64
65 match fn {
66 type_ => || ffi::gtk_slice_list_model_get_type(),
67 }
68}
69
70#[cfg(not(any(feature = "v4_12")))]
71glib::wrapper! {
72 #[doc(alias = "GtkSliceListModel")]
73 pub struct SliceListModel(Object<ffi::GtkSliceListModel, ffi::GtkSliceListModelClass>) @implements gio::ListModel;
74
75 match fn {
76 type_ => || ffi::gtk_slice_list_model_get_type(),
77 }
78}
79
80impl SliceListModel {
81 #[doc(alias = "gtk_slice_list_model_new")]
96 pub fn new(model: Option<impl IsA<gio::ListModel>>, offset: u32, size: u32) -> SliceListModel {
97 assert_initialized_main_thread!();
98 unsafe {
99 from_glib_full(ffi::gtk_slice_list_model_new(
100 model.map(|p| p.upcast()).into_glib_ptr(),
101 offset,
102 size,
103 ))
104 }
105 }
106
107 pub fn builder() -> SliceListModelBuilder {
112 SliceListModelBuilder::new()
113 }
114
115 #[doc(alias = "gtk_slice_list_model_get_model")]
121 #[doc(alias = "get_model")]
122 pub fn model(&self) -> Option<gio::ListModel> {
123 unsafe { from_glib_none(ffi::gtk_slice_list_model_get_model(self.to_glib_none().0)) }
124 }
125
126 #[doc(alias = "gtk_slice_list_model_get_offset")]
132 #[doc(alias = "get_offset")]
133 pub fn offset(&self) -> u32 {
134 unsafe { ffi::gtk_slice_list_model_get_offset(self.to_glib_none().0) }
135 }
136
137 #[doc(alias = "gtk_slice_list_model_get_size")]
143 #[doc(alias = "get_size")]
144 pub fn size(&self) -> u32 {
145 unsafe { ffi::gtk_slice_list_model_get_size(self.to_glib_none().0) }
146 }
147
148 #[doc(alias = "gtk_slice_list_model_set_model")]
154 #[doc(alias = "model")]
155 pub fn set_model(&self, model: Option<&impl IsA<gio::ListModel>>) {
156 unsafe {
157 ffi::gtk_slice_list_model_set_model(
158 self.to_glib_none().0,
159 model.map(|p| p.as_ref()).to_glib_none().0,
160 );
161 }
162 }
163
164 #[doc(alias = "gtk_slice_list_model_set_offset")]
171 #[doc(alias = "offset")]
172 pub fn set_offset(&self, offset: u32) {
173 unsafe {
174 ffi::gtk_slice_list_model_set_offset(self.to_glib_none().0, offset);
175 }
176 }
177
178 #[doc(alias = "gtk_slice_list_model_set_size")]
186 #[doc(alias = "size")]
187 pub fn set_size(&self, size: u32) {
188 unsafe {
189 ffi::gtk_slice_list_model_set_size(self.to_glib_none().0, size);
190 }
191 }
192
193 #[doc(alias = "model")]
194 pub fn connect_model_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
195 unsafe extern "C" fn notify_model_trampoline<F: Fn(&SliceListModel) + 'static>(
196 this: *mut ffi::GtkSliceListModel,
197 _param_spec: glib::ffi::gpointer,
198 f: glib::ffi::gpointer,
199 ) {
200 let f: &F = &*(f as *const F);
201 f(&from_glib_borrow(this))
202 }
203 unsafe {
204 let f: Box_<F> = Box_::new(f);
205 connect_raw(
206 self.as_ptr() as *mut _,
207 b"notify::model\0".as_ptr() as *const _,
208 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
209 notify_model_trampoline::<F> as *const (),
210 )),
211 Box_::into_raw(f),
212 )
213 }
214 }
215
216 #[doc(alias = "offset")]
217 pub fn connect_offset_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
218 unsafe extern "C" fn notify_offset_trampoline<F: Fn(&SliceListModel) + 'static>(
219 this: *mut ffi::GtkSliceListModel,
220 _param_spec: glib::ffi::gpointer,
221 f: glib::ffi::gpointer,
222 ) {
223 let f: &F = &*(f as *const F);
224 f(&from_glib_borrow(this))
225 }
226 unsafe {
227 let f: Box_<F> = Box_::new(f);
228 connect_raw(
229 self.as_ptr() as *mut _,
230 b"notify::offset\0".as_ptr() as *const _,
231 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
232 notify_offset_trampoline::<F> as *const (),
233 )),
234 Box_::into_raw(f),
235 )
236 }
237 }
238
239 #[doc(alias = "size")]
240 pub fn connect_size_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
241 unsafe extern "C" fn notify_size_trampoline<F: Fn(&SliceListModel) + 'static>(
242 this: *mut ffi::GtkSliceListModel,
243 _param_spec: glib::ffi::gpointer,
244 f: glib::ffi::gpointer,
245 ) {
246 let f: &F = &*(f as *const F);
247 f(&from_glib_borrow(this))
248 }
249 unsafe {
250 let f: Box_<F> = Box_::new(f);
251 connect_raw(
252 self.as_ptr() as *mut _,
253 b"notify::size\0".as_ptr() as *const _,
254 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
255 notify_size_trampoline::<F> as *const (),
256 )),
257 Box_::into_raw(f),
258 )
259 }
260 }
261}
262
263impl Default for SliceListModel {
264 fn default() -> Self {
265 glib::object::Object::new::<Self>()
266 }
267}
268
269#[must_use = "The builder must be built to be used"]
274pub struct SliceListModelBuilder {
275 builder: glib::object::ObjectBuilder<'static, SliceListModel>,
276}
277
278impl SliceListModelBuilder {
279 fn new() -> Self {
280 Self {
281 builder: glib::object::Object::builder(),
282 }
283 }
284
285 pub fn model(self, model: &impl IsA<gio::ListModel>) -> Self {
287 Self {
288 builder: self.builder.property("model", model.clone().upcast()),
289 }
290 }
291
292 pub fn offset(self, offset: u32) -> Self {
294 Self {
295 builder: self.builder.property("offset", offset),
296 }
297 }
298
299 pub fn size(self, size: u32) -> Self {
301 Self {
302 builder: self.builder.property("size", size),
303 }
304 }
305
306 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
309 pub fn build(self) -> SliceListModel {
310 assert_initialized_main_thread!();
311 self.builder.build()
312 }
313}