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::ffi;
use glib::{
    prelude::*,
    signal::{SignalHandlerId, connect_raw},
    translate::*,
};
use std::boxed::Box as Box_;

glib::wrapper! {
    #[doc(alias = "AdwShortcutsItem")]
    pub struct ShortcutsItem(Object<ffi::AdwShortcutsItem, ffi::AdwShortcutsItemClass>);

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

impl ShortcutsItem {
    #[doc(alias = "adw_shortcuts_item_new")]
    pub fn new(title: &str, accelerator: &str) -> ShortcutsItem {
        assert_initialized_main_thread!();
        unsafe {
            from_glib_full(ffi::adw_shortcuts_item_new(
                title.to_glib_none().0,
                accelerator.to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "adw_shortcuts_item_new_from_action")]
    #[doc(alias = "new_from_action")]
    pub fn from_action(title: &str, action_name: &str) -> ShortcutsItem {
        assert_initialized_main_thread!();
        unsafe {
            from_glib_full(ffi::adw_shortcuts_item_new_from_action(
                title.to_glib_none().0,
                action_name.to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "adw_shortcuts_item_get_accelerator")]
    #[doc(alias = "get_accelerator")]
    pub fn accelerator(&self) -> glib::GString {
        unsafe {
            from_glib_none(ffi::adw_shortcuts_item_get_accelerator(
                self.to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "adw_shortcuts_item_get_action_name")]
    #[doc(alias = "get_action_name")]
    #[doc(alias = "action-name")]
    pub fn action_name(&self) -> glib::GString {
        unsafe {
            from_glib_none(ffi::adw_shortcuts_item_get_action_name(
                self.to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "adw_shortcuts_item_get_direction")]
    #[doc(alias = "get_direction")]
    pub fn direction(&self) -> gtk::TextDirection {
        unsafe { from_glib(ffi::adw_shortcuts_item_get_direction(self.to_glib_none().0)) }
    }

    #[doc(alias = "adw_shortcuts_item_get_subtitle")]
    #[doc(alias = "get_subtitle")]
    pub fn subtitle(&self) -> glib::GString {
        unsafe { from_glib_none(ffi::adw_shortcuts_item_get_subtitle(self.to_glib_none().0)) }
    }

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

    #[doc(alias = "adw_shortcuts_item_set_accelerator")]
    #[doc(alias = "accelerator")]
    pub fn set_accelerator(&self, accelerator: &str) {
        unsafe {
            ffi::adw_shortcuts_item_set_accelerator(
                self.to_glib_none().0,
                accelerator.to_glib_none().0,
            );
        }
    }

    #[doc(alias = "adw_shortcuts_item_set_action_name")]
    #[doc(alias = "action-name")]
    pub fn set_action_name(&self, action_name: &str) {
        unsafe {
            ffi::adw_shortcuts_item_set_action_name(
                self.to_glib_none().0,
                action_name.to_glib_none().0,
            );
        }
    }

    #[doc(alias = "adw_shortcuts_item_set_direction")]
    #[doc(alias = "direction")]
    pub fn set_direction(&self, direction: gtk::TextDirection) {
        unsafe {
            ffi::adw_shortcuts_item_set_direction(self.to_glib_none().0, direction.into_glib());
        }
    }

    #[doc(alias = "adw_shortcuts_item_set_subtitle")]
    #[doc(alias = "subtitle")]
    pub fn set_subtitle(&self, subtitle: &str) {
        unsafe {
            ffi::adw_shortcuts_item_set_subtitle(self.to_glib_none().0, subtitle.to_glib_none().0);
        }
    }

    #[doc(alias = "adw_shortcuts_item_set_title")]
    #[doc(alias = "title")]
    pub fn set_title(&self, title: &str) {
        unsafe {
            ffi::adw_shortcuts_item_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 = "accelerator")]
    pub fn connect_accelerator_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_accelerator_trampoline<F: Fn(&ShortcutsItem) + 'static>(
            this: *mut ffi::AdwShortcutsItem,
            _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::accelerator".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_accelerator_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[cfg(feature = "v1_8")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_8")))]
    #[doc(alias = "action-name")]
    pub fn connect_action_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_action_name_trampoline<F: Fn(&ShortcutsItem) + 'static>(
            this: *mut ffi::AdwShortcutsItem,
            _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::action-name".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_action_name_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[cfg(feature = "v1_8")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_8")))]
    #[doc(alias = "direction")]
    pub fn connect_direction_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_direction_trampoline<F: Fn(&ShortcutsItem) + 'static>(
            this: *mut ffi::AdwShortcutsItem,
            _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::direction".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_direction_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[cfg(feature = "v1_8")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_8")))]
    #[doc(alias = "subtitle")]
    pub fn connect_subtitle_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_subtitle_trampoline<F: Fn(&ShortcutsItem) + 'static>(
            this: *mut ffi::AdwShortcutsItem,
            _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::subtitle".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_subtitle_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[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(&ShortcutsItem) + 'static>(
            this: *mut ffi::AdwShortcutsItem,
            _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),
            )
        }
    }
}