Added rsx iteration
This commit is contained in:
@@ -164,4 +164,9 @@ impl Rsx {
|
||||
pub fn expand(&mut self, other: &mut Rsx) {
|
||||
self.0.append(&mut other.0);
|
||||
}
|
||||
|
||||
/// Appends the elements from another `Rsx` tree into this one. nr stands for no reference
|
||||
pub fn expand_nr(&mut self, mut other: Rsx) {
|
||||
self.0.append(&mut other.0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -240,6 +240,20 @@ macro_rules! rsx {
|
||||
/// Would produce a nested `Rsx` tree of static and dynamic widgets.
|
||||
#[macro_export]
|
||||
macro_rules! rsx_inner {
|
||||
// for loop (iter)
|
||||
($r:expr, for $n:ident in $state:ident { $($inner:tt)* } $($rest:tt)*) => {
|
||||
$r.iter({
|
||||
let $state = $state.clone();
|
||||
move || {
|
||||
let mut r = $crate::frontend::Rsx(Vec::new());
|
||||
for $n in $state.get().iter() {
|
||||
r.expand_nr($crate::rsx!{ $($inner)* });
|
||||
}
|
||||
r
|
||||
}}, Box::new($state));
|
||||
$crate::rsx_inner! { $r, $($rest)* };
|
||||
};
|
||||
|
||||
// static
|
||||
($r:expr, $(@$comp:expr;)* static $s:literal $($rest:tt)*) => {
|
||||
let w = $crate::widget::StaticWidget::new(Box::new(format!($s)));
|
||||
|
||||
Reference in New Issue
Block a user