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::{ffi, ShortcutsItem};
7use glib::{
8    prelude::*,
9    signal::{connect_raw, SignalHandlerId},
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            let f: &F = &*(f as *const F);
61            f(&from_glib_borrow(this))
62        }
63        unsafe {
64            let f: Box_<F> = Box_::new(f);
65            connect_raw(
66                self.as_ptr() as *mut _,
67                c"notify::title".as_ptr() as *const _,
68                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
69                    notify_title_trampoline::<F> as *const (),
70                )),
71                Box_::into_raw(f),
72            )
73        }
74    }
75}