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    /// 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            let f: &F = &*(f as *const F);
161            f(&from_glib_borrow(this))
162        }
163        unsafe {
164            let f: Box_<F> = Box_::new(f);
165            connect_raw(
166                self.as_ptr() as *mut _,
167                c"notify::child".as_ptr() as *const _,
168                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
169                    notify_child_trampoline::<F> as *const (),
170                )),
171                Box_::into_raw(f),
172            )
173        }
174    }
175
176    #[cfg(feature = "v4_12")]
177    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
178    #[doc(alias = "end")]
179    pub fn connect_end_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
180        unsafe extern "C" fn notify_end_trampoline<F: Fn(&ListHeader) + 'static>(
181            this: *mut ffi::GtkListHeader,
182            _param_spec: glib::ffi::gpointer,
183            f: glib::ffi::gpointer,
184        ) {
185            let f: &F = &*(f as *const F);
186            f(&from_glib_borrow(this))
187        }
188        unsafe {
189            let f: Box_<F> = Box_::new(f);
190            connect_raw(
191                self.as_ptr() as *mut _,
192                c"notify::end".as_ptr() as *const _,
193                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
194                    notify_end_trampoline::<F> as *const (),
195                )),
196                Box_::into_raw(f),
197            )
198        }
199    }
200
201    #[cfg(feature = "v4_12")]
202    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
203    #[doc(alias = "item")]
204    pub fn connect_item_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
205        unsafe extern "C" fn notify_item_trampoline<F: Fn(&ListHeader) + 'static>(
206            this: *mut ffi::GtkListHeader,
207            _param_spec: glib::ffi::gpointer,
208            f: glib::ffi::gpointer,
209        ) {
210            let f: &F = &*(f as *const F);
211            f(&from_glib_borrow(this))
212        }
213        unsafe {
214            let f: Box_<F> = Box_::new(f);
215            connect_raw(
216                self.as_ptr() as *mut _,
217                c"notify::item".as_ptr() as *const _,
218                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
219                    notify_item_trampoline::<F> as *const (),
220                )),
221                Box_::into_raw(f),
222            )
223        }
224    }
225
226    #[cfg(feature = "v4_12")]
227    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
228    #[doc(alias = "n-items")]
229    pub fn connect_n_items_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
230        unsafe extern "C" fn notify_n_items_trampoline<F: Fn(&ListHeader) + 'static>(
231            this: *mut ffi::GtkListHeader,
232            _param_spec: glib::ffi::gpointer,
233            f: glib::ffi::gpointer,
234        ) {
235            let f: &F = &*(f as *const F);
236            f(&from_glib_borrow(this))
237        }
238        unsafe {
239            let f: Box_<F> = Box_::new(f);
240            connect_raw(
241                self.as_ptr() as *mut _,
242                c"notify::n-items".as_ptr() as *const _,
243                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
244                    notify_n_items_trampoline::<F> as *const (),
245                )),
246                Box_::into_raw(f),
247            )
248        }
249    }
250
251    #[cfg(feature = "v4_12")]
252    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
253    #[doc(alias = "start")]
254    pub fn connect_start_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
255        unsafe extern "C" fn notify_start_trampoline<F: Fn(&ListHeader) + 'static>(
256            this: *mut ffi::GtkListHeader,
257            _param_spec: glib::ffi::gpointer,
258            f: glib::ffi::gpointer,
259        ) {
260            let f: &F = &*(f as *const F);
261            f(&from_glib_borrow(this))
262        }
263        unsafe {
264            let f: Box_<F> = Box_::new(f);
265            connect_raw(
266                self.as_ptr() as *mut _,
267                c"notify::start".as_ptr() as *const _,
268                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
269                    notify_start_trampoline::<F> as *const (),
270                )),
271                Box_::into_raw(f),
272            )
273        }
274    }
275}