rcus-core 0.1.1

Core types for rcus: retained view tree, style, input, and the host bridge protocol
Documentation
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct Modifiers {
    pub control: bool,
    pub alt: bool,
    pub shift: bool,
    pub meta: bool,
}

#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Key {
    Character(String),
    Enter,
    Escape,
    Tab,
    Backspace,
    Delete,
    ArrowLeft,
    ArrowRight,
    ArrowUp,
    ArrowDown,
    Home,
    End,
    PageUp,
    PageDown,
}

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum PointerButton {
    Primary,
    Secondary,
    Middle,
}

#[derive(Clone, Debug, PartialEq)]
pub enum InputEvent {
    KeyDown {
        key: Key,
        modifiers: Modifiers,
    },
    KeyUp {
        key: Key,
        modifiers: Modifiers,
    },
    PointerDown {
        x: f32,
        y: f32,
        button: PointerButton,
        modifiers: Modifiers,
    },
    PointerMove {
        x: f32,
        y: f32,
        modifiers: Modifiers,
    },
    PointerUp {
        x: f32,
        y: f32,
        button: PointerButton,
        modifiers: Modifiers,
    },
    Wheel {
        x: f32,
        y: f32,
        dx: f32,
        dy: f32,
    },
    Resize {
        width: f32,
        height: f32,
    },
    /// Background work finished, so the host should refresh whatever it draws
    /// from outside the view tree: a pty's latest output, a reloaded file, a
    /// finished task. A cross-thread redraw request arrives as a tick, on the
    /// thread that owns the window.
    Tick,
    FocusGained,
    FocusLost,
}

impl InputEvent {
    pub fn is_save_shortcut(&self) -> bool {
        matches!(
            self,
            Self::KeyDown {
                key: Key::Character(value),
                modifiers: Modifiers { control: true, shift: false, .. }
            } if value.eq_ignore_ascii_case("s")
        )
    }
}