vizia_core/window/
window_event.rs

1use std::path::PathBuf;
2
3use crate::{entity::Entity, environment::ThemeMode, layout::cache::GeoChanged};
4use vizia_input::{Code, Key, MouseButton};
5use vizia_style::CursorIcon;
6use vizia_window::{WindowPosition, WindowSize};
7
8#[derive(Debug, Clone)]
9/// Data associated with a drop event.
10pub enum DropData {
11    /// Path to a dropped file.
12    File(PathBuf),
13    ///  Entity ID of a dropped entity.
14    Id(Entity),
15}
16
17impl From<Entity> for DropData {
18    fn from(value: Entity) -> Self {
19        DropData::Id(value)
20    }
21}
22
23impl From<PathBuf> for DropData {
24    fn from(value: PathBuf) -> Self {
25        DropData::File(value)
26    }
27}
28
29/// Events generated by the application in response to OS events as well as events that can be used
30/// to set properties of the window.
31#[derive(Debug, Clone)]
32pub enum WindowEvent {
33    /// Emitted when a window is closed. Can also be emitted by a view or model to close the window.
34    WindowClose,
35    /// Emitted when the window is moved.
36    WindowMoved(WindowPosition),
37    /// Emitted when a file is dragged and then dropped onto the window.
38    Drop(DropData),
39    /// Emitted when a mouse button is double clicked.
40    MouseDoubleClick(MouseButton),
41    /// Emitted when a mouse button is triple clicked
42    MouseTripleClick(MouseButton),
43    /// Emitted when a mouse button is pressed
44    MouseDown(MouseButton),
45    /// Emitted when a mouse button is released.
46    MouseUp(MouseButton),
47    /// Emitted when the primary mouse button or trigger key is pressed and then released on a view
48    Press {
49        /// Whether the press event was triggered by the mouse.
50        mouse: bool,
51    },
52    /// Emitted when the primary mouse button or trigger key is pressed on a view
53    PressDown {
54        /// Whether the press down event was triggered by the mouse.
55        mouse: bool,
56    },
57    /// Emitted when the mouse cursor is moved
58    MouseMove(f32, f32),
59    /// Emitted when the mouse scroll wheel is scrolled.
60    MouseScroll(f32, f32),
61    /// Emitted when the mouse cursor enters the bounding box of an entity.
62    MouseOver,
63    /// Emitted when the mouse cursor leaves the bounding box of an entity.
64    MouseOut,
65    /// Emitted when the mouse cursor enters an entity.
66    MouseEnter,
67    /// Emitted when the mouse cursor leaves an entity.
68    MouseLeave,
69    /// Emitted when an entity gains keyboard focus.
70    FocusIn,
71    /// Emitted when an entity loses keyboard focus.
72    FocusOut,
73    /// Emitted when an entity's focus visibility has changed.
74    FocusVisibility(bool),
75    /// Emitted when the window gains or loses focus
76    WindowFocused(bool),
77    /// Emitted when a character is typed.
78    CharInput(char),
79    /// Emitted when a keyboard key is pressed.
80    KeyDown(Code, Option<Key>),
81    /// Emitted when a keyboard key is released.
82    KeyUp(Code, Option<Key>),
83    /// Emited when the system window theme has changed.
84    ThemeChanged(ThemeMode),
85    /// Sets the mouse cursor icon.
86    SetCursor(CursorIcon),
87    /// Grabs the mouse cursor, preventing it from leaving the window.
88    GrabCursor(bool),
89    /// Sets the (x,y) position of the mouse cursor in window coordinates.
90    SetCursorPosition(u32, u32),
91    /// Sets the title of the window.
92    SetTitle(String),
93    /// Sets the size of the window.
94    SetSize(WindowSize),
95    /// Sets the position of the window.
96    SetPosition(WindowPosition),
97    /// Sets the maximum size of the window.
98    SetMaxSize(Option<WindowSize>),
99    /// Sets the minimum size of the window.
100    SetMinSize(Option<WindowSize>),
101    /// Sets whether the window is resizable.
102    SetResizable(bool),
103    /// Sets whether the window is minimized.
104    SetMinimized(bool),
105    /// Sets whether the window is maximized.
106    SetMaximized(bool),
107    /// Sets whether the window is visible.
108    SetVisible(bool),
109    /// Sets whether the window has decorations.
110    SetDecorations(bool),
111    /// Sets whether the window remains on top of other windows.
112    SetAlwaysOnTop(bool),
113    /// Emitted when mouse events have been captured.
114    MouseCaptureEvent,
115    /// Emitted when mouse events have been released.
116    MouseCaptureOutEvent,
117    // TODO: check if this includes margins + borders.
118    /// Emitted when an entity changes position or size.
119    GeometryChanged(GeoChanged),
120    /// Requests a redraw of the window contents.
121    Redraw,
122    /// Request a restyle.
123    Restyle,
124    /// Requests a relayout.
125    Relayout,
126    /// Move keyboard focus to the next navigable view.
127    FocusNext,
128    /// Move keyboard focus to the previous navigable view.
129    FocusPrev,
130    /// Prints the debug message to the console.
131    Debug(String),
132    /// Represents an action requested by an accessibility technology.
133    ActionRequest(accesskit::ActionRequest),
134    /// Reloads all application stylesheets.
135    ReloadStyles,
136    /// Enables or disabled mouse and keyboard input to the window.
137    SetEnabled(bool),
138    /// Puts the window in a drag state.
139    DragWindow,
140
141    /// Emitted when the window is destroyed.
142    Destroyed,
143}