working Rsx

This commit is contained in:
2026-01-25 18:58:24 +01:00
parent f6a4bbd8ac
commit a9ecc8da8b
3 changed files with 91 additions and 57 deletions
+6
View File
@@ -179,6 +179,12 @@ impl Context {
}
impl Scope {
pub fn new() -> Arc<Self> {
Arc::new(Self {
children: Mutex::new(Vec::new()),
})
}
pub fn child<F: Fn(&Arc<Context>) -> View + Send + Sync + 'static>(
self: &Arc<Self>,
child: F,
+34 -1
View File
@@ -3,9 +3,42 @@ macro_rules! rsx {
() => {
$crate::frontend::Rsx::new()
};
($($rsx:tt)+) => {{
let mut r = $crate::frontend::Rsx::new();
$crate::rsx_scope!(r, $($rsx)+);
r
}};
}
#[macro_export]
macro_rules! rsx_scope {
() => {};
($rsx:expr, $text:literal $($rest:tt)*) => {
let scope = $crate::component::Scope::new();
scope.view(Arc::new(move |ctx| ctx.draw_text(Point { x: 0, y: 0 }, &format!($text))));
$rsx.static_scope(scope);
$crate::rsx_scope!($rsx, $($rest)*);
};
($rsx:expr, $component:ident ($ctx:ident, $view:ident) $body:block $($rest:tt)*) => {
let scope = $crate::component::Scope::new();
scope.child($component, Some(Arc::new(|$ctx, $view| $body)));
$rsx.static_scope(scope);
$crate::rsx_scope!($rsx, $($rest)*);
};
($rsx:expr, $component:ident $($rest:tt)*) => {
let scope = $crate::component::Scope::new();
scope.child($component, None);
$rsx.static_scope(scope);
$crate::rsx_scope!($rsx, $($rest)*);
};
($rsx:expr,) => {};
}