mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-12-11 13:22:35 +00:00
67a6fa9eb8
* work on seperating tree struture from realdom * intial update to new mutations * handle height * update to taffy 0.2 * add as_varient functions to OwnedAttributeValue * make get node parent mut optionally return a parent * work on upward pass * add more code for parrellel passes * make resolve passes public * more work on parallel passes * fix deadlock and add more tests * move height into the tree instead of the realdom * make passes exicute in parallel instead of executing invidual passes in parellel * fix some warnings * add up dependant test * clean up examples * work on intigrating state with passes * update to new mutations * work on implementing macro * make the macro compile * more progress on macro * mark cloned nodes as dirty * update persistant_iterator utility * fix mask generation * update tui with new mutations * more progress updating tui * some basic tui examples working * don't push template nodes onto the stack * update hover example * update benchmark * update more examples * fix root node layout * ignore out of bounds renders * update color picker example * update all events example * update remaining examples * update tests * tests passing * move persistant iterator test * update examples * fix gaps in layout * fix formatting * fix memory leak
94 lines
2.7 KiB
Rust
94 lines
2.7 KiB
Rust
use dioxus::prelude::*;
|
|
use dioxus_html::input_data::keyboard_types::Code;
|
|
|
|
fn main() {
|
|
dioxus_tui::launch(app);
|
|
}
|
|
|
|
#[derive(PartialEq, Props)]
|
|
struct ButtonProps {
|
|
color_offset: u32,
|
|
layer: u16,
|
|
}
|
|
|
|
#[allow(non_snake_case)]
|
|
fn Button(cx: Scope<ButtonProps>) -> Element {
|
|
let toggle = use_state(&cx, || false);
|
|
let hovered = use_state(&cx, || false);
|
|
|
|
let hue = cx.props.color_offset % 255;
|
|
let saturation = if *toggle.get() { 50 } else { 25 } + if *hovered.get() { 50 } else { 25 };
|
|
let brightness = saturation / 2;
|
|
let color = format!("hsl({hue}, {saturation}, {brightness})");
|
|
|
|
cx.render(rsx! {
|
|
div{
|
|
width: "100%",
|
|
height: "100%",
|
|
background_color: "{color}",
|
|
tabindex: "{cx.props.layer}",
|
|
onkeydown: |e| {
|
|
if let Code::Space = e.inner().code() {
|
|
toggle.modify(|f| !f);
|
|
}
|
|
},
|
|
onclick: |_| {
|
|
toggle.modify(|f| !f);
|
|
},
|
|
onmouseenter: |_|{
|
|
hovered.set(true);
|
|
},
|
|
onmouseleave: |_|{
|
|
hovered.set(false);
|
|
},
|
|
justify_content: "center",
|
|
align_items: "center",
|
|
display: "flex",
|
|
flex_direction: "column",
|
|
|
|
p{"tabindex: {cx.props.layer}"}
|
|
}
|
|
})
|
|
}
|
|
|
|
fn app(cx: Scope) -> Element {
|
|
cx.render(rsx! {
|
|
div {
|
|
display: "flex",
|
|
flex_direction: "column",
|
|
width: "100%",
|
|
height: "100%",
|
|
|
|
(1..8).map(|y|
|
|
rsx!{
|
|
div{
|
|
display: "flex",
|
|
flex_direction: "row",
|
|
width: "100%",
|
|
height: "100%",
|
|
(1..8).map(|x|{
|
|
if (x + y) % 2 == 0{
|
|
rsx!{
|
|
div{
|
|
width: "100%",
|
|
height: "100%",
|
|
background_color: "rgb(100, 100, 100)",
|
|
}
|
|
}
|
|
}
|
|
else{
|
|
let layer = (x + y) % 3;
|
|
rsx!{
|
|
Button{
|
|
color_offset: x * y,
|
|
layer: layer as u16,
|
|
}
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|
|
)
|
|
}
|
|
})
|
|
}
|