1#[macro_export]
2macro_rules! preset {
3 ($name:ident ($img:ident, $($key:ident : $type:ty),*) {$( $body:stmt );* $(;)?}) => {
4 let $name = SiPreset::new(Box::new(|img, vals: HashMap<String, Box<dyn std::any::Any>>| {
5 $(
6 let $key = match vals.get(stringify!($key)) {
7 Some($key) => {
8 if $key.type_id() == std::any::TypeId::of::<$type>() {
10 $key.downcast_ref::<$type>().unwrap()
12 } else {
13 panic!("Expected type: {:?}\nFound type: {:?}", std::any::TypeId::of::<$type>(), $key.type_id());
14 }
15 }
16 None => panic!("No {} provided", stringify!($key))
17 };
18 )*;
19 let $img = img.clone();
20 $($body)*
21 }
22 ));
23 }
24}
25
26#[macro_export]
27macro_rules! anymap {
28 {$($key:ident : $val:expr),*} => {
29 {
30 let mut map = HashMap::new();
31 $(
32 map.insert(stringify!($key).to_string(), Box::new($val) as Box<dyn std::any::Any>);
33 )*
34 map
35 }
36 };
37}
38
39#[macro_export]
40macro_rules! render {
41 ($image:ident: $text:expr; $x:expr, $y:expr; "font" $font:expr, "scale" $scale:expr, "opts" $opts:expr, "color" $color:expr) => {
42 $image = $image.render_text($text, $scale, $x, $y, $color, $font, $opts);
43 };
44}