plushie-core 0.7.1

Core types and protocol for Plushie (no iced dependency)
Documentation
//! Typed pointer event data for the wire protocol.
//!
//! These structs represent the data payload of pointer and viewport
//! events. They are shared between the SDK (which parses them from
//! wire JSON) and could be used by the renderer to construct events
//! with typed fields.

use crate::key::{Key, MouseButton, PointerKind};
use crate::protocol::KeyModifiers;

/// Data from a pointer press event (mouse button down, touch start).
#[derive(Debug, Clone)]
pub struct PointerPress {
    /// X coordinate.
    pub x: f32,
    /// Y coordinate.
    pub y: f32,
    /// Pointer button.
    pub button: MouseButton,
    /// Pointer kind (Mouse, Touch, Pen).
    pub pointer: PointerKind,
    /// Finger index for multi-touch events.
    pub finger: Option<u64>,
    /// Active modifier keys.
    pub modifiers: KeyModifiers,
    /// Whether the event was consumed by a widget before reaching the
    /// global subscription layer.
    pub captured: bool,
}

/// Data from a pointer release event (mouse button up, touch end).
#[derive(Debug, Clone)]
pub struct PointerRelease {
    /// X coordinate.
    pub x: f32,
    /// Y coordinate.
    pub y: f32,
    /// Pointer button.
    pub button: MouseButton,
    /// Pointer kind (Mouse, Touch, Pen).
    pub pointer: PointerKind,
    /// Finger index for multi-touch events.
    pub finger: Option<u64>,
    /// Active modifier keys.
    pub modifiers: KeyModifiers,
    /// Whether the event was consumed by a widget before reaching the
    /// global subscription layer.
    pub captured: bool,
    /// Whether a touch release happened outside the widget's bounds
    /// (touch `lost` event). Absent for mouse / pen releases.
    pub lost: Option<bool>,
}

/// Data from a pointer move event.
#[derive(Debug, Clone)]
pub struct PointerMove {
    /// X coordinate.
    pub x: f32,
    /// Y coordinate.
    pub y: f32,
    /// Pointer kind (Mouse, Touch, Pen).
    pub pointer: PointerKind,
    /// Finger index for multi-touch events.
    pub finger: Option<u64>,
    /// Active modifier keys.
    pub modifiers: KeyModifiers,
    /// Whether the event was consumed by a widget before reaching the
    /// global subscription layer.
    pub captured: bool,
}

/// Data from a raw scroll input event (mouse wheel, trackpad).
///
/// Distinct from [`ScrollPosition`] which reports where a scrollable
/// widget's viewport ended up. This reports the raw pointer input.
#[derive(Debug, Clone)]
pub struct PointerScroll {
    /// X coordinate.
    pub x: f32,
    /// Y coordinate.
    pub y: f32,
    /// Scroll delta on the X axis.
    pub delta_x: f32,
    /// Scroll delta on the Y axis.
    pub delta_y: f32,
    /// Pointer kind (Mouse, Touch, Pen).
    pub pointer: PointerKind,
    /// Active modifier keys.
    pub modifiers: KeyModifiers,
    /// Whether the event was consumed by a widget before reaching the
    /// global subscription layer.
    pub captured: bool,
}

/// Data from a pointer enter / exit event.
///
/// Coordinates are populated when the event originates from a canvas
/// element (where they carry meaning) and `None` for widget-level
/// enter / exit (where they don't).
#[derive(Debug, Clone, Default)]
pub struct PointerBoundary {
    /// X coordinate (canvas sources only).
    pub x: Option<f32>,
    /// Y coordinate (canvas sources only).
    pub y: Option<f32>,
    /// Whether the event was consumed by a widget before reaching the
    /// global subscription layer.
    pub captured: bool,
}

/// Data from a drag event.
#[derive(Debug, Clone)]
pub struct PointerDrag {
    /// X coordinate.
    pub x: f32,
    /// Y coordinate.
    pub y: f32,
    /// Pointer kind (Mouse, Touch, Pen).
    pub pointer: PointerKind,
    /// Active modifier keys.
    pub modifiers: KeyModifiers,
    /// Whether the event was consumed by a widget before reaching the
    /// global subscription layer.
    pub captured: bool,
}

/// Viewport state from a scrollable widget's "scrolled" event.
///
/// Reports where the scrollable viewport ended up after scrolling.
/// Distinct from [`PointerScroll`] which reports raw wheel input.
#[derive(Debug, Clone)]
pub struct ScrollPosition {
    /// Absolute x.
    pub absolute_x: f32,
    /// Absolute y.
    pub absolute_y: f32,
    /// Relative x.
    pub relative_x: f32,
    /// Relative y.
    pub relative_y: f32,
    /// Bounds width.
    pub bounds_width: f32,
    /// Bounds height.
    pub bounds_height: f32,
    /// Content width.
    pub content_width: f32,
    /// Content height.
    pub content_height: f32,
}

/// Data from a widget-level key press or release event.
#[derive(Debug, Clone)]
pub struct KeyData {
    /// The logical key (typed enum with aliases).
    pub key: Key,
    /// Key after modifier application (e.g., Shift+a produces 'A').
    pub modified_key: Option<Key>,
    /// Physical key code (layout-independent).
    pub physical_key: Option<Key>,
    /// Active modifier keys.
    pub modifiers: KeyModifiers,
    /// Text generated by the key press, if any.
    pub text: Option<String>,
    /// Whether this is an auto-repeat event.
    pub repeat: bool,
}

/// Data from a window or widget resize event.
#[derive(Debug, Clone, Copy)]
pub struct ResizeDimensions {
    /// Width in pixels.
    pub width: f32,
    /// Height in pixels.
    pub height: f32,
}