diff --git a/macros/src/emit.rs b/macros/src/emit.rs index 186f505..c4683c9 100644 --- a/macros/src/emit.rs +++ b/macros/src/emit.rs @@ -28,21 +28,15 @@ fn emit_deps(deps: &[Dep]) -> TokenStream { fn emit_node(node: &RsxNode) -> TokenStream { match node { RsxNode::Text(text) => quote! { - { - let scope = osui::component::Scope::new(); - scope.view(Arc::new(move |ctx| { - ctx.draw_text(Point { x: 0, y: 0 }, &format!(#text)) - })); - r.static_scope(scope); - } + r.static_scope(|scope| scope.view(Arc::new(move |ctx| { + ctx.draw_text(Point { x: 0, y: 0 }, &format!(#text)) + }))); }, RsxNode::Component(name) => quote! { - { - let scope = osui::component::Scope::new(); - scope.child(#name, None); - r.static_scope(scope); - } + r.static_scope(|scope| scope.view(Arc::new(move |ctx| { + scope.child(#name, None) + }))); }, RsxNode::Mount(m) => quote! { diff --git a/src/engine/mod.rs b/src/engine/mod.rs index 0385182..a228b4d 100644 --- a/src/engine/mod.rs +++ b/src/engine/mod.rs @@ -4,7 +4,7 @@ pub mod console; pub use benchmark::*; pub use console::*; -use std::sync::Arc; +use std::{any::Any, sync::Arc}; use crate::{prelude::Context, render::Area, DrawContext, View}; @@ -30,3 +30,11 @@ pub trait Engine { fn render_view(&self, area: &Area, view: &View) -> DrawContext; fn draw_context(&self, ctx: &DrawContext); } + +pub trait Command { + fn as_any(&self) -> &dyn Any; +} + +pub trait CommandExecutor { + fn execute_command(&self, command: &Arc) -> crate::Result<()>; +} diff --git a/src/frontend.rs b/src/frontend.rs index e90ea99..dbbb7c2 100644 --- a/src/frontend.rs +++ b/src/frontend.rs @@ -7,7 +7,7 @@ use crate::{ }; pub enum RsxScope { - Static(Arc), + Static(Box) + Send + Sync>), Dynamic( Arc) + Send + Sync>, Vec>, @@ -21,8 +21,8 @@ impl Rsx { Self(Vec::new()) } - pub fn static_scope(&mut self, scope: Arc) { - self.0.push(RsxScope::Static(scope)); + pub fn static_scope) + Send + Sync + 'static>(&mut self, scope: F) { + self.0.push(RsxScope::Static(Box::new(scope))); } pub fn dynamic_scope) + Send + Sync + 'static>( @@ -37,7 +37,11 @@ impl Rsx { pub fn view(&self, context: Arc) -> View { for scope in &self.0 { match scope { - RsxScope::Static(scope) => context.scopes.lock().unwrap().push(scope.clone()), + RsxScope::Static(scope_fn) => { + let scope = Scope::new(); + (scope_fn)(&scope); + context.scopes.lock().unwrap().push(scope) + } RsxScope::Dynamic(drawer, dependencies) => { let drawer = drawer.clone(); context.dyn_scope( diff --git a/src/lib.rs b/src/lib.rs index 8b6da82..3590d5f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -19,3 +19,6 @@ pub mod prelude { pub type View = Arc; pub type ViewWrapper = Arc; +pub type Result = std::result::Result; + +pub enum Error {}