windowing_api 0.13.1

API for windowing system
Documentation
/// Event enum.
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq)]
pub enum Event {
    /// Mouse cursor enters window area.
    MouseEnter,

    /// Mouse cursor leaves window area.
    MouseLeave,

    /// Mouse button press / release.
    MouseButton {
        state: ElementState,
        button: MouseButton,
    },

    /// Mouse move.
    MouseMove { position: Position },

    /// Mouse scroll wheel rolled or touchpad scroll gesture.
    ScrollWheel { delta: ScrollDelta },

    // Key pressed/released.
    KeyEvent {
        state: ElementState,
        keycode: Option<Keycode>,
        is_repeat: bool,
        modifiers: KeyModifiers,
        text: Option<String>,
    },

    /// Window resized.
    Resize { width: i32, height: i32 },
}

/// Element state.
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum ElementState {
    Pressed,
    Released,
}

/// Mouse button enumeration.
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum MouseButton {
    Left,
    Right,
    Middle,
    Other(u8),
}

/// Position.
#[derive(Debug, Copy, Clone, PartialEq)]
pub struct Position {
    pub x: f32,
    pub y: f32,
}

/// Scroll delta enum.
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum ScrollDelta {
    /// Amount of lines to scroll horizontally and vertically.
    /// This is generated by mouse wheel.
    LineDelta(f32, f32),

    /// Amount of pixels to scroll horizontally and vertically.
    /// This is generated by touchpad.
    PixelDelta(f32, f32),
}

/// Keycode for the key that is not a printable key.
/// If there are more than one variant of the same key (like left/right or keypad),
/// you can use KeyModifiers to distinguish between them.
#[non_exhaustive]
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum Keycode {
    // function row
    Esc,
    F1,
    F2,
    F3,
    F4,
    F5,
    F6,
    F7,
    F8,
    F9,
    F10,
    F11,
    F12,
    F13,
    F14,
    F15,
    F16,
    F17,
    F18,
    F19,
    F20,
    PrintScreen,
    ScrollLock,
    Pause,

    // navigation
    Insert,
    Delete,
    Home,
    End,
    PageUp,
    PageDown,

    // arrows
    Left,
    Right,
    Up,
    Down,

    // modifiers
    Shift,
    Ctrl,
    Win,
    Alt,
    AltGr,

    // special
    Menu,
    Backspace,
    Tab,
    CapsLock,
    Return,
    Enter,
    Space,

    // symbols
    QuoteLeft,
    Minus,
    Equal,
    Asterisk,
    Plus,
    Period,
    Slash,
    BracketLeft,
    BracketRight,
    Backslash,
    Semicolon,
    Quote,
    Comma,

    // letters
    KeyA,
    KeyB,
    KeyC,
    KeyD,
    KeyE,
    KeyF,
    KeyG,
    KeyH,
    KeyI,
    KeyJ,
    KeyK,
    KeyL,
    KeyM,
    KeyN,
    KeyO,
    KeyP,
    KeyQ,
    KeyR,
    KeyS,
    KeyT,
    KeyU,
    KeyV,
    KeyW,
    KeyX,
    KeyY,
    KeyZ,

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

    // numeric keyboard
    NumLock,
}

/// Information of pressed special keys and
/// about the variant of the pressed key.
#[derive(Copy, Clone, Debug, PartialEq)]
pub struct KeyModifiers {
    pub shift: bool,
    pub ctrl: bool,
    pub alt: bool,
    pub win: bool,

    /// does the key belong to the keypad
    pub keypad: bool,

    /// is it the right variant of the key (like right shift, alt, etc.)
    /// this is not yet behaving correctly
    pub right: bool,
}