Files
dioxus/examples/keys.rs
T

60 lines
1.6 KiB
Rust

use std::cell::RefCell;
use crossterm::event::KeyEvent;
use dioxus::prelude::*;
use rink::InputHandler;
fn main() {
rink::launch(app);
}
fn app(cx: Scope) -> Element {
let (count, set_count) = use_state(&cx, || 0);
cx.render(rsx! {
div {
width: "100%",
height: "10px",
background_color: "red",
justify_content: "center",
align_items: "center",
"Hello world!",
// todo: enabling this will panic
// rink::InputHandler {
// onkeydown: move |evt: KeyEvent| {
// use crossterm::event::KeyCode::*;
// match evt.code {
// Left => set_count(count + 1),
// Right => set_count(count - 1),
// Up => set_count(count + 10),
// Down => set_count(count - 10),
// _ => {},
// }
// },
// onmousedown: move |evt| {},
// onresize: move |dims| {
// println!("{:?}", dims);
// },
// }
}
})
}
fn app2<'a>(cx: Scope<'a>) -> Element<'a> {
let (count, set_count) = use_state(&cx, || 0);
cx.render(rsx! {
div {
width: "100%",
height: "10px",
background_color: "red",
justify_content: "center",
align_items: "center",
oninput: move |_| set_count(count + 1),
"Hello world!",
h1 {},
}
})
}