vtui_core/
events.rs

1use std::any::{Any, TypeId};
2
3use crate::input::{KeyCode, MouseButton, MouseScrollDirection};
4
5pub trait Event: Send + 'static {}
6
7pub struct Message {
8    pub type_id: TypeId,
9    pub event: Box<dyn Any + Send>,
10}
11
12impl Message {
13    pub fn new(event: impl Event) -> Self {
14        let type_id = event.type_id();
15        let event = Box::new(event);
16        Self { type_id, event }
17    }
18}
19
20pub struct Tick {}
21
22impl Event for Tick {}
23
24pub struct MouseDown {
25    pub x: u16,
26    pub y: u16,
27    pub button: MouseButton,
28}
29
30impl Event for MouseDown {}
31
32pub struct MouseUp {
33    pub x: u16,
34    pub y: u16,
35    pub button: MouseButton,
36}
37
38impl Event for MouseUp {}
39
40pub struct MouseHover {
41    pub x: u16,
42    pub y: u16,
43}
44
45impl Event for MouseHover {}
46
47pub struct MouseDrag {
48    pub x: u16,
49    pub y: u16,
50    pub button: MouseButton,
51}
52
53impl Event for MouseDrag {}
54
55pub struct MouseScroll {
56    pub x: u16,
57    pub y: u16,
58    pub direction: MouseScrollDirection,
59}
60
61impl Event for MouseScroll {}
62
63pub struct KeyPress {
64    pub key: KeyCode,
65}
66
67impl Event for KeyPress {}
68
69pub struct KeyRepeat {
70    pub key: KeyCode,
71}
72
73impl Event for KeyRepeat {}
74
75pub struct KeyRelease {
76    pub key: KeyCode,
77}
78
79impl Event for KeyRelease {}