Skip to main content

zenthra_core/
event.rs

1// crates/zenthra-core/src/event.rs
2
3use glam::Vec2;
4
5#[derive(Debug, Clone, PartialEq)]
6pub enum Event {
7    // ── Pointer ──────────────────────────────────────────────
8    PointerMoved { pos: Vec2 },
9    PointerPressed { pos: Vec2, button: PointerButton },
10    PointerReleased { pos: Vec2, button: PointerButton },
11    PointerEntered,
12    PointerLeft,
13    Scroll { delta: Vec2 },
14
15    // ── Keyboard ─────────────────────────────────────────────
16    KeyPressed { key: KeyCode, modifiers: Modifiers },
17    KeyReleased { key: KeyCode, modifiers: Modifiers },
18    TextInput { ch: char },
19
20    // ── Focus ─────────────────────────────────────────────────
21    FocusGained,
22    FocusLost,
23
24    // ── Window ───────────────────────────────────────────────
25    Resized { width: u32, height: u32 },
26    CloseRequested,
27}
28
29#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
30pub enum PointerButton {
31    Primary,
32    Secondary,
33    Middle,
34}
35
36#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
37pub struct Modifiers {
38    pub shift: bool,
39    pub ctrl: bool,
40    pub alt: bool,
41    pub meta: bool,
42}
43
44#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
45pub enum KeyCode {
46    Backspace,
47    Delete,
48    Tab,
49    Return,
50    Escape,
51    Left,
52    Right,
53    Up,
54    Down,
55    Home,
56    End,
57    PageUp,
58    PageDown,
59    Other(u32),
60}
61
62/// What a widget returns after handling an event.
63#[derive(Debug, Clone, Copy, PartialEq, Eq)]
64pub enum EventResponse {
65    /// Stop propagation — this widget consumed the event.
66    Consumed,
67    /// Let it bubble up.
68    Ignored,
69}