working Rsx
This commit is contained in:
+51
-56
@@ -40,61 +40,55 @@ fn app(cx: &Arc<Context>) -> View {
|
||||
}
|
||||
});
|
||||
|
||||
{
|
||||
let scope = cx.scope();
|
||||
// {
|
||||
// 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],
|
||||
// );
|
||||
// }
|
||||
|
||||
scope.child(
|
||||
my_component,
|
||||
Some(Arc::new(|ctx, view| {
|
||||
let area = ctx.allocate(5, 0, 0, 0);
|
||||
ctx.draw_view(area, view)
|
||||
})),
|
||||
);
|
||||
// {
|
||||
// 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! {
|
||||
my_component (ctx, view) {
|
||||
let area = ctx.allocate(0, 0, 10, 10);
|
||||
ctx.draw_view(area, 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! {}.view(cx.clone())
|
||||
.view(cx.clone())
|
||||
}
|
||||
|
||||
fn my_component(cx: &Arc<Context>) -> View {
|
||||
@@ -112,7 +106,8 @@ fn my_component(cx: &Arc<Context>) -> View {
|
||||
}
|
||||
});
|
||||
|
||||
Arc::new(move |ctx| {
|
||||
ctx.draw_text(Point { x: 0, y: 0 }, &format!("Count: {count}"));
|
||||
})
|
||||
rsx! {
|
||||
"Count: {count}"
|
||||
}
|
||||
.view(cx.clone())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user