gtk4/auto/
flatten_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 = "GtkFlattenListModel")]
20    pub struct FlattenListModel(Object<ffi::GtkFlattenListModel, ffi::GtkFlattenListModelClass>) @implements gio::ListModel, SectionModel;
21
22    match fn {
23        type_ => || ffi::gtk_flatten_list_model_get_type(),
24    }
25}
26
27#[cfg(not(any(feature = "v4_12")))]
28glib::wrapper! {
29    #[doc(alias = "GtkFlattenListModel")]
30    pub struct FlattenListModel(Object<ffi::GtkFlattenListModel, ffi::GtkFlattenListModelClass>) @implements gio::ListModel;
31
32    match fn {
33        type_ => || ffi::gtk_flatten_list_model_get_type(),
34    }
35}
36
37impl FlattenListModel {
38    #[doc(alias = "gtk_flatten_list_model_new")]
39    pub fn new(model: Option<impl IsA<gio::ListModel>>) -> FlattenListModel {
40        assert_initialized_main_thread!();
41        unsafe {
42            from_glib_full(ffi::gtk_flatten_list_model_new(
43                model.map(|p| p.upcast()).into_glib_ptr(),
44            ))
45        }
46    }
47
48    #[doc(alias = "gtk_flatten_list_model_get_model")]
49    #[doc(alias = "get_model")]
50    pub fn model(&self) -> Option<gio::ListModel> {
51        unsafe { from_glib_none(ffi::gtk_flatten_list_model_get_model(self.to_glib_none().0)) }
52    }
53
54    #[doc(alias = "gtk_flatten_list_model_get_model_for_item")]
55    #[doc(alias = "get_model_for_item")]
56    pub fn model_for_item(&self, position: u32) -> Option<gio::ListModel> {
57        unsafe {
58            from_glib_none(ffi::gtk_flatten_list_model_get_model_for_item(
59                self.to_glib_none().0,
60                position,
61            ))
62        }
63    }
64
65    #[doc(alias = "gtk_flatten_list_model_set_model")]
66    #[doc(alias = "model")]
67    pub fn set_model(&self, model: Option<&impl IsA<gio::ListModel>>) {
68        unsafe {
69            ffi::gtk_flatten_list_model_set_model(
70                self.to_glib_none().0,
71                model.map(|p| p.as_ref()).to_glib_none().0,
72            );
73        }
74    }
75
76    #[doc(alias = "model")]
77    pub fn connect_model_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
78        unsafe extern "C" fn notify_model_trampoline<F: Fn(&FlattenListModel) + 'static>(
79            this: *mut ffi::GtkFlattenListModel,
80            _param_spec: glib::ffi::gpointer,
81            f: glib::ffi::gpointer,
82        ) {
83            let f: &F = &*(f as *const F);
84            f(&from_glib_borrow(this))
85        }
86        unsafe {
87            let f: Box_<F> = Box_::new(f);
88            connect_raw(
89                self.as_ptr() as *mut _,
90                c"notify::model".as_ptr() as *const _,
91                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
92                    notify_model_trampoline::<F> as *const (),
93                )),
94                Box_::into_raw(f),
95            )
96        }
97    }
98}