use crate::{ffi, Animation, AnimationState, AnimationTarget, Easing};
use glib::{
prelude::*,
signal::{connect_raw, SignalHandlerId},
translate::*,
};
use std::boxed::Box as Box_;
glib::wrapper! {
#[doc(alias = "HeTimedAnimation")]
pub struct TimedAnimation(Object<ffi::HeTimedAnimation, ffi::HeTimedAnimationClass>) @extends Animation;
match fn {
type_ => || ffi::he_timed_animation_get_type(),
}
}
impl TimedAnimation {
pub const NONE: Option<&'static TimedAnimation> = None;
#[doc(alias = "he_timed_animation_new")]
pub fn new(
widget: &impl IsA<gtk::Widget>,
from: f64,
to: f64,
duration: u32,
target: &impl IsA<AnimationTarget>,
) -> TimedAnimation {
skip_assert_initialized!();
unsafe {
from_glib_full(ffi::he_timed_animation_new(
widget.as_ref().to_glib_none().0,
from,
to,
duration,
target.as_ref().to_glib_none().0,
))
}
}
pub fn builder() -> TimedAnimationBuilder {
TimedAnimationBuilder::new()
}
}
impl Default for TimedAnimation {
fn default() -> Self {
glib::object::Object::new::<Self>()
}
}
#[must_use = "The builder must be built to be used"]
pub struct TimedAnimationBuilder {
builder: glib::object::ObjectBuilder<'static, TimedAnimation>,
}
impl TimedAnimationBuilder {
fn new() -> Self {
Self {
builder: glib::object::Object::builder(),
}
}
pub fn value_from(self, value_from: f64) -> Self {
Self {
builder: self.builder.property("value-from", value_from),
}
}
pub fn value_to(self, value_to: f64) -> Self {
Self {
builder: self.builder.property("value-to", value_to),
}
}
pub fn duration(self, duration: u32) -> Self {
Self {
builder: self.builder.property("duration", duration),
}
}
pub fn easing(self, easing: Easing) -> Self {
Self {
builder: self.builder.property("easing", easing),
}
}
pub fn repeat_count(self, repeat_count: u32) -> Self {
Self {
builder: self.builder.property("repeat-count", repeat_count),
}
}
pub fn reverse(self, reverse: bool) -> Self {
Self {
builder: self.builder.property("reverse", reverse),
}
}
pub fn alternate(self, alternate: bool) -> Self {
Self {
builder: self.builder.property("alternate", alternate),
}
}
pub fn state(self, state: AnimationState) -> Self {
Self {
builder: self.builder.property("state", state),
}
}
pub fn target(self, target: &impl IsA<AnimationTarget>) -> Self {
Self {
builder: self.builder.property("target", target.clone().upcast()),
}
}
pub fn widget(self, widget: &impl IsA<gtk::Widget>) -> Self {
Self {
builder: self.builder.property("widget", widget.clone().upcast()),
}
}
pub fn avalue(self, avalue: f64) -> Self {
Self {
builder: self.builder.property("avalue", avalue),
}
}
#[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
pub fn build(self) -> TimedAnimation {
self.builder.build()
}
}
mod sealed {
pub trait Sealed {}
impl<T: super::IsA<super::TimedAnimation>> Sealed for T {}
}
pub trait TimedAnimationExt: IsA<TimedAnimation> + sealed::Sealed + 'static {
#[doc(alias = "he_timed_animation_get_value_from")]
#[doc(alias = "get_value_from")]
fn value_from(&self) -> f64 {
unsafe { ffi::he_timed_animation_get_value_from(self.as_ref().to_glib_none().0) }
}
#[doc(alias = "he_timed_animation_set_value_from")]
fn set_value_from(&self, value: f64) {
unsafe {
ffi::he_timed_animation_set_value_from(self.as_ref().to_glib_none().0, value);
}
}
#[doc(alias = "he_timed_animation_get_value_to")]
#[doc(alias = "get_value_to")]
fn value_to(&self) -> f64 {
unsafe { ffi::he_timed_animation_get_value_to(self.as_ref().to_glib_none().0) }
}
#[doc(alias = "he_timed_animation_set_value_to")]
fn set_value_to(&self, value: f64) {
unsafe {
ffi::he_timed_animation_set_value_to(self.as_ref().to_glib_none().0, value);
}
}
#[doc(alias = "he_timed_animation_get_duration")]
#[doc(alias = "get_duration")]
fn duration(&self) -> u32 {
unsafe { ffi::he_timed_animation_get_duration(self.as_ref().to_glib_none().0) }
}
#[doc(alias = "he_timed_animation_set_duration")]
fn set_duration(&self, value: u32) {
unsafe {
ffi::he_timed_animation_set_duration(self.as_ref().to_glib_none().0, value);
}
}
#[doc(alias = "he_timed_animation_get_easing")]
#[doc(alias = "get_easing")]
fn easing(&self) -> Easing {
unsafe {
from_glib(ffi::he_timed_animation_get_easing(
self.as_ref().to_glib_none().0,
))
}
}
#[doc(alias = "he_timed_animation_set_easing")]
fn set_easing(&self, value: Easing) {
unsafe {
ffi::he_timed_animation_set_easing(self.as_ref().to_glib_none().0, value.into_glib());
}
}
#[doc(alias = "he_timed_animation_get_repeat_count")]
#[doc(alias = "get_repeat_count")]
fn repeat_count(&self) -> u32 {
unsafe { ffi::he_timed_animation_get_repeat_count(self.as_ref().to_glib_none().0) }
}
#[doc(alias = "he_timed_animation_set_repeat_count")]
fn set_repeat_count(&self, value: u32) {
unsafe {
ffi::he_timed_animation_set_repeat_count(self.as_ref().to_glib_none().0, value);
}
}
#[doc(alias = "he_timed_animation_get_reverse")]
#[doc(alias = "get_reverse")]
fn is_reverse(&self) -> bool {
unsafe {
from_glib(ffi::he_timed_animation_get_reverse(
self.as_ref().to_glib_none().0,
))
}
}
#[doc(alias = "he_timed_animation_set_reverse")]
fn set_reverse(&self, value: bool) {
unsafe {
ffi::he_timed_animation_set_reverse(self.as_ref().to_glib_none().0, value.into_glib());
}
}
#[doc(alias = "he_timed_animation_get_alternate")]
#[doc(alias = "get_alternate")]
fn is_alternate(&self) -> bool {
unsafe {
from_glib(ffi::he_timed_animation_get_alternate(
self.as_ref().to_glib_none().0,
))
}
}
#[doc(alias = "he_timed_animation_set_alternate")]
fn set_alternate(&self, value: bool) {
unsafe {
ffi::he_timed_animation_set_alternate(
self.as_ref().to_glib_none().0,
value.into_glib(),
);
}
}
#[doc(alias = "value-from")]
fn connect_value_from_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_value_from_trampoline<
P: IsA<TimedAnimation>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::HeTimedAnimation,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(TimedAnimation::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-from\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_value_from_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "value-to")]
fn connect_value_to_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_value_to_trampoline<
P: IsA<TimedAnimation>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::HeTimedAnimation,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(TimedAnimation::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-to\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_value_to_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "duration")]
fn connect_duration_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_duration_trampoline<
P: IsA<TimedAnimation>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::HeTimedAnimation,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(TimedAnimation::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::duration\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_duration_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "easing")]
fn connect_easing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_easing_trampoline<
P: IsA<TimedAnimation>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::HeTimedAnimation,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(TimedAnimation::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::easing\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_easing_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "repeat-count")]
fn connect_repeat_count_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_repeat_count_trampoline<
P: IsA<TimedAnimation>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::HeTimedAnimation,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(TimedAnimation::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::repeat-count\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_repeat_count_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "reverse")]
fn connect_reverse_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_reverse_trampoline<
P: IsA<TimedAnimation>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::HeTimedAnimation,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(TimedAnimation::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::reverse\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_reverse_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "alternate")]
fn connect_alternate_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_alternate_trampoline<
P: IsA<TimedAnimation>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::HeTimedAnimation,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(TimedAnimation::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::alternate\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_alternate_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}
impl<O: IsA<TimedAnimation>> TimedAnimationExt for O {}