use glib::{prelude::*,signal::{connect_raw, SignalHandlerId},translate::*};
use std::{boxed::Box as Box_};
glib::wrapper! {
#[doc(alias = "WpTransition")]
pub struct Transition(Object<ffi::WpTransition, ffi::WpTransitionClass>) @implements gio::AsyncResult;
match fn {
type_ => || ffi::wp_transition_get_type(),
}
}
impl Transition {
pub const NONE: Option<&'static Transition> = None;
#[doc(alias = "wp_transition_new_closure")]
pub fn new_closure(type_: glib::types::Type, source_object: Option<&impl IsA<glib::Object>>, cancellable: Option<&impl IsA<gio::Cancellable>>, closure: Option<&glib::Closure>) -> Transition {
unsafe {
from_glib_none(ffi::wp_transition_new_closure(type_.into_glib(), source_object.map(|p| p.as_ref()).to_glib_none().0, cancellable.map(|p| p.as_ref()).to_glib_none().0, closure.to_glib_none().0))
}
}
#[doc(alias = "wp_transition_finish")]
pub fn finish(res: &impl IsA<gio::AsyncResult>) -> Result<(), glib::Error> {
unsafe {
let mut error = std::ptr::null_mut();
let is_ok = ffi::wp_transition_finish(res.as_ref().to_glib_none().0, &mut error);
debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
if error.is_null() { Ok(()) } else { Err(from_glib_full(error)) }
}
}
}
mod sealed {
pub trait Sealed {}
impl<T: super::IsA<super::Transition>> Sealed for T {}
}
pub trait TransitionExt: IsA<Transition> + sealed::Sealed + 'static {
#[doc(alias = "wp_transition_advance")]
fn advance(&self) {
unsafe {
ffi::wp_transition_advance(self.as_ref().to_glib_none().0);
}
}
#[doc(alias = "wp_transition_get_completed")]
#[doc(alias = "get_completed")]
fn is_completed(&self) -> bool {
unsafe {
from_glib(ffi::wp_transition_get_completed(self.as_ref().to_glib_none().0))
}
}
#[doc(alias = "wp_transition_get_source_object")]
#[doc(alias = "get_source_object")]
fn source_object(&self) -> Option<glib::Object> {
unsafe {
from_glib_none(ffi::wp_transition_get_source_object(self.as_ref().to_glib_none().0))
}
}
#[doc(alias = "wp_transition_had_error")]
fn had_error(&self) -> bool {
unsafe {
from_glib(ffi::wp_transition_had_error(self.as_ref().to_glib_none().0))
}
}
#[doc(alias = "completed")]
fn connect_completed_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_completed_trampoline<P: IsA<Transition>, F: Fn(&P) + 'static>(this: *mut ffi::WpTransition, _param_spec: glib::ffi::gpointer, f: glib::ffi::gpointer) {
let f: &F = &*(f as *const F);
f(Transition::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(self.as_ptr() as *mut _, b"notify::completed\0".as_ptr() as *const _,
Some(std::mem::transmute::<_, unsafe extern "C" fn()>(notify_completed_trampoline::<Self, F> as *const ())), Box_::into_raw(f))
}
}
}
impl<O: IsA<Transition>> TransitionExt for O {}