libadwaita 0.1.0-beta-1

Rust bindings for libadwaita
// 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::AnimationState;
use crate::AnimationTarget;
use glib::object::Cast;
use glib::object::IsA;
use glib::signal::connect_raw;
use glib::signal::SignalHandlerId;
use glib::translate::*;
use glib::StaticType;
use glib::ToValue;
use std::boxed::Box as Box_;
use std::fmt;
use std::mem::transmute;

glib::wrapper! {
    #[doc(alias = "AdwAnimation")]
    pub struct Animation(Object<ffi::AdwAnimation, ffi::AdwAnimationClass>);

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

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

#[derive(Clone, Default)]
// rustdoc-stripper-ignore-next
/// A [builder-pattern] type to construct [`Animation`] objects.
///
/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
pub struct AnimationBuilder {
    target: Option<AnimationTarget>,
    widget: Option<gtk::Widget>,
}

impl AnimationBuilder {
    // rustdoc-stripper-ignore-next
    /// Create a new [`AnimationBuilder`].
    pub fn new() -> Self {
        Self::default()
    }

    // rustdoc-stripper-ignore-next
    /// Build the [`Animation`].
    pub fn build(self) -> Animation {
        let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
        if let Some(ref target) = self.target {
            properties.push(("target", target));
        }
        if let Some(ref widget) = self.widget {
            properties.push(("widget", widget));
        }
        glib::Object::new::<Animation>(&properties)
            .expect("Failed to create an instance of Animation")
    }

    pub fn target<P: IsA<AnimationTarget>>(mut self, target: &P) -> Self {
        self.target = Some(target.clone().upcast());
        self
    }

    pub fn widget<P: IsA<gtk::Widget>>(mut self, widget: &P) -> Self {
        self.widget = Some(widget.clone().upcast());
        self
    }
}

pub const NONE_ANIMATION: Option<&Animation> = None;

pub trait AnimationExt: 'static {
    #[doc(alias = "adw_animation_get_state")]
    #[doc(alias = "get_state")]
    fn state(&self) -> AnimationState;

    #[doc(alias = "adw_animation_get_target")]
    #[doc(alias = "get_target")]
    fn target(&self) -> Option<AnimationTarget>;

    #[doc(alias = "adw_animation_get_value")]
    #[doc(alias = "get_value")]
    fn value(&self) -> f64;

    #[doc(alias = "adw_animation_get_widget")]
    #[doc(alias = "get_widget")]
    fn widget(&self) -> Option<gtk::Widget>;

    #[doc(alias = "adw_animation_pause")]
    fn pause(&self);

    #[doc(alias = "adw_animation_play")]
    fn play(&self);

    #[doc(alias = "adw_animation_reset")]
    fn reset(&self);

    #[doc(alias = "adw_animation_resume")]
    fn resume(&self);

    #[doc(alias = "adw_animation_skip")]
    fn skip(&self);

    fn set_target<P: IsA<AnimationTarget>>(&self, target: Option<&P>);

    #[doc(alias = "done")]
    fn connect_done<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;

    #[doc(alias = "state")]
    fn connect_state_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;

    #[doc(alias = "target")]
    fn connect_target_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;

    #[doc(alias = "value")]
    fn connect_value_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
}

impl<O: IsA<Animation>> AnimationExt for O {
    fn state(&self) -> AnimationState {
        unsafe { from_glib(ffi::adw_animation_get_state(self.as_ref().to_glib_none().0)) }
    }

    fn target(&self) -> Option<AnimationTarget> {
        unsafe {
            from_glib_none(ffi::adw_animation_get_target(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn value(&self) -> f64 {
        unsafe { ffi::adw_animation_get_value(self.as_ref().to_glib_none().0) }
    }

    fn widget(&self) -> Option<gtk::Widget> {
        unsafe {
            from_glib_none(ffi::adw_animation_get_widget(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn pause(&self) {
        unsafe {
            ffi::adw_animation_pause(self.as_ref().to_glib_none().0);
        }
    }

    fn play(&self) {
        unsafe {
            ffi::adw_animation_play(self.as_ref().to_glib_none().0);
        }
    }

    fn reset(&self) {
        unsafe {
            ffi::adw_animation_reset(self.as_ref().to_glib_none().0);
        }
    }

    fn resume(&self) {
        unsafe {
            ffi::adw_animation_resume(self.as_ref().to_glib_none().0);
        }
    }

    fn skip(&self) {
        unsafe {
            ffi::adw_animation_skip(self.as_ref().to_glib_none().0);
        }
    }

    fn set_target<P: IsA<AnimationTarget>>(&self, target: Option<&P>) {
        unsafe {
            glib::gobject_ffi::g_object_set_property(
                self.to_glib_none().0 as *mut glib::gobject_ffi::GObject,
                b"target\0".as_ptr() as *const _,
                target.to_value().to_glib_none().0,
            );
        }
    }

    fn connect_done<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn done_trampoline<P: IsA<Animation>, F: Fn(&P) + 'static>(
            this: *mut ffi::AdwAnimation,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Animation::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"done\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    done_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_state_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_state_trampoline<P: IsA<Animation>, F: Fn(&P) + 'static>(
            this: *mut ffi::AdwAnimation,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Animation::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::state\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_state_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_target_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_target_trampoline<P: IsA<Animation>, F: Fn(&P) + 'static>(
            this: *mut ffi::AdwAnimation,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Animation::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::target\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_target_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_value_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_value_trampoline<P: IsA<Animation>, F: Fn(&P) + 'static>(
            this: *mut ffi::AdwAnimation,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Animation::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::value\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_value_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl fmt::Display for Animation {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.write_str("Animation")
    }
}