Implemented commands on scopes
This commit is contained in:
+6
-12
@@ -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! {
|
||||
|
||||
+9
-1
@@ -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<dyn Command>) -> crate::Result<()>;
|
||||
}
|
||||
|
||||
+8
-4
@@ -7,7 +7,7 @@ use crate::{
|
||||
};
|
||||
|
||||
pub enum RsxScope {
|
||||
Static(Arc<Scope>),
|
||||
Static(Box<dyn Fn(&Arc<Scope>) + Send + Sync>),
|
||||
Dynamic(
|
||||
Arc<dyn Fn(&Arc<Scope>) + Send + Sync>,
|
||||
Vec<Box<dyn HookDependency>>,
|
||||
@@ -21,8 +21,8 @@ impl Rsx {
|
||||
Self(Vec::new())
|
||||
}
|
||||
|
||||
pub fn static_scope(&mut self, scope: Arc<Scope>) {
|
||||
self.0.push(RsxScope::Static(scope));
|
||||
pub fn static_scope<F: Fn(&Arc<Scope>) + Send + Sync + 'static>(&mut self, scope: F) {
|
||||
self.0.push(RsxScope::Static(Box::new(scope)));
|
||||
}
|
||||
|
||||
pub fn dynamic_scope<F: Fn(&Arc<Scope>) + Send + Sync + 'static>(
|
||||
@@ -37,7 +37,11 @@ impl Rsx {
|
||||
pub fn view(&self, context: Arc<Context>) -> 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(
|
||||
|
||||
@@ -19,3 +19,6 @@ pub mod prelude {
|
||||
|
||||
pub type View = Arc<dyn Fn(&mut DrawContext) + Send + Sync>;
|
||||
pub type ViewWrapper = Arc<dyn Fn(&mut DrawContext, View) + Send + Sync>;
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
pub enum Error {}
|
||||
|
||||
Reference in New Issue
Block a user