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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/// A key
#[allow(missing_docs)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Key {
    LeftMouseButton,
    MiddleMouseButton,
    RightMouseButton,

    Key1,
    Key2,
    Key3,
    Key4,
    Key5,
    Key6,
    Key7,
    Key8,
    Key9,
    Key0,

    F1,
    F2,
    F3,
    F4,
    F5,
    F6,
    F7,
    F8,
    F9,
    F10,
    F11,
    F12,

    A,
    B,
    C,
    D,
    E,
    F,
    G,
    H,
    I,
    J,
    K,
    L,
    M,
    N,
    O,
    P,
    Q,
    R,
    S,
    T,
    U,
    V,
    W,
    X,
    Y,
    Z,

    Tab,
    Shift,
    Ctrl,
    Alt,
    Space,
    Enter,
    Backspace,
    Escape,
    Home,
    End,
    Minus,
    Plus,
    BracketOpen,
    BracketClose,
    Comma,
    Period,
    Semicolon,
    Quote,
    Tilde,
    Backslash,
    Slash,

    Left,
    Right,
    Up,
    Down,
}

/// A set of modifiers
#[derive(Clone, Copy, Debug)]
pub struct Modifiers {
    /// `true` if the control key is pressed, `false otherwise.
    pub ctrl: bool,
    /// `true` if the alt key is pressed, `false otherwise.
    pub alt: bool,
    /// `true` if the shift key is pressed, `false otherwise.
    pub shift: bool,
    /// `true` if the windows/super/command key is pressed, `false otherwise.
    pub logo: bool,
}

#[allow(missing_docs)]
impl Modifiers {
    pub fn none() -> Modifiers {
        Modifiers {
            ctrl: false,
            alt: false,
            shift: false,
            logo: false,
        }
    }

    pub fn ctrl() -> Modifiers {
        Modifiers {
            ctrl: true,
            alt: false,
            shift: false,
            logo: false,
        }
    }

    pub fn alt() -> Modifiers {
        Modifiers {
            ctrl: false,
            alt: true,
            shift: false,
            logo: false,
        }
    }

    pub fn shift() -> Modifiers {
        Modifiers {
            ctrl: false,
            alt: false,
            shift: true,
            logo: false,
        }
    }

    pub fn logo() -> Modifiers {
        Modifiers {
            ctrl: false,
            alt: false,
            shift: false,
            logo: true,
        }
    }
}

/// A user input event.
#[derive(Clone, Copy, Debug)]
pub enum Event {
    /// A button on some input device was pressed.
    Press(Key),
    /// A button on some input device was released.
    Release(Key),
    /// Modifiers were changed.
    Modifiers(Modifiers),
    /// The window was resized to the given dimensions.
    Resize(f32, f32),
    /// Some motion input was received (e.g. moving mouse or joystick axis).
    Motion(f32, f32),
    /// The mouse cursor was moved to a location.
    Cursor(f32, f32),
    /// The mouse wheel or touchpad scroll gesture sent us some scroll event.
    Scroll(f32, f32),
    /// Text input was received, usually via the keyboard.
    Text(char),
    /// The window was focused or lost focus.
    Focus(bool),
    /// The application exited it's main event loop
    Exit,
}

/// Events that can be subscribed to on a node
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum NodeEvent {
    /// Occurs when the mouse starts hovering the widget
    MouseEnter,
    /// Occurs when the mouse stops hovering the widget
    MouseLeave,
    /// Occurs when the mouse moves while hovering the widget
    MouseMove,
    /// Occurs when a mouse button goes down while hovering the widget
    MouseDown(Key),
    /// Occurs when a mouse button goes up while hovering the widget
    MouseUp(Key),
    /// Occurs when a mouse button goes up while hovering the widget, but only if the mouse didn't stop hovering for
    /// the entire duration of the click.
    MouseClick(Key),
}