-
-
Save pavi2410/450f2b25b2751deed16a81e535d5894d to your computer and use it in GitHub Desktop.
DSL for Declarative UI library in Rust
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
macro_rules! run { | |
($a:expr) => {{ | |
println!("{:?}", $a); | |
}}; | |
} | |
#[derive(Debug)] | |
enum UiNode<'a> { | |
Window { content: &'a UiNode<'a> }, | |
Column { content: Vec<UiNode<'a>> }, | |
Label { text: &'a str }, | |
Button { text: &'a str, on_click: fn() -> () }, | |
} | |
fn main() { | |
fn on_button_click() {} | |
run! { | |
UiNode::Window { | |
content: &UiNode::Column { | |
content: vec![ | |
UiNode::Label { | |
text: "Hello World" | |
}, | |
UiNode::Button { | |
text: "Say Hi!", | |
on_click: on_button_click | |
} | |
] | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment