Skip to main content

libadwaita/auto/
shortcuts_section.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from
3// from gir-files (https://github.com/gtk-rs/gir-files.git)
4// DO NOT EDIT
5
6use crate::{ShortcutsItem, ffi};
7use glib::{
8    prelude::*,
9    signal::{SignalHandlerId, connect_raw},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    #[doc(alias = "AdwShortcutsSection")]
16    pub struct ShortcutsSection(Object<ffi::AdwShortcutsSection, ffi::AdwShortcutsSectionClass>) @implements gio::ListModel, gtk::Buildable;
17
18    match fn {
19        type_ => || ffi::adw_shortcuts_section_get_type(),
20    }
21}
22
23impl ShortcutsSection {
24    #[doc(alias = "adw_shortcuts_section_new")]
25    pub fn new(title: Option<&str>) -> ShortcutsSection {
26        assert_initialized_main_thread!();
27        unsafe { from_glib_full(ffi::adw_shortcuts_section_new(title.to_glib_none().0)) }
28    }
29
30    #[doc(alias = "adw_shortcuts_section_add")]
31    pub fn add(&self, item: ShortcutsItem) {
32        unsafe {
33            ffi::adw_shortcuts_section_add(self.to_glib_none().0, item.into_glib_ptr());
34        }
35    }
36
37    #[doc(alias = "adw_shortcuts_section_get_title")]
38    #[doc(alias = "get_title")]
39    pub fn title(&self) -> Option<glib::GString> {
40        unsafe { from_glib_none(ffi::adw_shortcuts_section_get_title(self.to_glib_none().0)) }
41    }
42
43    #[doc(alias = "adw_shortcuts_section_set_title")]
44    #[doc(alias = "title")]
45    pub fn set_title(&self, title: Option<&str>) {
46        unsafe {
47            ffi::adw_shortcuts_section_set_title(self.to_glib_none().0, title.to_glib_none().0);
48        }
49    }
50
51    #[cfg(feature = "v1_8")]
52    #[cfg_attr(docsrs, doc(cfg(feature = "v1_8")))]
53    #[doc(alias = "title")]
54    pub fn connect_title_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
55        unsafe extern "C" fn notify_title_trampoline<F: Fn(&ShortcutsSection) + 'static>(
56            this: *mut ffi::AdwShortcutsSection,
57            _param_spec: glib::ffi::gpointer,
58            f: glib::ffi::gpointer,
59        ) {
60            unsafe {
61                let f: &F = &*(f as *const F);
62                f(&from_glib_borrow(this))
63            }
64        }
65        unsafe {
66            let f: Box_<F> = Box_::new(f);
67            connect_raw(
68                self.as_ptr() as *mut _,
69                c"notify::title".as_ptr(),
70                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
71                    notify_title_trampoline::<F> as *const (),
72                )),
73                Box_::into_raw(f),
74            )
75        }
76    }
77}