cotis-wgpu 0.1.0-alpha

Desktop wgpu renderer backend for Cotis
Documentation
//! Input state collected from winit and exposed through Cotis interactivity traits.
//!
//! [`InputSnapshot`] is updated by the renderer's event loop on each
//! [`cotis::renders::CotisRenderer::draw_frame`] / `pump_events` call.
//! Cotis interactivity traits on [`crate::renderer::CotisWgpuRenderer`] (see [`crate::cotis_traits`])
//! read from this snapshot.

use indexmap::IndexSet;

use cotis_utils::interactivity::keyboard::KeyboardKey;
use cotis_utils::interactivity::mouse::MouseButton;
use cotis_utils::math::Vector2;

/// Snapshot of keyboard and mouse state for the current frame.
#[derive(Debug, Clone, Default)]
pub struct InputSnapshot {
    /// Cursor position in physical window pixels.
    pub mouse_position: Vector2,
    /// Mouse buttons currently held down.
    pub mouse_buttons: IndexSet<MouseButton>,
    /// Keyboard keys currently held down.
    pub pressed_keys: IndexSet<KeyboardKey>,
    /// Text input characters received this frame (IME preedit).
    pub pressed_chars: Vec<char>,
    /// Scroll wheel delta accumulated this frame (lines or pixels, depending on winit event).
    pub scroll_delta: Vector2,
}

impl InputSnapshot {
    /// Returns and clears the accumulated text input characters for this frame.
    ///
    /// Call once per frame to consume IME/preedit input without duplication.
    pub fn take_pressed_chars(&mut self) -> Vec<char> {
        std::mem::take(&mut self.pressed_chars)
    }

    /// Returns and clears the accumulated scroll delta for this frame.
    ///
    /// Call once per frame to consume wheel movement without duplication.
    pub fn take_scroll_delta(&mut self) -> Vector2 {
        std::mem::take(&mut self.scroll_delta)
    }
}