anathema_widgets/components/events/
mod.rs1use std::time::Duration;
2
3use anathema_geometry::Size;
4
5pub use self::key::{KeyCode, KeyEvent, KeyState};
6pub use self::mouse::{MouseButton, MouseEvent, MouseState};
7
8mod key;
9mod mouse;
10
11#[derive(Debug, Copy, Clone)]
12pub enum EventType {
13 PreCycle,
14 PostCycle,
15}
16
17impl From<Event> for EventType {
18 fn from(event: Event) -> Self {
19 match event {
20 Event::Resize(_) => EventType::PostCycle,
21 _ => EventType::PreCycle,
22 }
23 }
24}
25
26#[derive(Debug, Copy, Clone, PartialEq)]
28pub enum Event {
29 Noop,
31 Mount,
33 Unmount,
35 Stop,
37 Blur,
39 Focus,
41 Key(KeyEvent),
43 Mouse(MouseEvent),
45 Resize(Size),
47 Tick(Duration),
49}
50
51impl Event {
52 pub fn is_mouse_event(&self) -> bool {
53 matches!(self, Self::Mouse(_))
54 }
55
56 pub fn get_char(&self) -> Option<char> {
57 match self {
58 Self::Key(event) => event.get_char(),
59 _ => None,
60 }
61 }
62
63 pub fn is_ctrl_c(&self) -> bool {
64 match self {
65 Self::Key(event) => match event.code {
66 KeyCode::Char('c') => event.ctrl,
67 _ => false,
68 },
69 _ => false,
70 }
71 }
72}