Skip to main content

astrelis_ui/plugin/
event_types.rs

1//! Event types for the plugin system.
2//!
3//! These types allow plugins to receive and handle UI input events
4//! before per-widget-type dispatch.
5
6use crate::tree::{NodeId, UiTree};
7use astrelis_core::math::Vec2;
8
9/// A processed UI input event passed to plugins.
10#[derive(Debug, Clone)]
11pub enum UiInputEvent {
12    /// Mouse moved to a new position.
13    MouseMove { position: Vec2 },
14    /// Mouse button pressed.
15    MouseDown {
16        position: Vec2,
17        button: MouseButtonKind,
18    },
19    /// Mouse button released.
20    MouseUp {
21        position: Vec2,
22        button: MouseButtonKind,
23    },
24    /// Mouse wheel scrolled.
25    Scroll { position: Vec2, delta: Vec2 },
26    /// Keyboard key pressed.
27    KeyDown { key: KeyEventData },
28    /// Keyboard key released.
29    KeyUp { key: KeyEventData },
30    /// Character typed.
31    CharInput { ch: char },
32}
33
34/// Mouse button identifier.
35#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
36pub enum MouseButtonKind {
37    Left,
38    Right,
39    Middle,
40    Other(u16),
41}
42
43/// Keyboard event data.
44#[derive(Debug, Clone)]
45pub struct KeyEventData {
46    /// The physical key code.
47    pub physical_key: astrelis_winit::event::PhysicalKey,
48    /// Whether this is a repeat event.
49    pub is_repeat: bool,
50}
51
52/// Context provided to plugins during event handling.
53///
54/// Gives read/write access to the UI tree and relevant state
55/// so plugins can query layout, modify widgets, etc.
56pub struct PluginEventContext<'a> {
57    /// The UI tree (read/write).
58    pub tree: &'a mut UiTree,
59    /// Current mouse position.
60    pub mouse_position: Vec2,
61    /// The node under the cursor (if any).
62    pub hovered_node: Option<NodeId>,
63}