From 470512a5429f6f63db5063e8ba2041969cd03d03 Mon Sep 17 00:00:00 2001 From: Leo dev Date: Sun, 25 Jan 2026 02:22:16 +0100 Subject: [PATCH] Dynamic scoping with for loop --- examples/hello_world.rs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/examples/hello_world.rs b/examples/hello_world.rs index dc65101..fc998cd 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -46,7 +46,7 @@ fn app(cx: &Arc) -> View { scope.child( my_component, 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) })), ); @@ -62,7 +62,7 @@ fn app(cx: &Arc) -> View { scope.child( my_component, 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) })), ); @@ -76,6 +76,27 @@ fn app(cx: &Arc) -> 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({ let cx = cx.clone();