Abstracted children in scope

This commit is contained in:
2026-01-31 14:52:05 +01:00
parent d8173b8ab3
commit 2faac93944
2 changed files with 21 additions and 9 deletions
+3 -3
View File
@@ -114,7 +114,7 @@ impl Context {
self.scopes.access(move |scopes| {
for scope in scopes {
let event = event.clone();
scope.children.access(move |children| {
scope.access_children(move |children| {
for (child, _) in children {
child.emit_event(event.clone());
}
@@ -143,7 +143,7 @@ impl Context {
self.scopes.access(move |scopes| {
for scope in scopes {
let event = event.clone();
scope.children.access(move |children| {
scope.access_children(move |children| {
for (child, _) in children {
child.emit_event_threaded(&event);
}
@@ -203,7 +203,7 @@ impl Context {
for scope in scopes {
let mut c = c.clone();
let tx = tx.clone();
scope.children.access(move |children| {
scope.access_children(move |children| {
for (child, view_wrapper) in children {
let view = child.get_view();
+18 -6
View File
@@ -1,13 +1,12 @@
use super::{context::Context, ComponentImpl};
use crate::{engine::CommandExecutor, View, ViewWrapper};
use access_cell::AccessCell;
use std::sync::Arc;
use access_cell::AccessCell;
use crate::{engine::CommandExecutor, View, ViewWrapper};
use super::{context::Context, ComponentImpl};
pub type ScopeChildren = Vec<(Arc<Context>, Option<ViewWrapper>)>;
pub struct Scope {
pub children: AccessCell<Vec<(Arc<Context>, Option<ViewWrapper>)>>,
children: AccessCell<ScopeChildren>,
executor: Arc<dyn CommandExecutor>,
}
@@ -39,4 +38,17 @@ impl Scope {
self.children.access(|children| children.push((ctx, None)));
}
pub fn view_wrapper(self: &Arc<Self>, view: View, view_wrapper: Option<ViewWrapper>) {
let ctx = Context::new(view, self.executor.clone());
ctx.refresh();
self.children
.access(|children| children.push((ctx, view_wrapper)));
}
pub fn access_children(self: &Arc<Self>, f: impl FnOnce(&mut ScopeChildren) + Send + 'static) {
self.children.access(f);
}
}