Skip to main content

gtk4/auto/
list_header.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::{Widget, ffi};
6use glib::{
7    prelude::*,
8    signal::{SignalHandlerId, connect_raw},
9    translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14    /// Used by list widgets to represent the headers they display.
15    ///
16    /// [`ListHeader`][crate::ListHeader] objects are managed just like [`ListItem`][crate::ListItem]
17    /// objects via their factory, but provide a different set of properties suitable
18    /// for managing the header instead of individual items.
19    ///
20    /// ## Properties
21    ///
22    ///
23    /// #### `child`
24    ///  Widget used for display.
25    ///
26    /// Readable | Writeable
27    ///
28    ///
29    /// #### `end`
30    ///  The first position no longer part of this section.
31    ///
32    /// Readable
33    ///
34    ///
35    /// #### `item`
36    ///  The item at the start of the section.
37    ///
38    /// Readable
39    ///
40    ///
41    /// #### `n-items`
42    ///  Number of items in this section.
43    ///
44    /// Readable
45    ///
46    ///
47    /// #### `start`
48    ///  First position of items in this section.
49    ///
50    /// Readable
51    ///
52    /// # Implements
53    ///
54    /// [`trait@glib::ObjectExt`]
55    #[doc(alias = "GtkListHeader")]
56    pub struct ListHeader(Object<ffi::GtkListHeader, ffi::GtkListHeaderClass>);
57
58    match fn {
59        type_ => || ffi::gtk_list_header_get_type(),
60    }
61}
62
63impl ListHeader {
64    /// Gets the child previously set via gtk_list_header_set_child() or
65    /// [`None`] if none was set.
66    ///
67    /// # Returns
68    ///
69    /// The child
70    #[doc(alias = "gtk_list_header_get_child")]
71    #[doc(alias = "get_child")]
72    pub fn child(&self) -> Option<Widget> {
73        unsafe { from_glib_none(ffi::gtk_list_header_get_child(self.to_glib_none().0)) }
74    }
75
76    /// Gets the end position in the model of the section that @self is
77    /// currently the header for.
78    ///
79    /// If @self is unbound, `GTK_INVALID_LIST_POSITION` is returned.
80    ///
81    /// # Returns
82    ///
83    /// The end position of the section
84    #[doc(alias = "gtk_list_header_get_end")]
85    #[doc(alias = "get_end")]
86    pub fn end(&self) -> u32 {
87        unsafe { ffi::gtk_list_header_get_end(self.to_glib_none().0) }
88    }
89
90    /// Gets the model item at the start of the section.
91    /// This is the item that occupies the list model at position
92    /// [`start`][struct@crate::ListHeader#start].
93    ///
94    /// If @self is unbound, this function returns [`None`].
95    ///
96    /// # Returns
97    ///
98    /// The item displayed
99    #[doc(alias = "gtk_list_header_get_item")]
100    #[doc(alias = "get_item")]
101    pub fn item(&self) -> Option<glib::Object> {
102        unsafe { from_glib_none(ffi::gtk_list_header_get_item(self.to_glib_none().0)) }
103    }
104
105    /// Gets the the number of items in the section.
106    ///
107    /// If @self is unbound, 0 is returned.
108    ///
109    /// # Returns
110    ///
111    /// The number of items in the section
112    #[doc(alias = "gtk_list_header_get_n_items")]
113    #[doc(alias = "get_n_items")]
114    #[doc(alias = "n-items")]
115    pub fn n_items(&self) -> u32 {
116        unsafe { ffi::gtk_list_header_get_n_items(self.to_glib_none().0) }
117    }
118
119    /// Gets the start position in the model of the section that @self is
120    /// currently the header for.
121    ///
122    /// If @self is unbound, `GTK_INVALID_LIST_POSITION` is returned.
123    ///
124    /// # Returns
125    ///
126    /// The start position of the section
127    #[doc(alias = "gtk_list_header_get_start")]
128    #[doc(alias = "get_start")]
129    pub fn start(&self) -> u32 {
130        unsafe { ffi::gtk_list_header_get_start(self.to_glib_none().0) }
131    }
132
133    /// Sets the child to be used for this listitem.
134    ///
135    /// This function is typically called by applications when
136    /// setting up a header so that the widget can be reused when
137    /// binding it multiple times.
138    /// ## `child`
139    /// The list item's child or [`None`] to unset
140    #[doc(alias = "gtk_list_header_set_child")]
141    #[doc(alias = "child")]
142    pub fn set_child(&self, child: Option<&impl IsA<Widget>>) {
143        unsafe {
144            ffi::gtk_list_header_set_child(
145                self.to_glib_none().0,
146                child.map(|p| p.as_ref()).to_glib_none().0,
147            );
148        }
149    }
150
151    #[cfg(feature = "v4_12")]
152    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
153    #[doc(alias = "child")]
154    pub fn connect_child_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
155        unsafe extern "C" fn notify_child_trampoline<F: Fn(&ListHeader) + 'static>(
156            this: *mut ffi::GtkListHeader,
157            _param_spec: glib::ffi::gpointer,
158            f: glib::ffi::gpointer,
159        ) {
160            unsafe {
161                let f: &F = &*(f as *const F);
162                f(&from_glib_borrow(this))
163            }
164        }
165        unsafe {
166            let f: Box_<F> = Box_::new(f);
167            connect_raw(
168                self.as_ptr() as *mut _,
169                c"notify::child".as_ptr() as *const _,
170                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
171                    notify_child_trampoline::<F> as *const (),
172                )),
173                Box_::into_raw(f),
174            )
175        }
176    }
177
178    #[cfg(feature = "v4_12")]
179    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
180    #[doc(alias = "end")]
181    pub fn connect_end_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
182        unsafe extern "C" fn notify_end_trampoline<F: Fn(&ListHeader) + 'static>(
183            this: *mut ffi::GtkListHeader,
184            _param_spec: glib::ffi::gpointer,
185            f: glib::ffi::gpointer,
186        ) {
187            unsafe {
188                let f: &F = &*(f as *const F);
189                f(&from_glib_borrow(this))
190            }
191        }
192        unsafe {
193            let f: Box_<F> = Box_::new(f);
194            connect_raw(
195                self.as_ptr() as *mut _,
196                c"notify::end".as_ptr() as *const _,
197                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
198                    notify_end_trampoline::<F> as *const (),
199                )),
200                Box_::into_raw(f),
201            )
202        }
203    }
204
205    #[cfg(feature = "v4_12")]
206    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
207    #[doc(alias = "item")]
208    pub fn connect_item_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
209        unsafe extern "C" fn notify_item_trampoline<F: Fn(&ListHeader) + 'static>(
210            this: *mut ffi::GtkListHeader,
211            _param_spec: glib::ffi::gpointer,
212            f: glib::ffi::gpointer,
213        ) {
214            unsafe {
215                let f: &F = &*(f as *const F);
216                f(&from_glib_borrow(this))
217            }
218        }
219        unsafe {
220            let f: Box_<F> = Box_::new(f);
221            connect_raw(
222                self.as_ptr() as *mut _,
223                c"notify::item".as_ptr() as *const _,
224                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
225                    notify_item_trampoline::<F> as *const (),
226                )),
227                Box_::into_raw(f),
228            )
229        }
230    }
231
232    #[cfg(feature = "v4_12")]
233    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
234    #[doc(alias = "n-items")]
235    pub fn connect_n_items_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
236        unsafe extern "C" fn notify_n_items_trampoline<F: Fn(&ListHeader) + 'static>(
237            this: *mut ffi::GtkListHeader,
238            _param_spec: glib::ffi::gpointer,
239            f: glib::ffi::gpointer,
240        ) {
241            unsafe {
242                let f: &F = &*(f as *const F);
243                f(&from_glib_borrow(this))
244            }
245        }
246        unsafe {
247            let f: Box_<F> = Box_::new(f);
248            connect_raw(
249                self.as_ptr() as *mut _,
250                c"notify::n-items".as_ptr() as *const _,
251                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
252                    notify_n_items_trampoline::<F> as *const (),
253                )),
254                Box_::into_raw(f),
255            )
256        }
257    }
258
259    #[cfg(feature = "v4_12")]
260    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
261    #[doc(alias = "start")]
262    pub fn connect_start_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
263        unsafe extern "C" fn notify_start_trampoline<F: Fn(&ListHeader) + 'static>(
264            this: *mut ffi::GtkListHeader,
265            _param_spec: glib::ffi::gpointer,
266            f: glib::ffi::gpointer,
267        ) {
268            unsafe {
269                let f: &F = &*(f as *const F);
270                f(&from_glib_borrow(this))
271            }
272        }
273        unsafe {
274            let f: Box_<F> = Box_::new(f);
275            connect_raw(
276                self.as_ptr() as *mut _,
277                c"notify::start".as_ptr() as *const _,
278                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
279                    notify_start_trampoline::<F> as *const (),
280                )),
281                Box_::into_raw(f),
282            )
283        }
284    }
285}