diff --git a/src/macros.rs b/src/macros.rs index fbb33c4..28afe93 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -13,10 +13,12 @@ macro_rules! rsx { #[macro_export] macro_rules! rsx_scope { - ($rsx:expr, $text:literal $($rest:tt)*) => { + ($rsx:expr, $(%$($dep:ident)+)? $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)))); + $($(let $dep = $dep.clone();)+)? + + $crate::rsx_child!(scope, $text); $rsx.static_scope(scope); $crate::rsx_scope!($rsx, $($rest)*); @@ -25,7 +27,7 @@ macro_rules! rsx_scope { ($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))); + $crate::rsx_child!(scope, $component ($ctx, $view) $body); $rsx.static_scope(scope); $crate::rsx_scope!($rsx, $($rest)*); @@ -34,7 +36,7 @@ macro_rules! rsx_scope { ($rsx:expr, $component:ident $($rest:tt)*) => { let scope = $crate::component::Scope::new(); - scope.child($component, None); + $crate::rsx_child!(scope, $component $body); $rsx.static_scope(scope); $crate::rsx_scope!($rsx, $($rest)*); @@ -42,3 +44,23 @@ macro_rules! rsx_scope { ($rsx:expr,) => {}; } + +#[macro_export] +macro_rules! rsx_child { + ($scope:expr, $text:literal $($rest:tt)*) => { + $scope.view(Arc::new(move |ctx| ctx.draw_text(Point { x: 0, y: 0 }, &format!($text)))); + $crate::rsx_child!($scope, $($rest)*); + }; + + ($scope:expr, $component:ident ($ctx:ident, $view:ident) $body:block $($rest:tt)*) => { + $scope.child($component, Some(Arc::new(|$ctx, $view| $body))); + $crate::rsx_child!($scope, $($rest)*); + }; + + ($scope:expr, $component:ident $($rest:tt)*) => { + $scope.child($component, None); + $crate::rsx_child!($scope, $($rest)*); + }; + + ($rsx:expr,) => {}; +}