RSX For loop
This commit is contained in:
+4
-44
@@ -40,57 +40,17 @@ fn app(cx: &Arc<Context>) -> View {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// {
|
|
||||||
// cx.dyn_scope(
|
|
||||||
// {
|
|
||||||
// let count = count.clone();
|
|
||||||
// move |scope| {
|
|
||||||
// if *count.get() != 0 {
|
|
||||||
// if scope.children.lock().unwrap().len() == 0 {
|
|
||||||
// scope.child(
|
|
||||||
// my_component,
|
|
||||||
// Some(Arc::new(|ctx, view| {
|
|
||||||
// let area = ctx.allocate(5, 2, 0, 0);
|
|
||||||
// ctx.draw_view(area, view)
|
|
||||||
// })),
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// scope.children.lock().unwrap().clear();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
// &[&count],
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
|
|
||||||
// {
|
|
||||||
// cx.dyn_scope(
|
|
||||||
// {
|
|
||||||
// let count = count.clone();
|
|
||||||
// move |scope| {
|
|
||||||
// scope.children.lock().unwrap().clear();
|
|
||||||
|
|
||||||
// for i in 0..count.get_dl() {
|
|
||||||
// scope.view(Arc::new(move |ctx| {
|
|
||||||
// ctx.draw_text(Point { x: 0, y: i }, &format!("{i}"));
|
|
||||||
// }));
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
// &[&count],
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
|
|
||||||
rsx! {
|
rsx! {
|
||||||
if %count (*count.get() > 0) {
|
if %count (*count.get() > 0) {
|
||||||
my_component (ctx, view) {
|
my_component (ctx, view) {
|
||||||
let area = ctx.allocate(0, 1, 10, 10);
|
let area = ctx.allocate(10, 0, 10, 10);
|
||||||
ctx.draw_view(area, view);
|
ctx.draw_view(area, view);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
%count "{count}"
|
for %count (i in 0..count.get_dl()) {
|
||||||
|
"{i}"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.view(cx.clone())
|
.view(cx.clone())
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-1
@@ -15,6 +15,23 @@ macro_rules! rsx {
|
|||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! rsx_scope {
|
macro_rules! rsx_scope {
|
||||||
|
($rsx:expr, for $(%$($dep:ident)+)? ($p:pat in $v:expr) {$($inner:tt)*} $($rest:tt)*) => {
|
||||||
|
{
|
||||||
|
$($(let $dep = $dep.clone();)+)?
|
||||||
|
|
||||||
|
$rsx.dynamic_scope({
|
||||||
|
$($(let $dep = $dep.clone();)+)?
|
||||||
|
move |scope| {
|
||||||
|
for $p in $v {
|
||||||
|
$crate::rsx_child!(scope, $($inner)*);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, vec![$($(Box::new($dep)),+)?]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$crate::rsx_scope!($rsx, $($rest)*);
|
||||||
|
};
|
||||||
|
|
||||||
($rsx:expr, if $(%$($dep:ident)+)? ($st:expr) {$($inner:tt)*} $($rest:tt)*) => {
|
($rsx:expr, if $(%$($dep:ident)+)? ($st:expr) {$($inner:tt)*} $($rest:tt)*) => {
|
||||||
{
|
{
|
||||||
$($(let $dep = $dep.clone();)+)?
|
$($(let $dep = $dep.clone();)+)?
|
||||||
@@ -66,7 +83,7 @@ macro_rules! rsx_scope {
|
|||||||
{
|
{
|
||||||
let scope = $crate::component::Scope::new();
|
let scope = $crate::component::Scope::new();
|
||||||
|
|
||||||
$crate::rsx_child!(scope, $component $body);
|
$crate::rsx_child!(scope, $component);
|
||||||
|
|
||||||
$rsx.static_scope(scope);
|
$rsx.static_scope(scope);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user