use crate::{ffi, Animation, AnimationState, AnimationTarget, SpringParams};
use glib::{
prelude::*,
signal::{connect_raw, SignalHandlerId},
translate::*,
};
use std::boxed::Box as Box_;
glib::wrapper! {
#[doc(alias = "HeSpringAnimation")]
pub struct SpringAnimation(Object<ffi::HeSpringAnimation, ffi::HeSpringAnimationClass>) @extends Animation;
match fn {
type_ => || ffi::he_spring_animation_get_type(),
}
}
impl SpringAnimation {
pub const NONE: Option<&'static SpringAnimation> = None;
#[doc(alias = "he_spring_animation_new")]
pub fn new(
widget: &impl IsA<gtk::Widget>,
from: f64,
to: f64,
sparams: impl IsA<SpringParams>,
target: impl IsA<AnimationTarget>,
) -> SpringAnimation {
skip_assert_initialized!();
unsafe {
from_glib_full(ffi::he_spring_animation_new(
widget.as_ref().to_glib_none().0,
from,
to,
sparams.upcast().into_glib_ptr(),
target.upcast().into_glib_ptr(),
))
}
}
pub fn builder() -> SpringAnimationBuilder {
SpringAnimationBuilder::new()
}
}
impl Default for SpringAnimation {
fn default() -> Self {
glib::object::Object::new::<Self>()
}
}
#[must_use = "The builder must be built to be used"]
pub struct SpringAnimationBuilder {
builder: glib::object::ObjectBuilder<'static, SpringAnimation>,
}
impl SpringAnimationBuilder {
fn new() -> Self {
Self {
builder: glib::object::Object::builder(),
}
}
pub fn epsilon(self, epsilon: f64) -> Self {
Self {
builder: self.builder.property("epsilon", epsilon),
}
}
pub fn estimated_duration(self, estimated_duration: u32) -> Self {
Self {
builder: self
.builder
.property("estimated-duration", estimated_duration),
}
}
pub fn initial_velocity(self, initial_velocity: f64) -> Self {
Self {
builder: self.builder.property("initial-velocity", initial_velocity),
}
}
pub fn latch(self, latch: bool) -> Self {
Self {
builder: self.builder.property("latch", latch),
}
}
pub fn spring_params(self, spring_params: &impl IsA<SpringParams>) -> Self {
Self {
builder: self
.builder
.property("spring-params", spring_params.clone().upcast()),
}
}
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 velocity(self, velocity: f64) -> Self {
Self {
builder: self.builder.property("velocity", velocity),
}
}
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) -> SpringAnimation {
self.builder.build()
}
}
mod sealed {
pub trait Sealed {}
impl<T: super::IsA<super::SpringAnimation>> Sealed for T {}
}
pub trait SpringAnimationExt: IsA<SpringAnimation> + sealed::Sealed + 'static {
#[doc(alias = "he_spring_animation_get_epsilon")]
#[doc(alias = "get_epsilon")]
fn epsilon(&self) -> f64 {
unsafe { ffi::he_spring_animation_get_epsilon(self.as_ref().to_glib_none().0) }
}
#[doc(alias = "he_spring_animation_set_epsilon")]
fn set_epsilon(&self, value: f64) {
unsafe {
ffi::he_spring_animation_set_epsilon(self.as_ref().to_glib_none().0, value);
}
}
#[doc(alias = "he_spring_animation_get_estimated_duration")]
#[doc(alias = "get_estimated_duration")]
fn estimated_duration(&self) -> u32 {
unsafe { ffi::he_spring_animation_get_estimated_duration(self.as_ref().to_glib_none().0) }
}
#[doc(alias = "he_spring_animation_set_estimated_duration")]
fn set_estimated_duration(&self, value: u32) {
unsafe {
ffi::he_spring_animation_set_estimated_duration(self.as_ref().to_glib_none().0, value);
}
}
#[doc(alias = "he_spring_animation_get_initial_velocity")]
#[doc(alias = "get_initial_velocity")]
fn initial_velocity(&self) -> f64 {
unsafe { ffi::he_spring_animation_get_initial_velocity(self.as_ref().to_glib_none().0) }
}
#[doc(alias = "he_spring_animation_set_initial_velocity")]
fn set_initial_velocity(&self, value: f64) {
unsafe {
ffi::he_spring_animation_set_initial_velocity(self.as_ref().to_glib_none().0, value);
}
}
#[doc(alias = "he_spring_animation_get_latch")]
#[doc(alias = "get_latch")]
fn is_latch(&self) -> bool {
unsafe {
from_glib(ffi::he_spring_animation_get_latch(
self.as_ref().to_glib_none().0,
))
}
}
#[doc(alias = "he_spring_animation_set_latch")]
fn set_latch(&self, value: bool) {
unsafe {
ffi::he_spring_animation_set_latch(self.as_ref().to_glib_none().0, value.into_glib());
}
}
#[doc(alias = "he_spring_animation_get_spring_params")]
#[doc(alias = "get_spring_params")]
fn spring_params(&self) -> SpringParams {
unsafe {
from_glib_none(ffi::he_spring_animation_get_spring_params(
self.as_ref().to_glib_none().0,
))
}
}
#[doc(alias = "he_spring_animation_set_spring_params")]
fn set_spring_params(&self, value: &impl IsA<SpringParams>) {
unsafe {
ffi::he_spring_animation_set_spring_params(
self.as_ref().to_glib_none().0,
value.as_ref().to_glib_none().0,
);
}
}
#[doc(alias = "he_spring_animation_get_value_from")]
#[doc(alias = "get_value_from")]
fn value_from(&self) -> f64 {
unsafe { ffi::he_spring_animation_get_value_from(self.as_ref().to_glib_none().0) }
}
#[doc(alias = "he_spring_animation_set_value_from")]
fn set_value_from(&self, value: f64) {
unsafe {
ffi::he_spring_animation_set_value_from(self.as_ref().to_glib_none().0, value);
}
}
#[doc(alias = "he_spring_animation_get_value_to")]
#[doc(alias = "get_value_to")]
fn value_to(&self) -> f64 {
unsafe { ffi::he_spring_animation_get_value_to(self.as_ref().to_glib_none().0) }
}
#[doc(alias = "he_spring_animation_set_value_to")]
fn set_value_to(&self, value: f64) {
unsafe {
ffi::he_spring_animation_set_value_to(self.as_ref().to_glib_none().0, value);
}
}
#[doc(alias = "he_spring_animation_get_velocity")]
#[doc(alias = "get_velocity")]
fn velocity(&self) -> f64 {
unsafe { ffi::he_spring_animation_get_velocity(self.as_ref().to_glib_none().0) }
}
#[doc(alias = "he_spring_animation_set_velocity")]
fn set_velocity(&self, value: f64) {
unsafe {
ffi::he_spring_animation_set_velocity(self.as_ref().to_glib_none().0, value);
}
}
#[doc(alias = "epsilon")]
fn connect_epsilon_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_epsilon_trampoline<
P: IsA<SpringAnimation>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::HeSpringAnimation,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(SpringAnimation::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::epsilon\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_epsilon_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "estimated-duration")]
fn connect_estimated_duration_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_estimated_duration_trampoline<
P: IsA<SpringAnimation>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::HeSpringAnimation,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(SpringAnimation::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::estimated-duration\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_estimated_duration_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "initial-velocity")]
fn connect_initial_velocity_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_initial_velocity_trampoline<
P: IsA<SpringAnimation>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::HeSpringAnimation,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(SpringAnimation::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::initial-velocity\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_initial_velocity_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "latch")]
fn connect_latch_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_latch_trampoline<
P: IsA<SpringAnimation>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::HeSpringAnimation,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(SpringAnimation::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::latch\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_latch_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "spring-params")]
fn connect_spring_params_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_spring_params_trampoline<
P: IsA<SpringAnimation>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::HeSpringAnimation,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(SpringAnimation::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::spring-params\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_spring_params_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[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<SpringAnimation>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::HeSpringAnimation,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(SpringAnimation::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<SpringAnimation>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::HeSpringAnimation,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(SpringAnimation::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 = "velocity")]
fn connect_velocity_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_velocity_trampoline<
P: IsA<SpringAnimation>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::HeSpringAnimation,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(SpringAnimation::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::velocity\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_velocity_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}
impl<O: IsA<SpringAnimation>> SpringAnimationExt for O {}