2022-06-28 23:13:01 +00:00
|
|
|
use dioxus::prelude::*;
|
|
|
|
use dioxus_html::input_data::keyboard_types::Code;
|
2022-05-03 16:02:35 +00:00
|
|
|
|
|
|
|
fn main() {
|
2022-07-09 19:15:20 +00:00
|
|
|
dioxus_tui::launch(app);
|
2022-05-03 16:02:35 +00:00
|
|
|
}
|
|
|
|
|
2024-01-19 22:19:49 +00:00
|
|
|
#[component]
|
|
|
|
fn Button(color_offset: u32, layer: u16) -> Element {
|
|
|
|
let mut toggle = use_signal(|| false);
|
|
|
|
let mut hovered = use_signal(|| false);
|
2022-05-03 22:50:04 +00:00
|
|
|
|
2024-01-19 22:19:49 +00:00
|
|
|
let hue = color_offset % 255;
|
|
|
|
let saturation = if toggle() { 50 } else { 25 } + if hovered() { 50 } else { 25 };
|
2022-05-03 22:50:04 +00:00
|
|
|
let brightness = saturation / 2;
|
|
|
|
let color = format!("hsl({hue}, {saturation}, {brightness})");
|
2022-05-03 16:02:35 +00:00
|
|
|
|
2024-01-14 05:12:21 +00:00
|
|
|
rsx! {
|
2022-05-03 22:50:04 +00:00
|
|
|
div{
|
|
|
|
width: "100%",
|
2022-05-03 16:02:35 +00:00
|
|
|
height: "100%",
|
|
|
|
background_color: "{color}",
|
2024-01-19 22:19:49 +00:00
|
|
|
tabindex: "{layer}",
|
2024-01-11 03:33:34 +00:00
|
|
|
onkeydown: move |e| {
|
2024-01-31 22:07:00 +00:00
|
|
|
if let Code::Space = e.code() {
|
2024-01-19 22:19:49 +00:00
|
|
|
toggle.toggle();
|
2022-05-03 22:50:04 +00:00
|
|
|
}
|
|
|
|
},
|
2024-01-19 22:19:49 +00:00
|
|
|
onclick: move |_| toggle.toggle(),
|
|
|
|
onmouseenter: move |_| hovered.set(true),
|
|
|
|
onmouseleave: move |_| hovered.set(false),
|
2022-05-03 16:02:35 +00:00
|
|
|
justify_content: "center",
|
|
|
|
align_items: "center",
|
2022-05-03 22:50:04 +00:00
|
|
|
display: "flex",
|
|
|
|
flex_direction: "column",
|
2024-01-19 22:19:49 +00:00
|
|
|
p { "tabindex: {layer}" }
|
2022-05-03 16:02:35 +00:00
|
|
|
}
|
2024-01-14 05:12:21 +00:00
|
|
|
}
|
2022-05-03 16:02:35 +00:00
|
|
|
}
|
|
|
|
|
2024-01-14 04:51:37 +00:00
|
|
|
fn app() -> Element {
|
2024-01-14 05:12:21 +00:00
|
|
|
rsx! {
|
2022-05-03 16:02:35 +00:00
|
|
|
div {
|
2022-05-03 22:50:04 +00:00
|
|
|
display: "flex",
|
|
|
|
flex_direction: "column",
|
2022-05-03 16:02:35 +00:00
|
|
|
width: "100%",
|
|
|
|
height: "100%",
|
2024-01-11 03:33:34 +00:00
|
|
|
for y in 1..8 {
|
|
|
|
div {
|
|
|
|
display: "flex",
|
|
|
|
flex_direction: "row",
|
|
|
|
width: "100%",
|
|
|
|
height: "100%",
|
|
|
|
for x in 1..8 {
|
|
|
|
if (x + y) % 2 == 0 {
|
|
|
|
div {
|
|
|
|
width: "100%",
|
|
|
|
height: "100%",
|
|
|
|
background_color: "rgb(100, 100, 100)",
|
2022-05-03 22:50:04 +00:00
|
|
|
}
|
2024-01-11 03:33:34 +00:00
|
|
|
} else {
|
|
|
|
Button {
|
|
|
|
color_offset: x * y,
|
|
|
|
layer: ((x + y) % 3) as u16,
|
2022-05-03 22:50:04 +00:00
|
|
|
}
|
2024-01-11 03:33:34 +00:00
|
|
|
}
|
2022-05-03 22:50:04 +00:00
|
|
|
}
|
2022-12-06 23:38:04 +00:00
|
|
|
}
|
2024-01-11 03:33:34 +00:00
|
|
|
}
|
2022-05-03 16:02:35 +00:00
|
|
|
}
|
2024-01-14 05:12:21 +00:00
|
|
|
}
|
2022-05-03 16:02:35 +00:00
|
|
|
}
|