euv-core 0.48.1

Core cross-platform runtime for euv featuring arena-based fine-grained reactivity, deterministic layout, flat scene graph, multi-mode rendering, and direct OS platform adapters.
Documentation
use super::*;

/// Handle returned by scoped system event hooks allowing optional manual early unregistration.
#[derive(Clone, Copy, Data, Debug, Eq, Hash, New, PartialEq)]
pub struct SystemEventSubscription {
    /// Monotonic listener identifier inside the thread-local `SystemEventHub`.
    #[get(type(copy))]
    pub(crate) id: u64,
}

/// Deterministic state machine deduplicating noisy OS callbacks and enforcing canonical cross-platform event ordering.
#[derive(Clone, Data, Debug, PartialEq)]
pub struct SystemEventNormalizer {
    /// Current canonical application lifecycle state.
    #[get(type(copy))]
    pub(crate) state: AppState,
    /// Whether the active application surface is currently visible (`Appear` emitted without matching `Disappear`).
    #[get(type(copy))]
    pub(crate) visible: bool,
    /// Most recently emitted window focus state for deduplication.
    #[get(skip)]
    pub(crate) last_focused: Option<bool>,
    /// Most recently emitted logical `(width, height, scale_factor)` resize tuple.
    #[get(skip)]
    pub(crate) last_resize: Option<(f32, f32, f32)>,
    /// Most recently emitted safe-area insets.
    #[get(skip)]
    pub(crate) last_safe_area: Option<SafeAreaInsets>,
    /// Most recently emitted screen orientation.
    #[get(skip)]
    pub(crate) last_orientation: Option<ScreenOrientation>,
    /// Most recently emitted OS light/dark theme.
    #[get(skip)]
    pub(crate) last_theme: Option<ThemeMode>,
    /// Most recently emitted OS locale string.
    #[get(skip)]
    pub(crate) last_locale: Option<String>,
    /// Most recently emitted virtual keyboard `(visible, height)` state.
    #[get(skip)]
    pub(crate) last_keyboard: Option<(bool, f32)>,
    /// Most recently emitted low-power mode flag.
    #[get(skip)]
    pub(crate) last_low_power: Option<bool>,
    /// Most recently emitted network reachability state.
    #[get(skip)]
    pub(crate) last_network: Option<NetworkStatus>,
    /// Most recently emitted sanitized 6-DOF device motion sample.
    #[get(skip)]
    pub(crate) last_device_motion: Option<DeviceMotionSample>,
}

/// Screen-aligned 6-DOF gravity, linear acceleration, and gyroscope sample delivered by real device motion sensors.
///
/// Linear vectors use the screen frame `+x` right, `+y` down, `+z` out of the screen in SI `m/s²`.
/// Angular rates use the native sensor right-hand convention (`gyro_x` about screen-right, `gyro_y`
/// about screen-up, `gyro_z` about the out-of-screen axis, positive counter-clockwise as seen by the user) in `rad/s`.
#[derive(Clone, Copy, Data, Debug, PartialEq)]
pub struct DeviceMotionSample {
    /// Gravity vector `x` component (`m/s²`, screen-right positive).
    #[get(type(copy))]
    pub(crate) gravity_x: f32,
    /// Gravity vector `y` component (`m/s²`, screen-down positive; `9.80665` when held upright).
    #[get(type(copy))]
    pub(crate) gravity_y: f32,
    /// Gravity vector `z` component (`m/s²`, out-of-screen positive; `-9.80665` lying face-up).
    #[get(type(copy))]
    pub(crate) gravity_z: f32,
    /// User-induced linear (shake/translation) acceleration `x` component in `m/s²`.
    #[get(type(copy))]
    pub(crate) linear_accel_x: f32,
    /// User-induced linear (shake/translation) acceleration `y` component in `m/s²`.
    #[get(type(copy))]
    pub(crate) linear_accel_y: f32,
    /// User-induced linear (shake/translation) acceleration `z` component in `m/s²`.
    #[get(type(copy))]
    pub(crate) linear_accel_z: f32,
    /// Angular velocity about the screen-right axis in `rad/s`.
    #[get(type(copy))]
    pub(crate) gyro_x: f32,
    /// Angular velocity about the screen-up axis in `rad/s`.
    #[get(type(copy))]
    pub(crate) gyro_y: f32,
    /// Angular velocity about the out-of-screen axis in `rad/s` (positive counter-clockwise as seen by the user).
    #[get(type(copy))]
    pub(crate) gyro_z: f32,
    /// Forward/backward tilt of the screen away from upright in radians (`+` = top tilted away from the user).
    #[get(type(copy))]
    pub(crate) pitch_rad: f32,
    /// In-screen-plane device rotation in radians (`+` = counter-clockwise as seen by the user).
    #[get(type(copy))]
    pub(crate) roll_rad: f32,
    /// Heading/azimuth in radians when reported by the host sensor fusion (`0.0` otherwise).
    #[get(type(copy))]
    pub(crate) yaw_rad: f32,
    /// Monotonic sensor timestamp in nanoseconds.
    #[get(type(copy))]
    pub(crate) timestamp_ns: u64,
    /// Whether this sample originates from a live hardware sensor stream.
    #[get(type(copy))]
    pub(crate) sensor_active: bool,
}

/// Internal scope-bound system event listener entry stored in `SystemEventHub`.
#[derive(CustomDebug)]
pub(crate) struct SystemEventListener {
    /// Unique listener identifier.
    pub(crate) id: u64,
    /// Reactive scope owning this listener, if registered inside a scope.
    pub(crate) owner_scope: Option<ScopeId>,
    /// Type-erased callback invoked when matching system events arrive.
    #[debug(skip)]
    pub(crate) callback: SystemEventCallback,
}

/// Thread-local registry of active scoped system event listeners.
#[derive(CustomDebug, Default)]
pub(crate) struct SystemEventHub {
    /// Monotonic listener identifier counter.
    pub(crate) next_id: u64,
    /// Active registered listeners in registration order.
    pub(crate) listeners: Vec<SystemEventListener>,
}