2022-11-16 00:37:23 +00:00
|
|
|
use dioxus::{events::*, html::MouseEvent, prelude::*};
|
2022-06-28 20:36:06 +00:00
|
|
|
|
|
|
|
fn main() {
|
2024-01-19 00:27:43 +00:00
|
|
|
launch(app);
|
2022-06-28 20:36:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
enum Event {
|
2022-07-03 03:12:26 +00:00
|
|
|
MouseMove(MouseEvent),
|
|
|
|
MouseClick(MouseEvent),
|
|
|
|
MouseDoubleClick(MouseEvent),
|
|
|
|
MouseDown(MouseEvent),
|
|
|
|
MouseUp(MouseEvent),
|
2022-06-28 22:18:09 +00:00
|
|
|
|
2022-07-03 03:12:26 +00:00
|
|
|
Wheel(WheelEvent),
|
2022-06-28 22:18:09 +00:00
|
|
|
|
2022-07-03 03:12:26 +00:00
|
|
|
KeyDown(KeyboardEvent),
|
|
|
|
KeyUp(KeyboardEvent),
|
|
|
|
KeyPress(KeyboardEvent),
|
2022-06-28 22:24:33 +00:00
|
|
|
|
2022-07-03 03:12:26 +00:00
|
|
|
FocusIn(FocusEvent),
|
|
|
|
FocusOut(FocusEvent),
|
2022-06-28 20:36:06 +00:00
|
|
|
}
|
|
|
|
|
2022-06-28 22:24:33 +00:00
|
|
|
const MAX_EVENTS: usize = 8;
|
2022-06-28 20:36:06 +00:00
|
|
|
|
2022-07-03 03:12:26 +00:00
|
|
|
const CONTAINER_STYLE: &str = r#"
|
2022-06-28 20:36:06 +00:00
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
align-items: center;
|
|
|
|
"#;
|
2022-07-03 03:12:26 +00:00
|
|
|
|
|
|
|
const RECT_STYLE: &str = r#"
|
2022-06-28 20:36:06 +00:00
|
|
|
background: deepskyblue;
|
|
|
|
height: 50vh;
|
|
|
|
width: 50vw;
|
2022-06-28 22:18:09 +00:00
|
|
|
color: white;
|
|
|
|
padding: 20px;
|
|
|
|
margin: 20px;
|
|
|
|
text-aligh: center;
|
2022-06-28 20:36:06 +00:00
|
|
|
"#;
|
|
|
|
|
2024-01-14 04:51:37 +00:00
|
|
|
fn app() -> Element {
|
2024-01-16 07:24:59 +00:00
|
|
|
let mut events = use_signal(std::collections::VecDeque::new);
|
2022-06-28 20:36:06 +00:00
|
|
|
|
2024-01-16 07:24:59 +00:00
|
|
|
let mut log_event = move |event: Event| {
|
2022-07-03 03:17:48 +00:00
|
|
|
let mut events = events.write();
|
|
|
|
|
|
|
|
if events.len() >= MAX_EVENTS {
|
|
|
|
events.pop_front();
|
|
|
|
}
|
|
|
|
events.push_back(event);
|
|
|
|
};
|
2022-06-28 20:36:06 +00:00
|
|
|
|
2024-01-16 19:18:46 +00:00
|
|
|
rsx! {
|
2024-01-03 20:02:08 +00:00
|
|
|
div { style: "{CONTAINER_STYLE}",
|
2022-06-28 20:36:06 +00:00
|
|
|
div {
|
2022-07-03 03:12:26 +00:00
|
|
|
style: "{RECT_STYLE}",
|
2022-06-28 20:58:07 +00:00
|
|
|
// focusing is necessary to catch keyboard events
|
|
|
|
tabindex: "0",
|
|
|
|
|
2022-07-03 03:12:26 +00:00
|
|
|
onmousemove: move |event| log_event(Event::MouseMove(event)),
|
|
|
|
onclick: move |event| log_event(Event::MouseClick(event)),
|
2024-01-03 20:02:08 +00:00
|
|
|
ondoubleclick: move |event| log_event(Event::MouseDoubleClick(event)),
|
2022-07-03 03:12:26 +00:00
|
|
|
onmousedown: move |event| log_event(Event::MouseDown(event)),
|
|
|
|
onmouseup: move |event| log_event(Event::MouseUp(event)),
|
2022-06-28 20:58:07 +00:00
|
|
|
|
2022-07-03 03:12:26 +00:00
|
|
|
onwheel: move |event| log_event(Event::Wheel(event)),
|
2022-06-28 22:18:09 +00:00
|
|
|
|
2022-07-03 03:12:26 +00:00
|
|
|
onkeydown: move |event| log_event(Event::KeyDown(event)),
|
|
|
|
onkeyup: move |event| log_event(Event::KeyUp(event)),
|
|
|
|
onkeypress: move |event| log_event(Event::KeyPress(event)),
|
2022-06-28 22:18:09 +00:00
|
|
|
|
2022-07-03 03:12:26 +00:00
|
|
|
onfocusin: move |event| log_event(Event::FocusIn(event)),
|
|
|
|
onfocusout: move |event| log_event(Event::FocusOut(event)),
|
2022-06-28 22:24:33 +00:00
|
|
|
|
2022-06-28 22:18:09 +00:00
|
|
|
"Hover, click, type or scroll to see the info down below"
|
2022-06-28 20:36:06 +00:00
|
|
|
}
|
2024-01-11 03:33:34 +00:00
|
|
|
div {
|
|
|
|
for event in events.read().iter() {
|
|
|
|
div { "{event:?}" }
|
|
|
|
}
|
|
|
|
}
|
2024-01-03 20:02:08 +00:00
|
|
|
}
|
2024-01-14 05:12:21 +00:00
|
|
|
}
|
2022-06-28 20:36:06 +00:00
|
|
|
}
|