dioxus/packages/dioxus-tui/examples/quadrants.rs

68 lines
1.5 KiB
Rust
Raw Normal View History

2023-05-02 14:38:58 +00:00
#![allow(non_snake_case)]
2022-01-01 04:53:37 +00:00
use dioxus::prelude::*;
2023-05-02 14:38:58 +00:00
use dioxus_tui::Config;
2022-01-01 04:53:37 +00:00
fn main() {
2023-05-02 14:38:58 +00:00
dioxus_tui::launch_cfg(app, Config::default());
}
#[derive(Props, PartialEq)]
struct QuadrentProps {
color: String,
text: String,
}
fn Quadrant(cx: Scope<QuadrentProps>) -> Element {
cx.render(rsx! {
div {
border_width: "1px",
width: "50%",
height: "100%",
background_color: "{cx.props.color}",
justify_content: "center",
align_items: "center",
"{cx.props.text}"
}
})
2022-01-01 04:53:37 +00:00
}
fn app() -> Element {
2022-01-01 04:53:37 +00:00
cx.render(rsx! {
div {
width: "100%",
height: "100%",
flex_direction: "column",
div {
width: "100%",
height: "50%",
flex_direction: "row",
2023-05-02 14:38:58 +00:00
Quadrant{
color: "red".to_string(),
text: "[A]".to_string()
},
Quadrant{
color: "black".to_string(),
text: "[B]".to_string()
2022-01-01 04:53:37 +00:00
}
}
div {
width: "100%",
height: "50%",
flex_direction: "row",
2023-05-02 14:38:58 +00:00
Quadrant{
color: "green".to_string(),
text: "[C]".to_string()
},
Quadrant{
color: "blue".to_string(),
text: "[D]".to_string()
2022-01-01 04:53:37 +00:00
}
}
}
})
}