working Rsx
This commit is contained in:
@@ -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
@@ -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,) => {};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user