gtk4/auto/
list_item.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 items in a [`gio::ListModel`][crate::gio::ListModel].
15    ///
16    /// [`ListItem`][crate::ListItem] objects are managed by the list widget (with its factory)
17    /// and cannot be created by applications, but they need to be populated
18    /// by application code. This is done by calling [`ListItemExt::set_child()`][crate::prelude::ListItemExt::set_child()].
19    ///
20    /// [`ListItem`][crate::ListItem] objects exist in 2 stages:
21    ///
22    /// 1. The unbound stage where the listitem is not currently connected to
23    ///    an item in the list. In that case, the [`item`][struct@crate::ListItem#item]
24    ///    property is set to `NULL`.
25    ///
26    /// 2. The bound stage where the listitem references an item from the list.
27    ///    The [`item`][struct@crate::ListItem#item] property is not `NULL`.
28    ///
29    /// ## Properties
30    ///
31    ///
32    /// #### `accessible-description`
33    ///  The accessible description to set on the listitem.
34    ///
35    /// Readable | Writeable
36    ///
37    ///
38    /// #### `accessible-label`
39    ///  The accessible label to set on the listitem.
40    ///
41    /// Readable | Writeable
42    ///
43    ///
44    /// #### `activatable`
45    ///  If the item can be activated by the user.
46    ///
47    /// Readable | Writeable
48    ///
49    ///
50    /// #### `child`
51    ///  Widget used for display.
52    ///
53    /// Readable | Writeable
54    ///
55    ///
56    /// #### `focusable`
57    ///  If the item can be focused with the keyboard.
58    ///
59    /// Readable | Writeable
60    ///
61    ///
62    /// #### `item`
63    ///  Displayed item.
64    ///
65    /// Readable
66    ///
67    ///
68    /// #### `position`
69    ///  Position of the item.
70    ///
71    /// Readable
72    ///
73    ///
74    /// #### `selectable`
75    ///  If the item can be selected by the user.
76    ///
77    /// Readable | Writeable
78    ///
79    ///
80    /// #### `selected`
81    ///  If the item is currently selected.
82    ///
83    /// Readable
84    ///
85    /// # Implements
86    ///
87    /// [`ListItemExt`][trait@crate::prelude::ListItemExt], [`trait@glib::ObjectExt`]
88    #[doc(alias = "GtkListItem")]
89    pub struct ListItem(Object<ffi::GtkListItem, ffi::GtkListItemClass>);
90
91    match fn {
92        type_ => || ffi::gtk_list_item_get_type(),
93    }
94}
95
96impl ListItem {
97    pub const NONE: Option<&'static ListItem> = None;
98}
99
100/// Trait containing all [`struct@ListItem`] methods.
101///
102/// # Implementors
103///
104/// [`ColumnViewCell`][struct@crate::ColumnViewCell], [`ListItem`][struct@crate::ListItem]
105pub trait ListItemExt: IsA<ListItem> + 'static {
106    /// Gets the accessible description of @self.
107    ///
108    /// # Returns
109    ///
110    /// the accessible description
111    #[cfg(feature = "v4_12")]
112    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
113    #[doc(alias = "gtk_list_item_get_accessible_description")]
114    #[doc(alias = "get_accessible_description")]
115    #[doc(alias = "accessible-description")]
116    fn accessible_description(&self) -> glib::GString {
117        unsafe {
118            from_glib_none(ffi::gtk_list_item_get_accessible_description(
119                self.as_ref().to_glib_none().0,
120            ))
121        }
122    }
123
124    /// Gets the accessible label of @self.
125    ///
126    /// # Returns
127    ///
128    /// the accessible label
129    #[cfg(feature = "v4_12")]
130    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
131    #[doc(alias = "gtk_list_item_get_accessible_label")]
132    #[doc(alias = "get_accessible_label")]
133    #[doc(alias = "accessible-label")]
134    fn accessible_label(&self) -> glib::GString {
135        unsafe {
136            from_glib_none(ffi::gtk_list_item_get_accessible_label(
137                self.as_ref().to_glib_none().0,
138            ))
139        }
140    }
141
142    /// Checks if a listitem has been set to be activatable via
143    /// [`set_activatable()`][Self::set_activatable()].
144    ///
145    /// # Returns
146    ///
147    /// true if the item is activatable
148    #[doc(alias = "gtk_list_item_get_activatable")]
149    #[doc(alias = "get_activatable")]
150    #[doc(alias = "activatable")]
151    fn is_activatable(&self) -> bool {
152        unsafe {
153            from_glib(ffi::gtk_list_item_get_activatable(
154                self.as_ref().to_glib_none().0,
155            ))
156        }
157    }
158
159    /// Gets the child previously set via [`set_child()`][Self::set_child()]
160    /// or `NULL` if none was set.
161    ///
162    /// # Returns
163    ///
164    /// The child
165    #[doc(alias = "gtk_list_item_get_child")]
166    #[doc(alias = "get_child")]
167    fn child(&self) -> Option<Widget> {
168        unsafe { from_glib_none(ffi::gtk_list_item_get_child(self.as_ref().to_glib_none().0)) }
169    }
170
171    /// Checks if a listitem has been set to be focusable via
172    /// [`set_focusable()`][Self::set_focusable()].
173    ///
174    /// # Returns
175    ///
176    /// true if the item is focusable
177    #[cfg(feature = "v4_12")]
178    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
179    #[doc(alias = "gtk_list_item_get_focusable")]
180    #[doc(alias = "get_focusable")]
181    #[doc(alias = "focusable")]
182    fn is_focusable(&self) -> bool {
183        unsafe {
184            from_glib(ffi::gtk_list_item_get_focusable(
185                self.as_ref().to_glib_none().0,
186            ))
187        }
188    }
189
190    /// Gets the model item that associated with @self.
191    ///
192    /// If @self is unbound, this function returns `NULL`.
193    ///
194    /// # Returns
195    ///
196    /// The item displayed
197    #[doc(alias = "gtk_list_item_get_item")]
198    #[doc(alias = "get_item")]
199    fn item(&self) -> Option<glib::Object> {
200        unsafe { from_glib_none(ffi::gtk_list_item_get_item(self.as_ref().to_glib_none().0)) }
201    }
202
203    /// Gets the position in the model that @self currently displays.
204    ///
205    /// If @self is unbound, `GTK_INVALID_LIST_POSITION` is returned.
206    ///
207    /// # Returns
208    ///
209    /// The position of this item
210    #[doc(alias = "gtk_list_item_get_position")]
211    #[doc(alias = "get_position")]
212    fn position(&self) -> u32 {
213        unsafe { ffi::gtk_list_item_get_position(self.as_ref().to_glib_none().0) }
214    }
215
216    /// Checks if a listitem has been set to be selectable via
217    /// [`set_selectable()`][Self::set_selectable()].
218    ///
219    /// Do not confuse this function with [`is_selected()`][Self::is_selected()].
220    ///
221    /// # Returns
222    ///
223    /// true if the item is selectable
224    #[doc(alias = "gtk_list_item_get_selectable")]
225    #[doc(alias = "get_selectable")]
226    #[doc(alias = "selectable")]
227    fn is_selectable(&self) -> bool {
228        unsafe {
229            from_glib(ffi::gtk_list_item_get_selectable(
230                self.as_ref().to_glib_none().0,
231            ))
232        }
233    }
234
235    /// Checks if the item is displayed as selected.
236    ///
237    /// The selected state is maintained by the list widget and its model
238    /// and cannot be set otherwise.
239    ///
240    /// # Returns
241    ///
242    /// true if the item is selected.
243    #[doc(alias = "gtk_list_item_get_selected")]
244    #[doc(alias = "get_selected")]
245    #[doc(alias = "selected")]
246    fn is_selected(&self) -> bool {
247        unsafe {
248            from_glib(ffi::gtk_list_item_get_selected(
249                self.as_ref().to_glib_none().0,
250            ))
251        }
252    }
253
254    /// Sets the accessible description for the listitem.
255    ///
256    /// The accessible description may be used by e.g. screen readers.
257    /// ## `description`
258    /// the description
259    #[cfg(feature = "v4_12")]
260    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
261    #[doc(alias = "gtk_list_item_set_accessible_description")]
262    #[doc(alias = "accessible-description")]
263    fn set_accessible_description(&self, description: &str) {
264        unsafe {
265            ffi::gtk_list_item_set_accessible_description(
266                self.as_ref().to_glib_none().0,
267                description.to_glib_none().0,
268            );
269        }
270    }
271
272    /// Sets the accessible label for the listitem.
273    ///
274    /// The accessible label may be used by e.g. screen readers.
275    /// ## `label`
276    /// the label
277    #[cfg(feature = "v4_12")]
278    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
279    #[doc(alias = "gtk_list_item_set_accessible_label")]
280    #[doc(alias = "accessible-label")]
281    fn set_accessible_label(&self, label: &str) {
282        unsafe {
283            ffi::gtk_list_item_set_accessible_label(
284                self.as_ref().to_glib_none().0,
285                label.to_glib_none().0,
286            );
287        }
288    }
289
290    /// Sets @self to be activatable.
291    ///
292    /// If an item is activatable, double-clicking on the item, using
293    /// the Return key or calling [`WidgetExt::activate()`][crate::prelude::WidgetExt::activate()] will activate
294    /// the item. Activating instructs the containing view to handle
295    /// activation. [`ListView`][crate::ListView] for example will be emitting the
296    /// [`activate`][struct@crate::ListView#activate] signal.
297    ///
298    /// By default, listitems are activatable.
299    /// ## `activatable`
300    /// if the item should be activatable
301    #[doc(alias = "gtk_list_item_set_activatable")]
302    #[doc(alias = "activatable")]
303    fn set_activatable(&self, activatable: bool) {
304        unsafe {
305            ffi::gtk_list_item_set_activatable(
306                self.as_ref().to_glib_none().0,
307                activatable.into_glib(),
308            );
309        }
310    }
311
312    /// Sets the child to be used for this listitem.
313    ///
314    /// This function is typically called by applications when
315    /// setting up a listitem so that the widget can be reused when
316    /// binding it multiple times.
317    /// ## `child`
318    /// The listitem's child or `NULL` to unset
319    #[doc(alias = "gtk_list_item_set_child")]
320    #[doc(alias = "child")]
321    fn set_child(&self, child: Option<&impl IsA<Widget>>) {
322        unsafe {
323            ffi::gtk_list_item_set_child(
324                self.as_ref().to_glib_none().0,
325                child.map(|p| p.as_ref()).to_glib_none().0,
326            );
327        }
328    }
329
330    /// Sets @self to be focusable.
331    ///
332    /// If an item is focusable, it can be focused using the keyboard.
333    /// This works similar to [`WidgetExt::set_focusable()`][crate::prelude::WidgetExt::set_focusable()].
334    ///
335    /// Note that if items are not focusable, the keyboard cannot be used to activate
336    /// them and selecting only works if one of the listitem's children is focusable.
337    ///
338    /// By default, listitems are focusable.
339    /// ## `focusable`
340    /// if the item should be focusable
341    #[cfg(feature = "v4_12")]
342    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
343    #[doc(alias = "gtk_list_item_set_focusable")]
344    #[doc(alias = "focusable")]
345    fn set_focusable(&self, focusable: bool) {
346        unsafe {
347            ffi::gtk_list_item_set_focusable(self.as_ref().to_glib_none().0, focusable.into_glib());
348        }
349    }
350
351    /// Sets @self to be selectable.
352    ///
353    /// If an item is selectable, clicking on the item or using the keyboard
354    /// will try to select or unselect the item. If this succeeds is up to
355    /// the model to determine, as it is managing the selected state.
356    ///
357    /// Note that this means that making an item non-selectable has no
358    /// influence on the selected state at all. A non-selectable item
359    /// may still be selected.
360    ///
361    /// By default, listitems are selectable. When rebinding them to
362    /// a new item, they will also be reset to be selectable by GTK.
363    /// ## `selectable`
364    /// if the item should be selectable
365    #[doc(alias = "gtk_list_item_set_selectable")]
366    #[doc(alias = "selectable")]
367    fn set_selectable(&self, selectable: bool) {
368        unsafe {
369            ffi::gtk_list_item_set_selectable(
370                self.as_ref().to_glib_none().0,
371                selectable.into_glib(),
372            );
373        }
374    }
375
376    #[cfg(feature = "v4_12")]
377    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
378    #[doc(alias = "accessible-description")]
379    fn connect_accessible_description_notify<F: Fn(&Self) + 'static>(
380        &self,
381        f: F,
382    ) -> SignalHandlerId {
383        unsafe extern "C" fn notify_accessible_description_trampoline<
384            P: IsA<ListItem>,
385            F: Fn(&P) + 'static,
386        >(
387            this: *mut ffi::GtkListItem,
388            _param_spec: glib::ffi::gpointer,
389            f: glib::ffi::gpointer,
390        ) {
391            let f: &F = &*(f as *const F);
392            f(ListItem::from_glib_borrow(this).unsafe_cast_ref())
393        }
394        unsafe {
395            let f: Box_<F> = Box_::new(f);
396            connect_raw(
397                self.as_ptr() as *mut _,
398                c"notify::accessible-description".as_ptr() as *const _,
399                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
400                    notify_accessible_description_trampoline::<Self, F> as *const (),
401                )),
402                Box_::into_raw(f),
403            )
404        }
405    }
406
407    #[cfg(feature = "v4_12")]
408    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
409    #[doc(alias = "accessible-label")]
410    fn connect_accessible_label_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
411        unsafe extern "C" fn notify_accessible_label_trampoline<
412            P: IsA<ListItem>,
413            F: Fn(&P) + 'static,
414        >(
415            this: *mut ffi::GtkListItem,
416            _param_spec: glib::ffi::gpointer,
417            f: glib::ffi::gpointer,
418        ) {
419            let f: &F = &*(f as *const F);
420            f(ListItem::from_glib_borrow(this).unsafe_cast_ref())
421        }
422        unsafe {
423            let f: Box_<F> = Box_::new(f);
424            connect_raw(
425                self.as_ptr() as *mut _,
426                c"notify::accessible-label".as_ptr() as *const _,
427                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
428                    notify_accessible_label_trampoline::<Self, F> as *const (),
429                )),
430                Box_::into_raw(f),
431            )
432        }
433    }
434
435    #[doc(alias = "activatable")]
436    fn connect_activatable_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
437        unsafe extern "C" fn notify_activatable_trampoline<
438            P: IsA<ListItem>,
439            F: Fn(&P) + 'static,
440        >(
441            this: *mut ffi::GtkListItem,
442            _param_spec: glib::ffi::gpointer,
443            f: glib::ffi::gpointer,
444        ) {
445            let f: &F = &*(f as *const F);
446            f(ListItem::from_glib_borrow(this).unsafe_cast_ref())
447        }
448        unsafe {
449            let f: Box_<F> = Box_::new(f);
450            connect_raw(
451                self.as_ptr() as *mut _,
452                c"notify::activatable".as_ptr() as *const _,
453                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
454                    notify_activatable_trampoline::<Self, F> as *const (),
455                )),
456                Box_::into_raw(f),
457            )
458        }
459    }
460
461    #[doc(alias = "child")]
462    fn connect_child_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
463        unsafe extern "C" fn notify_child_trampoline<P: IsA<ListItem>, F: Fn(&P) + 'static>(
464            this: *mut ffi::GtkListItem,
465            _param_spec: glib::ffi::gpointer,
466            f: glib::ffi::gpointer,
467        ) {
468            let f: &F = &*(f as *const F);
469            f(ListItem::from_glib_borrow(this).unsafe_cast_ref())
470        }
471        unsafe {
472            let f: Box_<F> = Box_::new(f);
473            connect_raw(
474                self.as_ptr() as *mut _,
475                c"notify::child".as_ptr() as *const _,
476                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
477                    notify_child_trampoline::<Self, F> as *const (),
478                )),
479                Box_::into_raw(f),
480            )
481        }
482    }
483
484    #[cfg(feature = "v4_12")]
485    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
486    #[doc(alias = "focusable")]
487    fn connect_focusable_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
488        unsafe extern "C" fn notify_focusable_trampoline<P: IsA<ListItem>, F: Fn(&P) + 'static>(
489            this: *mut ffi::GtkListItem,
490            _param_spec: glib::ffi::gpointer,
491            f: glib::ffi::gpointer,
492        ) {
493            let f: &F = &*(f as *const F);
494            f(ListItem::from_glib_borrow(this).unsafe_cast_ref())
495        }
496        unsafe {
497            let f: Box_<F> = Box_::new(f);
498            connect_raw(
499                self.as_ptr() as *mut _,
500                c"notify::focusable".as_ptr() as *const _,
501                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
502                    notify_focusable_trampoline::<Self, F> as *const (),
503                )),
504                Box_::into_raw(f),
505            )
506        }
507    }
508
509    #[doc(alias = "item")]
510    fn connect_item_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
511        unsafe extern "C" fn notify_item_trampoline<P: IsA<ListItem>, F: Fn(&P) + 'static>(
512            this: *mut ffi::GtkListItem,
513            _param_spec: glib::ffi::gpointer,
514            f: glib::ffi::gpointer,
515        ) {
516            let f: &F = &*(f as *const F);
517            f(ListItem::from_glib_borrow(this).unsafe_cast_ref())
518        }
519        unsafe {
520            let f: Box_<F> = Box_::new(f);
521            connect_raw(
522                self.as_ptr() as *mut _,
523                c"notify::item".as_ptr() as *const _,
524                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
525                    notify_item_trampoline::<Self, F> as *const (),
526                )),
527                Box_::into_raw(f),
528            )
529        }
530    }
531
532    #[doc(alias = "position")]
533    fn connect_position_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
534        unsafe extern "C" fn notify_position_trampoline<P: IsA<ListItem>, F: Fn(&P) + 'static>(
535            this: *mut ffi::GtkListItem,
536            _param_spec: glib::ffi::gpointer,
537            f: glib::ffi::gpointer,
538        ) {
539            let f: &F = &*(f as *const F);
540            f(ListItem::from_glib_borrow(this).unsafe_cast_ref())
541        }
542        unsafe {
543            let f: Box_<F> = Box_::new(f);
544            connect_raw(
545                self.as_ptr() as *mut _,
546                c"notify::position".as_ptr() as *const _,
547                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
548                    notify_position_trampoline::<Self, F> as *const (),
549                )),
550                Box_::into_raw(f),
551            )
552        }
553    }
554
555    #[doc(alias = "selectable")]
556    fn connect_selectable_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
557        unsafe extern "C" fn notify_selectable_trampoline<P: IsA<ListItem>, F: Fn(&P) + 'static>(
558            this: *mut ffi::GtkListItem,
559            _param_spec: glib::ffi::gpointer,
560            f: glib::ffi::gpointer,
561        ) {
562            let f: &F = &*(f as *const F);
563            f(ListItem::from_glib_borrow(this).unsafe_cast_ref())
564        }
565        unsafe {
566            let f: Box_<F> = Box_::new(f);
567            connect_raw(
568                self.as_ptr() as *mut _,
569                c"notify::selectable".as_ptr() as *const _,
570                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
571                    notify_selectable_trampoline::<Self, F> as *const (),
572                )),
573                Box_::into_raw(f),
574            )
575        }
576    }
577
578    #[doc(alias = "selected")]
579    fn connect_selected_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
580        unsafe extern "C" fn notify_selected_trampoline<P: IsA<ListItem>, F: Fn(&P) + 'static>(
581            this: *mut ffi::GtkListItem,
582            _param_spec: glib::ffi::gpointer,
583            f: glib::ffi::gpointer,
584        ) {
585            let f: &F = &*(f as *const F);
586            f(ListItem::from_glib_borrow(this).unsafe_cast_ref())
587        }
588        unsafe {
589            let f: Box_<F> = Box_::new(f);
590            connect_raw(
591                self.as_ptr() as *mut _,
592                c"notify::selected".as_ptr() as *const _,
593                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
594                    notify_selected_trampoline::<Self, F> as *const (),
595                )),
596                Box_::into_raw(f),
597            )
598        }
599    }
600}
601
602impl<O: IsA<ListItem>> ListItemExt for O {}