[go: up one dir, main page]

gtk4/auto/
section_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;
6use glib::{
7    object::ObjectType as _,
8    prelude::*,
9    signal::{connect_raw, SignalHandlerId},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    #[doc(alias = "GtkSectionModel")]
16    pub struct SectionModel(Interface<ffi::GtkSectionModel, ffi::GtkSectionModelInterface>) @requires gio::ListModel;
17
18    match fn {
19        type_ => || ffi::gtk_section_model_get_type(),
20    }
21}
22
23impl SectionModel {
24    pub const NONE: Option<&'static SectionModel> = None;
25}
26
27pub trait SectionModelExt: IsA<SectionModel> + 'static {
28    #[doc(alias = "gtk_section_model_get_section")]
29    #[doc(alias = "get_section")]
30    fn section(&self, position: u32) -> (u32, u32) {
31        unsafe {
32            let mut out_start = std::mem::MaybeUninit::uninit();
33            let mut out_end = std::mem::MaybeUninit::uninit();
34            ffi::gtk_section_model_get_section(
35                self.as_ref().to_glib_none().0,
36                position,
37                out_start.as_mut_ptr(),
38                out_end.as_mut_ptr(),
39            );
40            (out_start.assume_init(), out_end.assume_init())
41        }
42    }
43
44    #[doc(alias = "gtk_section_model_sections_changed")]
45    fn sections_changed(&self, position: u32, n_items: u32) {
46        unsafe {
47            ffi::gtk_section_model_sections_changed(
48                self.as_ref().to_glib_none().0,
49                position,
50                n_items,
51            );
52        }
53    }
54
55    #[cfg(feature = "v4_12")]
56    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
57    #[doc(alias = "sections-changed")]
58    fn connect_sections_changed<F: Fn(&Self, u32, u32) + 'static>(&self, f: F) -> SignalHandlerId {
59        unsafe extern "C" fn sections_changed_trampoline<
60            P: IsA<SectionModel>,
61            F: Fn(&P, u32, u32) + 'static,
62        >(
63            this: *mut ffi::GtkSectionModel,
64            position: std::ffi::c_uint,
65            n_items: std::ffi::c_uint,
66            f: glib::ffi::gpointer,
67        ) {
68            let f: &F = &*(f as *const F);
69            f(
70                SectionModel::from_glib_borrow(this).unsafe_cast_ref(),
71                position,
72                n_items,
73            )
74        }
75        unsafe {
76            let f: Box_<F> = Box_::new(f);
77            connect_raw(
78                self.as_ptr() as *mut _,
79                c"sections-changed".as_ptr() as *const _,
80                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
81                    sections_changed_trampoline::<Self, F> as *const (),
82                )),
83                Box_::into_raw(f),
84            )
85        }
86    }
87}
88
89impl<O: IsA<SectionModel>> SectionModelExt for O {}