Added rsx iteration

This commit is contained in:
2025-08-12 23:40:56 -04:00
parent fde8ad17d6
commit 9a03f241d8
3 changed files with 27 additions and 22 deletions
+8 -22
View File
@@ -21,26 +21,12 @@ pub fn app() -> Rsx {
} }
}); });
Rsx(vec![RsxElement::Element( rsx! {
StaticWidget::new(Box::new(FlexRow::new())), FlexRow {
Rsx(vec![RsxElement::Iter( for item in items {
Box::new({ static "{item}"
let items = items.clone(); static "Idk {item}"
move || { }
Rsx(items }
.get_dl() }
.iter()
.enumerate()
.map(|(i, _)| {
RsxElement::Element(
StaticWidget::new(Box::new(format!("Item {i}"))),
Rsx(vec![]),
)
})
.collect())
}
}),
Box::new(items),
)]),
)])
} }
+5
View File
@@ -164,4 +164,9 @@ impl Rsx {
pub fn expand(&mut self, other: &mut Rsx) { pub fn expand(&mut self, other: &mut Rsx) {
self.0.append(&mut other.0); 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);
}
} }
+14
View File
@@ -240,6 +240,20 @@ macro_rules! rsx {
/// Would produce a nested `Rsx` tree of static and dynamic widgets. /// Would produce a nested `Rsx` tree of static and dynamic widgets.
#[macro_export] #[macro_export]
macro_rules! rsx_inner { 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 // static
($r:expr, $(@$comp:expr;)* static $s:literal $($rest:tt)*) => { ($r:expr, $(@$comp:expr;)* static $s:literal $($rest:tt)*) => {
let w = $crate::widget::StaticWidget::new(Box::new(format!($s))); let w = $crate::widget::StaticWidget::new(Box::new(format!($s)));