Implemented commands on scopes

This commit is contained in:
2026-01-28 19:33:12 +01:00
parent 715175c412
commit 63abf41094
4 changed files with 26 additions and 17 deletions
+9 -1
View File
@@ -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
View File
@@ -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(
+3
View File
@@ -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 {}