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

94 lines
2.6 KiB
Rust
Raw Normal View History

2022-12-08 02:28:01 +00:00
use dioxus::prelude::*;
2023-03-24 17:43:51 +00:00
use dioxus_tui::Config;
2022-12-08 02:28:01 +00:00
fn main() {
dioxus_tui::launch_cfg(app, Config::new());
}
fn app(cx: Scope) -> Element {
let bg_green = use_state(cx, || false);
let color = if *bg_green.get() { "green" } else { "red" };
cx.render(rsx! {
div{
width: "100%",
background_color: "{color}",
flex_direction: "column",
align_items: "center",
justify_content: "center",
2023-03-24 17:43:51 +00:00
input {
oninput: |data| if &data.value == "good"{
2022-12-08 02:28:01 +00:00
bg_green.set(true);
} else{
bg_green.set(false);
},
r#type: "checkbox",
value: "good",
width: "50%",
height: "10%",
checked: "true",
}
2023-03-24 17:43:51 +00:00
input {
oninput: |data| if &data.value == "hello world"{
2022-12-08 02:28:01 +00:00
bg_green.set(true);
} else{
bg_green.set(false);
},
width: "50%",
height: "10%",
maxlength: "11",
}
2023-03-24 17:43:51 +00:00
input {
oninput: |data| {
2022-12-08 05:01:13 +00:00
if (data.value.parse::<f32>().unwrap() - 40.0).abs() < 5.0 {
bg_green.set(true);
} else{
bg_green.set(false);
}
},
r#type: "range",
width: "50%",
height: "10%",
min: "20",
max: "80",
}
2023-03-24 17:43:51 +00:00
input {
oninput: |data| {
2022-12-08 05:01:13 +00:00
if data.value == "10"{
bg_green.set(true);
} else{
bg_green.set(false);
}
},
r#type: "number",
width: "50%",
height: "10%",
maxlength: "4",
}
2023-03-24 17:43:51 +00:00
input {
oninput: |data| {
2022-12-08 05:01:13 +00:00
if data.value == "hello world"{
bg_green.set(true);
} else{
bg_green.set(false);
}
},
r#type: "password",
width: "50%",
height: "10%",
maxlength: "11",
}
2023-03-24 17:43:51 +00:00
input {
oninput: |_| {
bg_green.set(true)
},
2022-12-08 05:01:13 +00:00
r#type: "button",
value: "green",
width: "50%",
height: "10%",
}
2022-12-08 02:28:01 +00:00
}
})
}