carbide_core/event/input.rs
1use crate::event::touch::Touch;
2use crate::event::Motion;
3
4/// The event type that is used by carbide to track inputs from the world. Events yielded by polling
5/// window backends should be converted to this type. This can be thought of as the event type
6/// which is supplied by the window backend to drive the state of the `Ui` forward.
7///
8/// This type is solely used within the `Ui::handle_event` method. The `Input` events are
9/// interpreted to create higher level `Event`s (such as DoubleClick, WidgetCapturesKeyboard, etc)
10/// which are stored for later processing by `Widget`s, which will occur during the call to
11/// `Ui::set_widgets`.
12///
13/// **Note:** `Input` events that contain co-ordinates must be oriented with (0, 0) at the middle
14/// of the window with the *y* axis pointing upwards (Cartesian co-ordinates). All co-ordinates and
15/// dimensions must be given as `Scalar` (DPI agnostic) values. Many windows provide coordinates
16/// with the origin in the top left with *y* pointing down, so you might need to translate these
17/// co-ordinates when converting to this event. Also be sure to invert the *y* axis of MouseScroll
18/// events.
19#[derive(Clone, Debug, PartialEq)]
20pub enum Input {
21 /// A button on some input device was pressed.
22 Press(input::Button),
23 /// A button on some input device was released.
24 Release(input::Button),
25 /// The window was received to the given dimensions.
26 Resize(f64, f64),
27 /// Some motion input was received (e.g. moving mouse or joystick axis).
28 Motion(Motion),
29 /// Input from a touch surface/screen.
30 Touch(Touch),
31 /// Text input was received, usually via the keyboard.
32 Text(String),
33 /// The window was focused or lost focus.
34 Focus(bool),
35 /// The backed requested to redraw.
36 Redraw,
37}
38
39
40impl From<Touch> for Input {
41 fn from(touch: Touch) -> Self {
42 Input::Touch(touch)
43 }
44}
45
46impl From<Motion> for Input {
47 fn from(motion: Motion) -> Self {
48 Input::Motion(motion)
49 }
50}