From 6b3e9239c94d408f0aa429559975dcc5235a9fe0 Mon Sep 17 00:00:00 2001 From: Leo dev Date: Sun, 25 Jan 2026 02:27:36 +0100 Subject: [PATCH] Scope view --- examples/hello_world.rs | 9 +++------ src/component.rs | 8 ++++++++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/examples/hello_world.rs b/examples/hello_world.rs index fc998cd..87702ef 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -84,12 +84,9 @@ fn app(cx: &Arc) -> View { 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}")); - })), - ); + scope.view(Arc::new(move |ctx| { + ctx.draw_text(Point { x: 0, y: i }, &format!("{i}")); + })); } } }, diff --git a/src/component.rs b/src/component.rs index 18a4d9b..a65bde0 100644 --- a/src/component.rs +++ b/src/component.rs @@ -190,4 +190,12 @@ impl Scope { self.children.lock().unwrap().push((ctx, view_wrapper)); } + + pub fn view(self: &Arc, view: View) { + let ctx = Context::new(move |_| view.clone()); + + ctx.refresh(); + + self.children.lock().unwrap().push((ctx, None)); + } }