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