pub mod core;
pub mod prim;
pub mod list;
pub mod animate;
pub use crate::core::{
Link,
LinkTrait,
EventGraph,
ProcessingContext,
};
pub use crate::prim::{
Prim,
HistPrim,
};
pub use crate::list::{
List,
};
pub use crate::animate::{
Animator,
HistPrimEaseExt,
};
pub use paste;
#[macro_export]
macro_rules! link{
(
//. .
($pcname: ident = $pcval: expr),
($($input_name: ident = $input_val: expr), * $(,) ?),
($($output_name: ident = $output_val: expr), * $(,) ?),
($($name: ident = $val: expr), * $(,) ?) $(,) ?
$body: block) => {
$crate:: paste:: paste ! {
{
struct _Link <
$([< _ $input_name: upper >],) *
$([< _ $output_name: upper >],) *
$([< _ $name: upper >],) *
> {
$([< _ $input_name >]:[< _ $input_name: upper >],) *
$([< _ $output_name >]:[< _ $output_name: upper >],) *
$([< _ $name >]:[< _ $name: upper >],) *
f: fn(& mut $crate:: core:: ProcessingContext,
//. .
$(&[< _ $input_name: upper >],) *
//. .
$(&[< _ $output_name: upper >],) *
//. .
$(&[< _ $name: upper >],) *) -> Option <() >,
}
impl <
$([< _ $input_name: upper >]: Clone,) *
$([< _ $output_name: upper >]: Clone + $crate:: core:: IntoValue,) *
$([< _ $name: upper >],) *
> $crate:: core:: LinkTrait for _Link <
$([< _ $input_name: upper >],) *
$([< _ $output_name: upper >],) *
$([< _ $name: upper >],) *
> {
fn call(&self, pc:& mut $crate:: core:: ProcessingContext) {
(self.f)(pc,
$(& self.[< _ $input_name >],) *
$(& self.[< _ $output_name >],) *
$(& self.[< _ $name >],) *);
}
fn next_values(&self) -> std:: vec:: Vec < $crate:: core:: Value > {
return vec![
$(< dyn $crate:: core:: IntoValue >:: into_value(& self.[< _ $output_name >]),) *
];
}
}
$(let[< _ $input_name >] = $input_val;) *
let out = $crate:: Link:: new($pcval, _Link {
$([< _ $input_name >]:[< _ $input_name >].clone(),) *
$([< _ $output_name >]: $output_val,) *
$([< _ $name >]: $val,) *
f:| $pcname,
$($input_name,) *
$($output_name,) *
$($name,) *
|-> Option <() > {
$body;
return None;
}
});
$([< _ $input_name >].add_next(&out);) *
out
}
}
};
}
#[test]
fn basic0() {
use crate::{
core::{
Value,
},
prim::{
WeakPrim,
},
};
let eg = EventGraph::new();
let mut store_a = None;
let mut store_b = None;
let mut store_link = None;
eg.event(|pc| {
let a = Prim::new(0);
let b = Prim::new(0);
struct LinkAB {
a: WeakPrim<i32>,
value: Prim<i32>,
}
impl LinkTrait for LinkAB {
fn call(&self, pc: &mut ProcessingContext) {
let Some(a) = self.a.upgrade() else {
return;
};
self.value.set(pc, *a.borrow() + 5);
}
fn next_values(&self) -> Vec<Value> {
return vec![Value(self.value.0.clone())];
}
}
let _link = Link::new(pc, LinkAB {
a: a.weak(),
value: b.clone(),
});
a.set(pc, 46);
store_a = Some(a);
store_b = Some(b);
store_link = Some(_link);
});
assert_eq!(*store_b.unwrap().borrow(), 51);
}