2022-03-09 18:36:30 +00:00
|
|
|
use dioxus::events::WheelEvent;
|
|
|
|
use dioxus::prelude::*;
|
2022-05-07 15:28:15 +00:00
|
|
|
use dioxus_html::geometry::ScreenPoint;
|
2022-05-12 11:36:52 +00:00
|
|
|
use dioxus_html::input_data::keyboard_types::Code;
|
2022-05-11 10:47:58 +00:00
|
|
|
use dioxus_html::input_data::MouseButtonSet;
|
2022-03-09 18:36:30 +00:00
|
|
|
use dioxus_html::on::{KeyboardEvent, MouseEvent};
|
|
|
|
|
|
|
|
fn main() {
|
2022-07-09 19:15:20 +00:00
|
|
|
dioxus_tui::launch(app);
|
2022-03-09 18:36:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn app(cx: Scope) -> Element {
|
|
|
|
let key = use_state(&cx, || "".to_string());
|
2022-06-20 06:24:39 +00:00
|
|
|
let mouse = use_state(&cx, ScreenPoint::zero);
|
2022-03-09 18:36:30 +00:00
|
|
|
let count = use_state(&cx, || 0);
|
2022-06-20 06:24:39 +00:00
|
|
|
let buttons = use_state(&cx, MouseButtonSet::empty);
|
2022-03-09 18:36:30 +00:00
|
|
|
let mouse_clicked = use_state(&cx, || false);
|
|
|
|
|
2022-05-12 11:36:52 +00:00
|
|
|
let key_down_handler = move |evt: KeyboardEvent| {
|
|
|
|
match evt.data.code() {
|
|
|
|
Code::ArrowLeft => count.set(count + 1),
|
|
|
|
Code::ArrowRight => count.set(count - 1),
|
|
|
|
Code::ArrowUp => count.set(count + 10),
|
|
|
|
Code::ArrowDown => count.set(count - 10),
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
key.set(format!(
|
|
|
|
"{:?} repeating: {:?}",
|
|
|
|
evt.key(),
|
|
|
|
evt.is_auto_repeating()
|
|
|
|
));
|
|
|
|
};
|
|
|
|
|
2022-03-09 18:36:30 +00:00
|
|
|
cx.render(rsx! {
|
|
|
|
div {
|
|
|
|
width: "100%",
|
|
|
|
height: "10px",
|
|
|
|
background_color: "red",
|
|
|
|
justify_content: "center",
|
|
|
|
align_items: "center",
|
|
|
|
flex_direction: "column",
|
2022-05-12 11:36:52 +00:00
|
|
|
onkeydown: key_down_handler,
|
2022-03-09 18:36:30 +00:00
|
|
|
onwheel: move |evt: WheelEvent| {
|
2022-05-12 08:03:51 +00:00
|
|
|
count.set(count + evt.data.delta().strip_units().y as i64);
|
2022-03-09 18:36:30 +00:00
|
|
|
},
|
|
|
|
ondrag: move |evt: MouseEvent| {
|
2022-05-07 15:28:15 +00:00
|
|
|
mouse.set(evt.data.screen_coordinates());
|
2022-03-09 18:36:30 +00:00
|
|
|
},
|
|
|
|
onmousedown: move |evt: MouseEvent| {
|
2022-05-07 15:28:15 +00:00
|
|
|
mouse.set(evt.data.screen_coordinates());
|
|
|
|
buttons.set(evt.data.held_buttons());
|
2022-03-09 18:36:30 +00:00
|
|
|
mouse_clicked.set(true);
|
|
|
|
},
|
|
|
|
onmouseup: move |evt: MouseEvent| {
|
2022-05-07 15:28:15 +00:00
|
|
|
buttons.set(evt.data.held_buttons());
|
2022-03-09 18:36:30 +00:00
|
|
|
mouse_clicked.set(false);
|
|
|
|
},
|
|
|
|
|
|
|
|
"count: {count:?}",
|
|
|
|
"key: {key}",
|
2022-05-07 15:28:15 +00:00
|
|
|
"mouse buttons: {buttons:?}",
|
2022-03-09 18:36:30 +00:00
|
|
|
"mouse pos: {mouse:?}",
|
|
|
|
"mouse button pressed: {mouse_clicked}"
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|