added for loops
This commit is contained in:
+18
-1
@@ -116,11 +116,18 @@ macro_rules! command {
|
||||
///
|
||||
/// # Parameters
|
||||
/// - `elem`: The element being updated.
|
||||
/// - Various key-value pairs, child elements, and text content.
|
||||
/// - Various key-value pairs, child elements, and text content. even for loops
|
||||
#[macro_export]
|
||||
macro_rules! parse_rsx_param {
|
||||
($elem:expr, ) => {};
|
||||
|
||||
($elem:expr, for ($item:ident in $expr:expr) {$($inner:tt)*} $($rest:tt)*) => {
|
||||
for $item in $expr {
|
||||
$elem.children.push({$($inner)*})
|
||||
}
|
||||
osui::parse_rsx_param!($elem, $($rest)*);
|
||||
};
|
||||
|
||||
($elem:expr, $($k:ident: $v:expr),*) => {
|
||||
$(
|
||||
$elem.$k = $v;
|
||||
@@ -167,6 +174,16 @@ macro_rules! parse_rsx_param {
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// # For loops
|
||||
/// ```
|
||||
/// rsx! {
|
||||
/// text { "Welcome!" }
|
||||
/// for (i in 1..5) { // must be contained with ()
|
||||
/// rsx_elem!{text { y: i, "Text: {i}" }}
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// This macro provides a clean way to express OSUI elements, functioning like a div that can
|
||||
/// contain multiple components.
|
||||
|
||||
Reference in New Issue
Block a user