use crate::core::animation::base::Node;
use crate::core::animation::tween::{Signal, Tweenable};
#[cfg(feature = "runtime")]
use kurbo::Affine;
use std::time::Duration;
#[cfg(feature = "runtime")]
use vello::Scene;
pub struct BindingNode<T, S>
where
T: Tweenable + PartialEq,
S: Tweenable + PartialEq,
{
source: Signal<S>,
target: Signal<T>,
mapper: Box<dyn Fn(S) -> T + Send + Sync + 'static>,
}
impl<T, S> BindingNode<T, S>
where
T: Tweenable + PartialEq,
S: Tweenable + PartialEq,
{
pub fn new(
source: Signal<S>,
target: Signal<T>,
mapper: impl Fn(S) -> T + Send + Sync + 'static,
) -> Self {
Self {
source,
target,
mapper: Box::new(mapper),
}
}
}
impl<T, S> Node for BindingNode<T, S>
where
T: Tweenable + PartialEq,
S: Tweenable + PartialEq,
{
#[cfg(feature = "runtime")]
fn render(&self, _scene: &mut Scene, _transform: Affine, _opacity: f32) {
}
fn update(&mut self, _dt: Duration) {
let source_val = self.source.get();
let mapped_val = (self.mapper)(source_val);
self.target.set(mapped_val);
}
fn state_hash(&self) -> u64 {
0
}
fn clone_node(&self) -> Box<dyn Node> {
panic!("BindingNode cloning is not implemented");
}
fn reset(&mut self) {
}
}