use crate::Context;
#[derive(Debug, Copy, Clone, PartialEq, Hash, Eq)]
pub enum MouseButton {
Right,
Left,
Middle,
Unknown,
}
#[derive(Debug, Copy, Clone)]
pub struct Touch {
pub id: u32,
pub x: f32,
pub y: f32,
}
#[derive(Debug, Copy, Clone, PartialEq, Hash, Eq)]
pub enum KeyCode {
Space,
Apostrophe,
Comma,
Minus,
Period,
Slash,
Key0,
Key1,
Key2,
Key3,
Key4,
Key5,
Key6,
Key7,
Key8,
Key9,
Semicolon,
Equal,
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O,
P,
Q,
R,
S,
T,
U,
V,
W,
X,
Y,
Z,
LeftBracket,
Backslash,
RightBracket,
GraveAccent,
World1,
World2,
Escape,
Enter,
Tab,
Backspace,
Insert,
Delete,
Right,
Left,
Down,
Up,
PageUp,
PageDown,
Home,
End,
CapsLock,
ScrollLock,
NumLock,
PrintScreen,
Pause,
F1,
F2,
F3,
F4,
F5,
F6,
F7,
F8,
F9,
F10,
F11,
F12,
F13,
F14,
F15,
F16,
F17,
F18,
F19,
F20,
F21,
F22,
F23,
F24,
F25,
Kp0,
Kp1,
Kp2,
Kp3,
Kp4,
Kp5,
Kp6,
Kp7,
Kp8,
Kp9,
KpDecimal,
KpDivide,
KpMultiply,
KpSubtract,
KpAdd,
KpEnter,
KpEqual,
LeftShift,
LeftControl,
LeftAlt,
LeftSuper,
RightShift,
RightControl,
RightAlt,
RightSuper,
Menu,
Unknown,
}
#[derive(Debug, Copy, Clone, PartialEq, Default)]
pub struct KeyMods {
pub shift: bool,
pub ctrl: bool,
pub alt: bool,
pub logo: bool,
}
#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)]
pub enum TouchPhase {
Started,
Moved,
Ended,
Cancelled,
}
pub trait EventHandler {
fn update(&mut self, _ctx: &mut Context);
fn draw(&mut self, _ctx: &mut Context);
fn resize_event(&mut self, _ctx: &mut Context, _width: f32, _height: f32) {}
fn mouse_motion_event(&mut self, _ctx: &mut Context, _x: f32, _y: f32) {}
fn mouse_wheel_event(&mut self, _ctx: &mut Context, _x: f32, _y: f32) {}
fn mouse_button_down_event(
&mut self,
_ctx: &mut Context,
_button: MouseButton,
_x: f32,
_y: f32,
) {
}
fn mouse_button_up_event(
&mut self,
_ctx: &mut Context,
_button: MouseButton,
_x: f32,
_y: f32,
) {
}
fn char_event(
&mut self,
_ctx: &mut Context,
_character: char,
_keymods: KeyMods,
_repeat: bool,
) {
}
fn key_down_event(
&mut self,
_ctx: &mut Context,
_keycode: KeyCode,
_keymods: KeyMods,
_repeat: bool,
) {
}
fn key_up_event(&mut self, _ctx: &mut Context, _keycode: KeyCode, _keymods: KeyMods) {}
fn touch_event(&mut self, ctx: &mut Context, phase: TouchPhase, _id: u64, x: f32, y: f32) {
if phase == TouchPhase::Started {
self.mouse_button_down_event(ctx, MouseButton::Left, x, y);
}
if phase == TouchPhase::Ended {
self.mouse_button_up_event(ctx, MouseButton::Left, x, y);
}
if phase == TouchPhase::Moved {
self.mouse_motion_event(ctx, x, y);
}
}
fn raw_mouse_motion(&mut self, _ctx: &mut Context, _dx: f32, _dy: f32) {}
fn window_minimized_event(&mut self, _ctx: &mut Context) {}
fn window_restored_event(&mut self, _ctx: &mut Context) {}
fn quit_requested_event(&mut self, _ctx: &mut Context) {}
fn files_dropped_event(&mut self, _ctx: &mut Context) {}
}