use std::ops::Deref;
use oxframe_core::{Seconds, Signal, Tween, Vec2};
pub trait IntoScale {
fn into_scale(self) -> Vec2;
}
impl IntoScale for f64 {
fn into_scale(self) -> Vec2 {
Vec2::new(self, self)
}
}
impl IntoScale for i32 {
fn into_scale(self) -> Vec2 {
f64::from(self).into_scale()
}
}
impl IntoScale for (f64, f64) {
fn into_scale(self) -> Vec2 {
Vec2::new(self.0, self.1)
}
}
impl IntoScale for [f64; 2] {
fn into_scale(self) -> Vec2 {
Vec2::new(self[0], self[1])
}
}
impl IntoScale for Vec2 {
fn into_scale(self) -> Vec2 {
self
}
}
#[derive(Clone)]
pub struct ScaleSignal(pub(crate) Signal<Vec2>);
impl ScaleSignal {
pub fn to(&self, target: impl IntoScale, duration: impl Seconds) -> Tween<Vec2> {
self.0.to(target.into_scale(), duration)
}
pub fn set(&self, value: impl IntoScale) {
self.0.set(value.into_scale());
}
pub fn signal(&self) -> Signal<Vec2> {
self.0.clone()
}
}
impl Deref for ScaleSignal {
type Target = Signal<Vec2>;
fn deref(&self) -> &Signal<Vec2> {
&self.0
}
}
impl From<ScaleSignal> for Signal<Vec2> {
fn from(s: ScaleSignal) -> Self {
s.0
}
}