lambda/
events.rs

1//! Event definitions for lambda runtimes and applications.
2
3use std::time::Instant;
4
5/// events generated by kernel interactions with the component.
6#[derive(Debug, Clone)]
7pub enum ComponentEvent {
8  Attached { name: String },
9  Detached { name: String },
10}
11
12/// Window events are generated in response to window events coming from
13/// the windowing system.
14#[derive(Debug, Clone)]
15pub enum WindowEvent {
16  Close,
17  Resize { width: u32, height: u32 },
18}
19
20/// Runtime events are generated by the Runtimes themselves.
21#[derive(Debug, Clone)]
22pub enum RuntimeEvent {
23  Initialized,
24  Shutdown,
25  ComponentPanic { message: String },
26}
27
28/// Exports the winit virtual key codes to this namespace for convenience.
29pub use lambda_platform::winit::winit_exports::VirtualKeyCode as VirtualKey;
30
31/// Keyboard events are generated in response to keyboard events coming from
32/// the windowing system.
33#[derive(Debug, Clone)]
34pub enum Key {
35  /// Emitted when a key is pressed.
36  Pressed {
37    scan_code: u32,
38    virtual_key: Option<VirtualKey>,
39  },
40  /// Emitted when a key is released.
41  Released {
42    scan_code: u32,
43    virtual_key: Option<VirtualKey>,
44  },
45  /// Emitted when a modifier key is pressed.
46  ModifierPressed {
47    modifier: u32,
48    virtual_key: VirtualKey,
49  },
50}
51
52/// Mouse buttons.
53#[derive(Debug, Clone)]
54pub enum Button {
55  Left,
56  Right,
57  Middle,
58  Other(u16),
59}
60
61/// Mouse events are generated in response to mouse events coming from the
62/// windowing system. The coordinates are in logical pixels.
63#[derive(Debug, Clone)]
64pub enum Mouse {
65  /// Emitted when the mouse cursor is moved within the window.
66  Moved {
67    x: f64,
68    y: f64,
69    dx: f64,
70    dy: f64,
71    device_id: u32,
72  },
73  /// Emitted when the mouse wheel is scrolled.
74  Scrolled { device_id: u32 },
75  /// Emitted when a mouse button is pressed.
76  Pressed {
77    x: f64,
78    y: f64,
79    button: Button,
80    device_id: u32,
81  },
82  /// Emitted when a mouse button is released.
83  Released {
84    x: f64,
85    y: f64,
86    button: Button,
87    device_id: u32,
88  },
89  /// Emitted when the mouse cursor leaves the window.
90  LeftWindow { device_id: u32 },
91  /// Emitted when the mouse cursor enters the window.
92  EnteredWindow { device_id: u32 },
93}
94
95/// Generic Event Enum which encapsulates all possible events that will be
96/// emitted by the LambdaKernel
97#[derive(Debug, Clone)]
98pub enum Events {
99  Component {
100    event: ComponentEvent,
101    issued_at: Instant,
102  },
103  Window {
104    event: WindowEvent,
105    issued_at: Instant,
106  },
107  Runtime {
108    event: RuntimeEvent,
109    issued_at: Instant,
110  },
111  Keyboard {
112    event: Key,
113    issued_at: Instant,
114  },
115  Mouse {
116    event: Mouse,
117    issued_at: Instant,
118  },
119}