gtk4/auto/
slice_list_model.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;
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")]
20    pub struct SliceListModel(Object<ffi::GtkSliceListModel, ffi::GtkSliceListModelClass>) @implements gio::ListModel, SectionModel;
21
22    match fn {
23        type_ => || ffi::gtk_slice_list_model_get_type(),
24    }
25}
26
27#[cfg(not(any(feature = "v4_12")))]
28glib::wrapper! {
29    #[doc(alias = "GtkSliceListModel")]
30    pub struct SliceListModel(Object<ffi::GtkSliceListModel, ffi::GtkSliceListModelClass>) @implements gio::ListModel;
31
32    match fn {
33        type_ => || ffi::gtk_slice_list_model_get_type(),
34    }
35}
36
37impl SliceListModel {
38    #[doc(alias = "gtk_slice_list_model_new")]
39    pub fn new(model: Option<impl IsA<gio::ListModel>>, offset: u32, size: u32) -> SliceListModel {
40        assert_initialized_main_thread!();
41        unsafe {
42            from_glib_full(ffi::gtk_slice_list_model_new(
43                model.map(|p| p.upcast()).into_glib_ptr(),
44                offset,
45                size,
46            ))
47        }
48    }
49
50    // rustdoc-stripper-ignore-next
51    /// Creates a new builder-pattern struct instance to construct [`SliceListModel`] objects.
52    ///
53    /// This method returns an instance of [`SliceListModelBuilder`](crate::builders::SliceListModelBuilder) which can be used to create [`SliceListModel`] objects.
54    pub fn builder() -> SliceListModelBuilder {
55        SliceListModelBuilder::new()
56    }
57
58    #[doc(alias = "gtk_slice_list_model_get_model")]
59    #[doc(alias = "get_model")]
60    pub fn model(&self) -> Option<gio::ListModel> {
61        unsafe { from_glib_none(ffi::gtk_slice_list_model_get_model(self.to_glib_none().0)) }
62    }
63
64    #[doc(alias = "gtk_slice_list_model_get_offset")]
65    #[doc(alias = "get_offset")]
66    pub fn offset(&self) -> u32 {
67        unsafe { ffi::gtk_slice_list_model_get_offset(self.to_glib_none().0) }
68    }
69
70    #[doc(alias = "gtk_slice_list_model_get_size")]
71    #[doc(alias = "get_size")]
72    pub fn size(&self) -> u32 {
73        unsafe { ffi::gtk_slice_list_model_get_size(self.to_glib_none().0) }
74    }
75
76    #[doc(alias = "gtk_slice_list_model_set_model")]
77    #[doc(alias = "model")]
78    pub fn set_model(&self, model: Option<&impl IsA<gio::ListModel>>) {
79        unsafe {
80            ffi::gtk_slice_list_model_set_model(
81                self.to_glib_none().0,
82                model.map(|p| p.as_ref()).to_glib_none().0,
83            );
84        }
85    }
86
87    #[doc(alias = "gtk_slice_list_model_set_offset")]
88    #[doc(alias = "offset")]
89    pub fn set_offset(&self, offset: u32) {
90        unsafe {
91            ffi::gtk_slice_list_model_set_offset(self.to_glib_none().0, offset);
92        }
93    }
94
95    #[doc(alias = "gtk_slice_list_model_set_size")]
96    #[doc(alias = "size")]
97    pub fn set_size(&self, size: u32) {
98        unsafe {
99            ffi::gtk_slice_list_model_set_size(self.to_glib_none().0, size);
100        }
101    }
102
103    #[doc(alias = "model")]
104    pub fn connect_model_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
105        unsafe extern "C" fn notify_model_trampoline<F: Fn(&SliceListModel) + 'static>(
106            this: *mut ffi::GtkSliceListModel,
107            _param_spec: glib::ffi::gpointer,
108            f: glib::ffi::gpointer,
109        ) {
110            let f: &F = &*(f as *const F);
111            f(&from_glib_borrow(this))
112        }
113        unsafe {
114            let f: Box_<F> = Box_::new(f);
115            connect_raw(
116                self.as_ptr() as *mut _,
117                c"notify::model".as_ptr() as *const _,
118                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
119                    notify_model_trampoline::<F> as *const (),
120                )),
121                Box_::into_raw(f),
122            )
123        }
124    }
125
126    #[doc(alias = "offset")]
127    pub fn connect_offset_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
128        unsafe extern "C" fn notify_offset_trampoline<F: Fn(&SliceListModel) + 'static>(
129            this: *mut ffi::GtkSliceListModel,
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                c"notify::offset".as_ptr() as *const _,
141                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
142                    notify_offset_trampoline::<F> as *const (),
143                )),
144                Box_::into_raw(f),
145            )
146        }
147    }
148
149    #[doc(alias = "size")]
150    pub fn connect_size_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
151        unsafe extern "C" fn notify_size_trampoline<F: Fn(&SliceListModel) + 'static>(
152            this: *mut ffi::GtkSliceListModel,
153            _param_spec: glib::ffi::gpointer,
154            f: glib::ffi::gpointer,
155        ) {
156            let f: &F = &*(f as *const F);
157            f(&from_glib_borrow(this))
158        }
159        unsafe {
160            let f: Box_<F> = Box_::new(f);
161            connect_raw(
162                self.as_ptr() as *mut _,
163                c"notify::size".as_ptr() as *const _,
164                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
165                    notify_size_trampoline::<F> as *const (),
166                )),
167                Box_::into_raw(f),
168            )
169        }
170    }
171}
172
173impl Default for SliceListModel {
174    fn default() -> Self {
175        glib::object::Object::new::<Self>()
176    }
177}
178
179// rustdoc-stripper-ignore-next
180/// A [builder-pattern] type to construct [`SliceListModel`] objects.
181///
182/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
183#[must_use = "The builder must be built to be used"]
184pub struct SliceListModelBuilder {
185    builder: glib::object::ObjectBuilder<'static, SliceListModel>,
186}
187
188impl SliceListModelBuilder {
189    fn new() -> Self {
190        Self {
191            builder: glib::object::Object::builder(),
192        }
193    }
194
195    pub fn model(self, model: &impl IsA<gio::ListModel>) -> Self {
196        Self {
197            builder: self.builder.property("model", model.clone().upcast()),
198        }
199    }
200
201    pub fn offset(self, offset: u32) -> Self {
202        Self {
203            builder: self.builder.property("offset", offset),
204        }
205    }
206
207    pub fn size(self, size: u32) -> Self {
208        Self {
209            builder: self.builder.property("size", size),
210        }
211    }
212
213    // rustdoc-stripper-ignore-next
214    /// Build the [`SliceListModel`].
215    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
216    pub fn build(self) -> SliceListModel {
217        assert_initialized_main_thread!();
218        self.builder.build()
219    }
220}