1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
//! # Event System
//!
//! This module provides a comprehensive event system for handling user input and system events
//! in terminal applications. Events are generated from various sources including keyboard input,
//! mouse interactions, window changes, and application timers.
//!
//! ## Event Types
//!
//! - **Keyboard Events**: Character input, arrow keys, function keys, and special keys
//! - **Mouse Events**: Movement, clicks, and scroll wheel interactions
//! - **Window Events**: Terminal resize events
//! - **Application Events**: Fixed-rate tick events for game loops
//!
//! ## Usage in Event Loops
//!
//! Events are typically processed in the main application loop:
//!
//! ```rust
//! use minui::{Event, App};
//!
//! let mut app = App::new(())?;
//!
//! app.run(
//! |state, event| {
//! match event {
//! Event::Character('q') | Event::Escape => false, // Exit
//! Event::KeyUp => {
//! // Handle up arrow key
//! true
//! },
//! Event::MouseClick { x, y, button } => {
//! // Handle mouse click at position (x, y)
//! true
//! },
//! Event::Tick => {
//! // Fixed-rate update for games
//! true
//! },
//! _ => true, // Continue for other events
//! }
//! },
//! |state, window| {
//! // Drawing logic
//! }
//! )?;
//! # Ok::<(), minui::Error>(())
//! ```
/// Represents an input or system event that can occur during application execution.
///
/// Events are generated from various sources and are typically processed in the main
/// application loop to handle user interaction and system changes.
///
/// ## Event Categories
///
/// - **Keyboard**: Character input and special keys
/// - **Mouse**: Clicks, movement, and scrolling
/// - **System**: Window resize and application ticks
///
/// # Examples
///
/// ```rust
/// use minui::{Event, MouseButton};
///
/// // Keyboard events
/// let char_event = Event::Character('a');
/// let arrow_event = Event::KeyUp;
/// let function_event = Event::FunctionKey(1); // F1
///
/// // Mouse events
/// let click_event = Event::MouseClick {
/// x: 10,
/// y: 5,
/// button: MouseButton::Left,
/// };
///
/// // System events
/// let resize_event = Event::Resize { width: 80, height: 24 };
/// let tick_event = Event::Tick;
/// ```
/// Represents the different mouse buttons that can be clicked.
///
/// This enum covers the standard mouse buttons and provides an extension
/// point for additional buttons that might be present on some mice.
///
/// # Examples
///
/// ```rust
/// use minui::{Event, MouseButton};
///
/// // Handle different mouse buttons
/// match event {
/// Event::MouseClick { x, y, button: MouseButton::Left } => {
/// // Handle left click
/// },
/// Event::MouseClick { x, y, button: MouseButton::Right } => {
/// // Handle right click (context menu)
/// },
/// Event::MouseClick { x, y, button: MouseButton::Middle } => {
/// // Handle middle click (scroll wheel click)
/// },
/// Event::MouseClick { x, y, button: MouseButton::Other(4) } => {
/// // Handle additional mouse button (e.g., "back" button)
/// },
/// _ => {}
/// }
/// ```