If statement rsx
This commit is contained in:
+54
-14
@@ -6,39 +6,71 @@ macro_rules! rsx {
|
||||
|
||||
($($rsx:tt)+) => {{
|
||||
let mut r = $crate::frontend::Rsx::new();
|
||||
$crate::rsx_scope!(r, $($rsx)+);
|
||||
{
|
||||
$crate::rsx_scope!(r, $($rsx)+);
|
||||
}
|
||||
r
|
||||
}};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! rsx_scope {
|
||||
($rsx:expr, if $(%$($dep:ident)+)? ($st:expr) {$($inner:tt)*} $($rest:tt)*) => {
|
||||
{
|
||||
$($(let $dep = $dep.clone();)+)?
|
||||
|
||||
$rsx.dynamic_scope({
|
||||
$($(let $dep = $dep.clone();)+)?
|
||||
move |scope| {
|
||||
if $st {
|
||||
if scope.children.lock().unwrap().len() == 0 {
|
||||
$crate::rsx_child!(scope, $($inner)*);
|
||||
}
|
||||
} else {
|
||||
scope.children.lock().unwrap().clear();
|
||||
}
|
||||
}
|
||||
}, vec![$($(Box::new($dep)),+)?]);
|
||||
}
|
||||
|
||||
$crate::rsx_scope!($rsx, $($rest)*);
|
||||
};
|
||||
|
||||
($rsx:expr, $(%$($dep:ident)+)? $text:literal $($rest:tt)*) => {
|
||||
let scope = $crate::component::Scope::new();
|
||||
{
|
||||
let scope = $crate::component::Scope::new();
|
||||
|
||||
$($(let $dep = $dep.clone();)+)?
|
||||
$($(let $dep = $dep.clone();)+)?
|
||||
|
||||
$crate::rsx_child!(scope, $text);
|
||||
$crate::rsx_child!(scope, $text);
|
||||
|
||||
$rsx.static_scope(scope);
|
||||
}
|
||||
|
||||
$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();
|
||||
{
|
||||
let scope = $crate::component::Scope::new();
|
||||
|
||||
$crate::rsx_child!(scope, $component ($ctx, $view) $body);
|
||||
$crate::rsx_child!(scope, $component ($ctx, $view) $body);
|
||||
|
||||
$rsx.static_scope(scope);
|
||||
}
|
||||
|
||||
$rsx.static_scope(scope);
|
||||
$crate::rsx_scope!($rsx, $($rest)*);
|
||||
};
|
||||
|
||||
($rsx:expr, $component:ident $($rest:tt)*) => {
|
||||
let scope = $crate::component::Scope::new();
|
||||
{
|
||||
let scope = $crate::component::Scope::new();
|
||||
|
||||
$crate::rsx_child!(scope, $component $body);
|
||||
$crate::rsx_child!(scope, $component $body);
|
||||
|
||||
$rsx.static_scope(scope);
|
||||
}
|
||||
|
||||
$rsx.static_scope(scope);
|
||||
$crate::rsx_scope!($rsx, $($rest)*);
|
||||
};
|
||||
|
||||
@@ -48,17 +80,25 @@ macro_rules! rsx_scope {
|
||||
#[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))));
|
||||
{
|
||||
$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)));
|
||||
{
|
||||
$scope.child($component, Some(Arc::new(|$ctx, $view| $body)));
|
||||
}
|
||||
|
||||
$crate::rsx_child!($scope, $($rest)*);
|
||||
};
|
||||
|
||||
($scope:expr, $component:ident $($rest:tt)*) => {
|
||||
$scope.child($component, None);
|
||||
{
|
||||
$scope.child($component, None);
|
||||
}
|
||||
$crate::rsx_child!($scope, $($rest)*);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user