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,
))
}
}
pub fn builder() -> TipBuilder {
TipBuilder::new()
}
}
impl Default for Tip {
fn default() -> Self {
glib::object::Object::new::<Self>()
}
}
#[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()),
}
}
#[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
pub fn build(self) -> Tip {
self.builder.build()
}
}
mod sealed {
pub trait Sealed {}
impl<T: super::IsA<super::Tip>> Sealed for T {}
}
pub trait TipExt: IsA<Tip> + sealed::Sealed + '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 _,
b"notify::title\0".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 _,
b"notify::image\0".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 _,
b"notify::message\0".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 _,
b"notify::action-label\0".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 {}