Skip to content

Instantly share code, notes, and snippets.

@pavi2410
Forked from rust-play/playground.rs
Created October 5, 2022 07:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pavi2410/450f2b25b2751deed16a81e535d5894d to your computer and use it in GitHub Desktop.
Save pavi2410/450f2b25b2751deed16a81e535d5894d to your computer and use it in GitHub Desktop.
DSL for Declarative UI library in Rust
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