Files
osui/src/macros.rs
T
2024-10-15 13:20:04 +02:00

32 lines
893 B
Rust

#[macro_export]
macro_rules! __oml {
($( ($tag:ident $($k:ident = $v:expr)*) {$($inner:tt)*} )+) => {{
let mut comps: Vec<Box<dyn Component>> = Vec::new();
$(
// comps.push(Box::new($tag(ComponentParams { children: osui::__oml!($($inner)*) })));
comps.push(oml!(($tag $($k = $v)*) {$($inner)*}));
)*
comps
}};
() => { Vec::new() };
}
#[macro_export]
macro_rules! oml {
( ($tag:ident) {} ) => {
Box::new($tag(ComponentParams { children: Vec::new() }))
};
( ($tag:ident) {$($inner:tt)*} ) => {
Box::new($tag(ComponentParams { children: osui::__oml!($($inner)*) }))
};
( ($tag:ident $($k:ident = $v:expr)+ ) {$($inner:tt)*} ) => {{
let mut c = $tag(ComponentParams { children: osui::__oml!($($inner)*) });
$(
c.$k = $v;
)+
Box::new(c)
}};
}