euv-core 0.52.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::*;

/// Unified host-declared rendering channel shared across HarmonyOS, Wearables, MiniApps, and QuickApps.
#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub enum HostRenderChannel {
    /// Direct native GPU rendering on a verified host surface (Vulkan / GLES3 / Metal).
    GpuDirect,
    /// GPU texture upload from a CPU software framebuffer.
    GpuUpload,
    /// Native CPU software pixel buffer (`OH_NativeWindow` / watch framebuffer).
    #[default]
    SoftwareBuffer,
    /// Host `<canvas>` 2D context (`putImageData`).
    Canvas2d,
    /// Host `<canvas>` WebGL 1.0 context.
    WebGl,
    /// Host `<canvas>` WebGL 2.0 context.
    WebGl2,
}

/// All 7 HarmonyOS / OpenHarmony physical device categories unified by `HarmonyPlatform`.
#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub enum HarmonyDeviceType {
    /// HarmonyOS smartphone (`deviceType: "phone"`).
    #[default]
    Phone,
    /// HarmonyOS tablet (`deviceType: "tablet"`).
    Tablet,
    /// HarmonyOS PC / 2-in-1 desktop (`deviceType: "2in1"`).
    Pc2In1,
    /// HarmonyOS foldable phone/tablet with dynamic hinge transitions (`"foldable"`).
    Foldable,
    /// HarmonyOS Watch / Wearable (`deviceType: "wearable"`).
    Watch,
    /// HarmonyOS Smart TV / Vision (`deviceType: "tv"`).
    Tv,
    /// HarmonyOS Automotive / Smart Cockpit (`deviceType: "car"`).
    Automotive,
}

/// Physical hinge posture state reported by HarmonyOS foldable devices (`display.FoldStatus`).
#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub enum HarmonyFoldState {
    /// Device is closed to its compact cover screen.
    Folded,
    /// Device is partially unfolded (tent / flex laptop posture).
    HalfFolded,
    /// Device is fully unfolded to its tablet-class inner display.
    #[default]
    Expanded,
}

/// Active native rendering path bound to HarmonyOS `OHNativeWindow`.
#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub enum HarmonyGraphicsApi {
    /// Direct GPU rendering over Khronos Vulkan (`VK_OHOS_surface`).
    Vulkan,
    /// Direct GPU rendering over EGL + OpenGL ES 3.0 (`eglCreateWindowSurface`).
    #[default]
    OpenGlEs3,
    /// Reference CPU software buffer upload via `OH_NativeWindow_NativeWindowRequestBuffer` / `FlushBuffer`.
    SoftwareBuffer,
}

