libadwaita 0.9.1

Rust bindings for libadwaita
Documentation
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from
// from gir-files (https://github.com/gtk-rs/gir-files.git)
// DO NOT EDIT

use crate::{ShortcutsItem, ffi};
use glib::{
    prelude::*,
    signal::{SignalHandlerId, connect_raw},
    translate::*,
};
use std::boxed::Box as Box_;

glib::wrapper! {
    #[doc(alias = "AdwShortcutsSection")]
    pub struct ShortcutsSection(Object<ffi::AdwShortcutsSection, ffi::AdwShortcutsSectionClass>) @implements gio::ListModel, gtk::Buildable;

    match fn {
        type_ => || ffi::adw_shortcuts_section_get_type(),
    }
}

impl ShortcutsSection {
    #[doc(alias = "adw_shortcuts_section_new")]
    pub fn new(title: Option<&str>) -> ShortcutsSection {
        assert_initialized_main_thread!();
        unsafe { from_glib_full(ffi::adw_shortcuts_section_new(title.to_glib_none().0)) }
    }

    #[doc(alias = "adw_shortcuts_section_add")]
    pub fn add(&self, item: ShortcutsItem) {
        unsafe {
            ffi::adw_shortcuts_section_add(self.to_glib_none().0, item.into_glib_ptr());
        }
    }

    #[doc(alias = "adw_shortcuts_section_get_title")]
    #[doc(alias = "get_title")]
    pub fn title(&self) -> Option<glib::GString> {
        unsafe { from_glib_none(ffi::adw_shortcuts_section_get_title(self.to_glib_none().0)) }
    }

    #[doc(alias = "adw_shortcuts_section_set_title")]
    #[doc(alias = "title")]
    pub fn set_title(&self, title: Option<&str>) {
        unsafe {
            ffi::adw_shortcuts_section_set_title(self.to_glib_none().0, title.to_glib_none().0);
        }
    }

    #[cfg(feature = "v1_8")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_8")))]
    #[doc(alias = "title")]
    pub fn connect_title_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_title_trampoline<F: Fn(&ShortcutsSection) + 'static>(
            this: *mut ffi::AdwShortcutsSection,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            unsafe {
                let f: &F = &*(f as *const F);
                f(&from_glib_borrow(this))
            }
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"notify::title".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_title_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}