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
+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);
}
}