gtk4/auto/
slice_list_model.rs1#[cfg(feature = "v4_12")]
6#[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
7use crate::SectionModel;
8use crate::ffi;
9use glib::{
10 prelude::*,
11 signal::{SignalHandlerId, connect_raw},
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 unsafe {
201 let f: &F = &*(f as *const F);
202 f(&from_glib_borrow(this))
203 }
204 }
205 unsafe {
206 let f: Box_<F> = Box_::new(f);
207 connect_raw(
208 self.as_ptr() as *mut _,
209 c"notify::model".as_ptr() as *const _,
210 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
211 notify_model_trampoline::<F> as *const (),
212 )),
213 Box_::into_raw(f),
214 )
215 }
216 }
217
218 #[doc(alias = "offset")]
219 pub fn connect_offset_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
220 unsafe extern "C" fn notify_offset_trampoline<F: Fn(&SliceListModel) + 'static>(
221 this: *mut ffi::GtkSliceListModel,
222 _param_spec: glib::ffi::gpointer,
223 f: glib::ffi::gpointer,
224 ) {
225 unsafe {
226 let f: &F = &*(f as *const F);
227 f(&from_glib_borrow(this))
228 }
229 }
230 unsafe {
231 let f: Box_<F> = Box_::new(f);
232 connect_raw(
233 self.as_ptr() as *mut _,
234 c"notify::offset".as_ptr() as *const _,
235 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
236 notify_offset_trampoline::<F> as *const (),
237 )),
238 Box_::into_raw(f),
239 )
240 }
241 }
242
243 #[doc(alias = "size")]
244 pub fn connect_size_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
245 unsafe extern "C" fn notify_size_trampoline<F: Fn(&SliceListModel) + 'static>(
246 this: *mut ffi::GtkSliceListModel,
247 _param_spec: glib::ffi::gpointer,
248 f: glib::ffi::gpointer,
249 ) {
250 unsafe {
251 let f: &F = &*(f as *const F);
252 f(&from_glib_borrow(this))
253 }
254 }
255 unsafe {
256 let f: Box_<F> = Box_::new(f);
257 connect_raw(
258 self.as_ptr() as *mut _,
259 c"notify::size".as_ptr() as *const _,
260 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
261 notify_size_trampoline::<F> as *const (),
262 )),
263 Box_::into_raw(f),
264 )
265 }
266 }
267}
268
269impl Default for SliceListModel {
270 fn default() -> Self {
271 glib::object::Object::new::<Self>()
272 }
273}
274
275#[must_use = "The builder must be built to be used"]
280pub struct SliceListModelBuilder {
281 builder: glib::object::ObjectBuilder<'static, SliceListModel>,
282}
283
284impl SliceListModelBuilder {
285 fn new() -> Self {
286 Self {
287 builder: glib::object::Object::builder(),
288 }
289 }
290
291 pub fn model(self, model: &impl IsA<gio::ListModel>) -> Self {
293 Self {
294 builder: self.builder.property("model", model.clone().upcast()),
295 }
296 }
297
298 pub fn offset(self, offset: u32) -> Self {
300 Self {
301 builder: self.builder.property("offset", offset),
302 }
303 }
304
305 pub fn size(self, size: u32) -> Self {
307 Self {
308 builder: self.builder.property("size", size),
309 }
310 }
311
312 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
315 pub fn build(self) -> SliceListModel {
316 assert_initialized_main_thread!();
317 self.builder.build()
318 }
319}