/// Stage-Model HarmonyOS `UIAbility` and `WindowStage` lifecycle hooks normalized into EUV `SystemEvent`s.
#[derive(Clone, Debug, PartialEq)]
pub enum HarmonyLifecycleHook {
    /// `UIAbility.onCreate(want)` creating a fresh ability session.
    OnCreate {
        /// Optional incoming Want URI deep link.
        want_uri: Option<String>,
    },
    /// `UIAbility.onWindowStageCreate(windowStage)` attaching `OHNativeWindow` / `XComponent`.
    OnWindowStageCreate {
        /// Raw `OHNativeWindow*` pointer (`0` when deferred).
        native_window: usize,
        /// Raw `OH_NativeXComponent*` pointer (`0` when deferred).
        xcomponent: usize,
    },
    /// `UIAbility.onForeground()` resuming rendering and active interactive frame pumping.
    OnForeground,
    /// `WindowStageEventType.ACTIVE` signaling active window input focus.
    OnWindowActive,
    /// `WindowStageEventType.INACTIVE` signaling transient focus loss (control center, multi-window switch).
    OnWindowInactive,
    /// `UIAbility.onBackground()` freezing rendering, timers, and frame pumping (0% CPU/GPU).
    OnBackground,
    /// `UIAbility.onWindowStageDestroy()` detaching native surface handles safely.
    OnWindowStageDestroy,
    /// `UIAbility.onDestroy()` terminating the ability session gracefully.
    OnDestroy,
    /// `UIAbility.onMemoryLevel(level)` reporting OS memory pressure.
    OnMemoryLevel(i32),
    /// `UIAbility.onConfigurationUpdate` updating theme, locale, density, or foldable state.
    OnConfigurationUpdate {
        /// Updated OS appearance mode (`Light` / `Dark`).
        theme: ThemeMode,
        /// Updated BCP-47 locale tag.
        locale: String,
        /// Updated display density scale factor (`vp -> px`).
        density: f32,
        /// Optional updated foldable hinge posture.
        fold_state: Option<HarmonyFoldState>,
    },
    /// System gesture or hardware Back button press (`onBackPress`).
    OnBackPress,
    /// Warm-launch `UIAbility.onNewWant(want)` delivering a new deep-link URI.
    OnNewWant(String),
    /// Window status or layout mode change (`window.WindowStatusType` on HarmonyOS PC/Tablet/Foldable).
    OnWindowModeChanged(HarmonyWindowMode),
    /// Host network reachability update (`@ohos.net.connection`).
    OnNetworkStatusChanged(NetworkStatus),
}

/// HarmonyOS Stage-Model window presentation modes spanning Phone fullscreen, Tablet split-screen, and PC freeform desktop windows.
#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub enum HarmonyWindowMode {
    /// Standard single-surface fullscreen application window (Phone / Watch / TV / Car).
    #[default]
    Fullscreen,
    /// Freeform resizable desktop window on HarmonyOS PC (`2in1`) or Tablet desktop mode.
    Floating,
    /// Maximized desktop window on HarmonyOS PC (`2in1`).
    Maximized,
    /// Minimized desktop window on HarmonyOS PC (`2in1`).
    Minimized,
    /// Split-screen primary pane on HarmonyOS Tablet, Foldable, or PC.
    SplitPrimary,
    /// Split-screen secondary pane on HarmonyOS Tablet, Foldable, or PC.
    SplitSecondary,
}

/// Outbound ArkTS / N-API host command emitted by `HarmonyPlatform` for PC desktop windowing, cursor, IME, and OS bridges.
#[derive(Clone, Debug, PartialEq)]
pub enum HarmonyHostCommand {
    /// Updates the HarmonyOS PC/Tablet window title (`win.setWindowTitle`).
    SetWindowTitle(String),
    /// Transitions the HarmonyOS PC/Tablet window mode (`maximize` / `minimize` / `recover` / `setWindowLayoutFullScreen`).
    SetWindowMode(HarmonyWindowMode),
    /// Requests a freeform window resize on HarmonyOS PC (`win.resize`).
    SetWindowSize {
        /// Target logical width in vp.
        width: u32,
        /// Target logical height in vp.
        height: u32,
    },
    /// Shows or hides native HarmonyOS PC window titlebar decorations (`win.setWindowDecorVisible`).
    SetDecorations(bool),
    /// Pins or unpins a HarmonyOS PC window above sibling windows (`win.setWindowTopmost`).
    SetAlwaysOnTop(bool),
    /// Updates the desktop pointer cursor style (`pointer.setPointerStyle`).
    SetCursor(CursorIcon),
    /// Shows or hides the HarmonyOS soft keyboard / IME (`@ohos.inputMethod`).
    SetIme {
        /// Whether text input is active.
        enabled: bool,
        /// Logical anchor rectangle for candidate bar placement.
        rect: Rect,
    },
    /// Writes UTF-8 text to `@ohos.pasteboard`.
    SetClipboard(String),
    /// Triggers short haptic feedback via `@ohos.vibrator`.
    VibrateShort,
    /// Requests closing a HarmonyOS window (`win.destroyWindow`).
    CloseWindow(WindowId),
}