libhelium 0.12.0

Rust bindings for libhelium
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::{connect_raw, SignalHandlerId},
    translate::*,
};
use std::boxed::Box as Box_;

glib::wrapper! {
    #[doc(alias = "HeTip")]
    pub struct Tip(Object<ffi::HeTip, ffi::HeTipClass>);

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

impl Tip {
    pub const NONE: Option<&'static Tip> = None;

    #[doc(alias = "he_tip_new")]
    pub fn new(
        title: &str,
        image: Option<&str>,
        message: Option<&str>,
        action_label: Option<&str>,
    ) -> Tip {
        assert_initialized_main_thread!();
        unsafe {
            from_glib_full(ffi::he_tip_new(
                title.to_glib_none().0,
                image.to_glib_none().0,
                message.to_glib_none().0,
                action_label.to_glib_none().0,
            ))
        }
    }

    // rustdoc-stripper-ignore-next
    /// Creates a new builder-pattern struct instance to construct [`Tip`] objects.
    ///
    /// This method returns an instance of [`TipBuilder`](crate::builders::TipBuilder) which can be used to create [`Tip`] objects.
    pub fn builder() -> TipBuilder {
        TipBuilder::new()
    }
}

impl Default for Tip {
    fn default() -> Self {
        glib::object::Object::new::<Self>()
    }
}

// rustdoc-stripper-ignore-next
/// A [builder-pattern] type to construct [`Tip`] objects.
///
/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
#[must_use = "The builder must be built to be used"]
pub struct TipBuilder {
    builder: glib::object::ObjectBuilder<'static, Tip>,
}

impl TipBuilder {
    fn new() -> Self {
        Self {
            builder: glib::object::Object::builder(),
        }
    }

    pub fn title(self, title: impl Into<glib::GString>) -> Self {
        Self {
            builder: self.builder.property("title", title.into()),
        }
    }

    pub fn image(self, image: impl Into<glib::GString>) -> Self {
        Self {
            builder: self.builder.property("image", image.into()),
        }
    }

    pub fn message(self, message: impl Into<glib::GString>) -> Self {
        Self {
            builder: self.builder.property("message", message.into()),
        }
    }

    pub fn action_label(self, action_label: impl Into<glib::GString>) -> Self {
        Self {
            builder: self.builder.property("action-label", action_label.into()),
        }
    }

    // rustdoc-stripper-ignore-next
    /// Build the [`Tip`].
    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
    pub fn build(self) -> Tip {
        assert_initialized_main_thread!();
        self.builder.build()
    }
}

pub trait TipExt: IsA<Tip> + 'static {
    #[doc(alias = "he_tip_get_title")]
    #[doc(alias = "get_title")]
    fn title(&self) -> glib::GString {
        unsafe { from_glib_none(ffi::he_tip_get_title(self.as_ref().to_glib_none().0)) }
    }

    #[doc(alias = "he_tip_set_title")]
    fn set_title(&self, value: &str) {
        unsafe {
            ffi::he_tip_set_title(self.as_ref().to_glib_none().0, value.to_glib_none().0);
        }
    }

    #[doc(alias = "he_tip_get_image")]
    #[doc(alias = "get_image")]
    fn image(&self) -> glib::GString {
        unsafe { from_glib_none(ffi::he_tip_get_image(self.as_ref().to_glib_none().0)) }
    }

    #[doc(alias = "he_tip_set_image")]
    fn set_image(&self, value: &str) {
        unsafe {
            ffi::he_tip_set_image(self.as_ref().to_glib_none().0, value.to_glib_none().0);
        }
    }

    #[doc(alias = "he_tip_get_message")]
    #[doc(alias = "get_message")]
    fn message(&self) -> glib::GString {
        unsafe { from_glib_none(ffi::he_tip_get_message(self.as_ref().to_glib_none().0)) }
    }

    #[doc(alias = "he_tip_set_message")]
    fn set_message(&self, value: &str) {
        unsafe {
            ffi::he_tip_set_message(self.as_ref().to_glib_none().0, value.to_glib_none().0);
        }
    }

    #[doc(alias = "he_tip_get_action_label")]
    #[doc(alias = "get_action_label")]
    fn action_label(&self) -> glib::GString {
        unsafe { from_glib_none(ffi::he_tip_get_action_label(self.as_ref().to_glib_none().0)) }
    }

    #[doc(alias = "he_tip_set_action_label")]
    fn set_action_label(&self, value: &str) {
        unsafe {
            ffi::he_tip_set_action_label(self.as_ref().to_glib_none().0, value.to_glib_none().0);
        }
    }

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

    #[doc(alias = "image")]
    fn connect_image_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_image_trampoline<P: IsA<Tip>, F: Fn(&P) + 'static>(
            this: *mut ffi::HeTip,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Tip::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"notify::image".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_image_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "message")]
    fn connect_message_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_message_trampoline<P: IsA<Tip>, F: Fn(&P) + 'static>(
            this: *mut ffi::HeTip,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Tip::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"notify::message".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_message_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "action-label")]
    fn connect_action_label_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_action_label_trampoline<P: IsA<Tip>, F: Fn(&P) + 'static>(
            this: *mut ffi::HeTip,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Tip::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"notify::action-label".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_action_label_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl<O: IsA<Tip>> TipExt for O {}