1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
use std::path::PathBuf;

use crate::{entity::Entity, environment::ThemeMode, layout::cache::GeoChanged};
use vizia_input::{Code, Key, MouseButton};
use vizia_style::CursorIcon;
use vizia_window::{WindowPosition, WindowSize};

#[derive(Debug, Clone)]
pub enum DropData {
    File(PathBuf),
    Id(Entity),
}

impl From<Entity> for DropData {
    fn from(value: Entity) -> Self {
        DropData::Id(value)
    }
}

impl From<PathBuf> for DropData {
    fn from(value: PathBuf) -> Self {
        DropData::File(value)
    }
}

/// Events generated by the application in response to OS events as well as events that can be used
/// to set properties of the window.
#[derive(Debug, Clone)]
pub enum WindowEvent {
    /// Emitted when a window is closed. Can also be emitted by a view or model to close the window.
    WindowClose,
    /// Emitted when a file is dragged and then dropped onto the window.
    Drop(DropData),
    /// Emitted when a mouse button is double clicked.
    MouseDoubleClick(MouseButton),
    /// Emitted when a mouse button is triple clicked
    MouseTripleClick(MouseButton),
    /// Emitted when a mouse button is pressed
    MouseDown(MouseButton),
    /// Emitted when a mouse button is released.
    MouseUp(MouseButton),
    /// Emitted when the primary mouse button or trigger key is pressed and then released on a view
    Press {
        mouse: bool,
    },
    /// Emitted when the primary mouse button or trigger key is pressed on a view
    PressDown {
        mouse: bool,
    },
    /// Emitted when the mouse cursor is moved
    MouseMove(f32, f32),
    /// Emitted when the mouse scroll wheel is scrolled.
    MouseScroll(f32, f32),
    /// Emitted when the mouse cursor enters the bounding box of an entity.
    MouseOver,
    /// Emitted when the mouse cursor leaves the bounding box of an entity.
    MouseOut,
    /// Emitted when the mouse cursor enters an entity.
    MouseEnter,
    /// Emitted when the mouse cursor leaves an entity.
    MouseLeave,
    // Emitted when an entity gains keyboard focus.
    FocusIn,
    // Emitted when an entity loses keyboard focus.
    FocusOut,
    /// Emitted when a character is typed.
    CharInput(char),
    /// Emitted when a keyboard key is pressed.
    KeyDown(Code, Option<Key>),
    /// Emitted when a keyboard key is released.
    KeyUp(Code, Option<Key>),
    /// Emited when the system window theme has changed.
    ThemeChanged(ThemeMode),
    /// Sets the mouse cursor icon.
    SetCursor(CursorIcon),
    /// Grabs the mouse cursor, preventing it from leaving the window.
    GrabCursor(bool),
    /// Sets the (x,y) position of the mouse cursor in window coordinates.
    SetCursorPosition(u32, u32),
    /// Sets the title of the window.
    SetTitle(String),
    /// Sets the size of the window.
    SetSize(WindowSize),
    /// Sets the position of the window.
    SetPosition(WindowPosition),
    /// Sets the maximum size of the window.
    SetMaxSize(Option<WindowSize>),
    /// Sets the minimum size of the window.
    SetMinSize(Option<WindowSize>),
    /// Sets whether the window is resizable.
    SetResizable(bool),
    /// Sets whether the window is minimized.
    SetMinimized(bool),
    /// Sets whether the window is maximized.
    SetMaximized(bool),
    /// Sets whether the window is visible.
    SetVisible(bool),
    /// Sets whether the window has decorations.
    SetDecorations(bool),
    /// Sets whether the window remains on top of other windows.
    SetAlwaysOnTop(bool),
    /// Emitted when mouse events have been captured.
    MouseCaptureEvent,
    /// Emitted when mouse events have been released.
    MouseCaptureOutEvent,
    // TODO: check if this includes margins + borders.
    /// Emitted when an entity changes position or size.
    GeometryChanged(GeoChanged),
    /// Requests a redraw of the window contents.
    Redraw,
    /// Request a restyle.
    Restyle,
    /// Requests a relayout.
    Relayout,
    /// Move keyboard focus to the next navigable view.
    FocusNext,
    /// Move keyboard focus to the previous navigable view.
    FocusPrev,
    /// Prints the debug message to the console.
    Debug(String),
    ActionRequest(accesskit::ActionRequest),
    /// Reloads all application stylesheets.
    ReloadStyles,

    SetEnabled(bool),

    DragWindow,

    // ToDo: Move this
    Destroyed,
}