diff --git a/examples/hello_world.rs b/examples/hello_world.rs index 7dfb5da..4e5c77f 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -56,7 +56,7 @@ fn app(cx: &Arc) -> View { // Dynamic scope for %count (i in 0..count.get_dl()) { - "{i}" + "{i}" @Point { x: 0, y: i }; } } .view(cx.clone()) diff --git a/src/macros.rs b/src/macros.rs index b1b1a57..4c8b828 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -53,6 +53,20 @@ macro_rules! rsx_scope { $crate::rsx_scope!($rsx, $($rest)*); }; + ($rsx:expr, $(%$($dep:ident $(as $dp:pat,)?),+)? $text:literal @$d:expr; $($rest:tt)*) => { + { + let scope = $crate::component::Scope::new(); + + $($($crate::rsx_dep!($dep $(as $dp)?);)+)? + + $crate::rsx_child!(scope, $text @$d;); + + $rsx.static_scope(scope); + } + + $crate::rsx_scope!($rsx, $($rest)*); + }; + ($rsx:expr, $(%$($dep:ident $(as $dp:pat,)?),+)? $text:literal $($rest:tt)*) => { { let scope = $crate::component::Scope::new(); @@ -96,6 +110,14 @@ macro_rules! rsx_scope { #[macro_export] macro_rules! rsx_child { + ($scope:expr, $text:literal @$d:expr; $($rest:tt)*) => { + { + $scope.view(Arc::new(move |ctx| ctx.draw_text($d, &format!($text)))); + } + + $crate::rsx_child!($scope, $($rest)*); + }; + ($scope:expr, $text:literal $($rest:tt)*) => { { $scope.view(Arc::new(move |ctx| ctx.draw_text(Point { x: 0, y: 0 }, &format!($text))));