Dynamic scoping with for loop
This commit is contained in:
+23
-2
@@ -46,7 +46,7 @@ fn app(cx: &Arc<Context>) -> View {
|
|||||||
scope.child(
|
scope.child(
|
||||||
my_component,
|
my_component,
|
||||||
Some(Arc::new(|ctx, view| {
|
Some(Arc::new(|ctx, view| {
|
||||||
let area = ctx.allocate(0, 0, 0, 0);
|
let area = ctx.allocate(5, 0, 0, 0);
|
||||||
ctx.draw_view(area, view)
|
ctx.draw_view(area, view)
|
||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
@@ -62,7 +62,7 @@ fn app(cx: &Arc<Context>) -> View {
|
|||||||
scope.child(
|
scope.child(
|
||||||
my_component,
|
my_component,
|
||||||
Some(Arc::new(|ctx, view| {
|
Some(Arc::new(|ctx, view| {
|
||||||
let area = ctx.allocate(0, 2, 0, 0);
|
let area = ctx.allocate(5, 2, 0, 0);
|
||||||
ctx.draw_view(area, view)
|
ctx.draw_view(area, view)
|
||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
@@ -76,6 +76,27 @@ fn app(cx: &Arc<Context>) -> View {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
cx.dyn_scope(
|
||||||
|
{
|
||||||
|
let count = count.clone();
|
||||||
|
move |scope| {
|
||||||
|
scope.children.lock().unwrap().clear();
|
||||||
|
|
||||||
|
for i in 0..count.get_dl() {
|
||||||
|
scope.child(
|
||||||
|
my_component,
|
||||||
|
Some(Arc::new(move |ctx, _| {
|
||||||
|
ctx.draw_text(Point { x: 0, y: i }, &format!("{i}"));
|
||||||
|
})),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
&[&count],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
Arc::new({
|
Arc::new({
|
||||||
let cx = cx.clone();
|
let cx = cx.clone();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user