Skip to main content

magma_windowing/
window_event.rs

1use std::path::PathBuf;
2
3use magma_app::magma_ecs::entities::Entity;
4use magma_math::IVec2;
5
6use crate::window::WindowTheme;
7
8/// An event for signaling a window resize.
9#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Default)]
10pub struct WindowResized {
11    pub window: Entity,
12    pub width: u32,
13    pub height: u32,
14}
15
16/// An event signaling a requested redraw of the whole application.
17#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Default)]
18pub struct RedrawRequested;
19
20/// An event signaling a window has been created.
21#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Default)]
22pub struct WindowCreated {
23    pub window: Entity,
24}
25
26/// An event signaling that a window has been requested to close. It should live one more update cycle with a [`ClosingWindow`](crate::ClosingWindow)
27#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Default)]
28pub struct WindowCloseRequested {
29    pub window: Entity,
30}
31
32/// An event signaling a window has been closed. The corresponding entity will no longer exist at the time this is emmited.
33#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Default)]
34pub struct WindowClosed {
35    pub window: Entity,
36}
37
38/// An event signaling a window has been destroyed. The corresponding entity will no longer exist at the time this is emmited.
39#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Default)]
40pub struct WindowDestroyed;
41
42/// An event signaling that the cursor has moved within a window.
43#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Default)]
44pub struct CursorMoved {
45    pub window: Entity,
46    pub position: IVec2,
47}
48
49/// An event signaling the cursor has entered a winbdow.
50#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Default)]
51pub struct CursorEntered {
52    pub window: Entity,
53}
54
55/// An event signaling the cursor has left a window.
56#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Default)]
57pub struct CursorLeft {
58    pub window: Entity,
59}
60
61/// An event signaling a focus change for a window.
62#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Default)]
63pub struct WindowFocused {
64    pub window: Entity,
65    pub focus: bool,
66}
67
68/// An event signaling the window's occlusion has changed.
69#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
70pub enum WindowOcclusion {
71    /// The window is occluded by another window.
72    Occluded { window: Entity },
73    /// The window is not occluded anymore.
74    NotOccluded { window: Entity },
75}
76
77/// An event signaling file drag and drops.
78#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
79pub enum FileDragDrop {
80    /// A file has been dropped on a window.
81    Dropped { window: Entity, path: PathBuf },
82    /// A file is hovering over a window.
83    Hovered { window: Entity, path: PathBuf },
84    /// A file hover has been canceled.
85    HoverCanceled { window: Entity },
86}
87
88/// An event signaling that the window has moved.
89#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Default)]
90pub struct WindowMoved {
91    pub window: Entity,
92    pub position: IVec2,
93}
94
95/// An event signaling that the window's theme variant changed.
96#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Default)]
97pub struct WindowThemeChanged {
98    pub window: Entity,
99    pub theme: WindowTheme,
100}