Added rsx iteration
This commit is contained in:
+8
-22
@@ -21,26 +21,12 @@ pub fn app() -> Rsx {
|
||||
}
|
||||
});
|
||||
|
||||
Rsx(vec![RsxElement::Element(
|
||||
StaticWidget::new(Box::new(FlexRow::new())),
|
||||
Rsx(vec![RsxElement::Iter(
|
||||
Box::new({
|
||||
let items = items.clone();
|
||||
move || {
|
||||
Rsx(items
|
||||
.get_dl()
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, _)| {
|
||||
RsxElement::Element(
|
||||
StaticWidget::new(Box::new(format!("Item {i}"))),
|
||||
Rsx(vec![]),
|
||||
)
|
||||
})
|
||||
.collect())
|
||||
}
|
||||
}),
|
||||
Box::new(items),
|
||||
)]),
|
||||
)])
|
||||
rsx! {
|
||||
FlexRow {
|
||||
for item in items {
|
||||
static "{item}"
|
||||
static "Idk {item}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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