Skip to main content

HarmonyPlatform

Struct HarmonyPlatform 

Source
pub struct HarmonyPlatform { /* private fields */ }
Expand description

Unified HarmonyOS / OpenHarmony platform backend bridging ArkUI XComponent, OHNativeWindow, EGL/GLES3/Vulkan, and NAPI.

Implementations§

Source§

impl HarmonyPlatform

ArkUI XComponent binding, avoidArea safe-area, foldable transition, touch/key/IME, and UIAbility lifecycle hooks for HarmonyPlatform.

Source

pub fn for_device_type(device_type: HarmonyDeviceType) -> Self

Creates a HarmonyPlatform configured for any of the 7 HarmonyOS device form factors.

§Arguments
  • HarmonyDeviceType - Target HarmonyOS device category.
§Returns
  • Self - Configured HarmonyOS platform backend.
Source

pub fn primary_window_id(&self) -> Option<WindowId>

Returns the primary XComponent WindowId, if created.

§Arguments
  • &Self - HarmonyOS platform reference.
§Returns
  • Option<WindowId> - Primary window handle.
Source

pub fn attach_xcomponent( &mut self, native_window: usize, xcomponent: usize, phys_width: u32, phys_height: u32, )

Attaches live ArkUI OHNativeWindow* and OH_NativeXComponent* handles received from OnSurfaceCreatedCB.

§Arguments
  • &Self - Mutable HarmonyOS platform.
  • usize - Raw OHNativeWindow* pointer.
  • usize - Raw OH_NativeXComponent* pointer.
  • u32 - Physical surface width in pixels.
  • u32 - Physical surface height in pixels.
Source

pub fn detach_xcomponent(&mut self)

Detaches ArkUI OHNativeWindow* safely on OnSurfaceDestroyedCB and cancels dangling touches.

§Arguments
  • &Self - Mutable HarmonyOS platform.
Source

pub fn update_avoid_area(&mut self, avoid: HarmonyAvoidArea)

Updates HarmonyOS window.AvoidArea insets and emits SafeAreaChanged plus KeyboardVisibilityChanged.

§Arguments
  • &Self - Mutable HarmonyOS platform.
  • HarmonyAvoidArea - Physical-pixel avoid area from @ohos.window.
Source

pub fn handle_lifecycle_hook( &mut self, hook: HarmonyLifecycleHook, ) -> Vec<WindowEvent>

Translates a Stage-Model HarmonyLifecycleHook into canonical EUV SystemEvents and Freeze/Resume/Destroy transitions.

§Arguments
  • &Self - Mutable HarmonyOS platform.
  • HarmonyLifecycleHook - Native ArkTS UIAbility / WindowStage callback payload.
§Returns
  • Vec<WindowEvent> - Normalized events also enqueued for poll_events().
Source

pub fn handle_touch_event( &mut self, touch_type: i32, raw_id: i32, phys_x: f32, phys_y: f32, ) -> Vec<WindowEvent>

Translates an OpenHarmony OH_NativeXComponent touch contact action into normalized EUV pointer events.

§Arguments
  • &Self - Mutable HarmonyOS platform.
  • i32 - OpenHarmony touch action (HARMONY_TOUCH_DOWN..HARMONY_TOUCH_CANCEL).
  • i32 - Raw contact identifier.
  • f32 - Component-local physical X coordinate.
  • f32 - Component-local physical Y coordinate.
§Returns
  • Vec<WindowEvent> - Normalized pointer events.
Source

pub fn handle_key_event( &mut self, ohos_code: i32, down: bool, ) -> Option<WindowEvent>

Translates an OpenHarmony NDK key code (KEYCODE_*) into a unified WindowEvent::KeyDown or KeyUp.

§Arguments
  • &Self - Mutable HarmonyOS platform.
  • i32 - OpenHarmony key code.
  • bool - true for key down, false for key up.
§Returns
  • Option<WindowEvent> - Translated keyboard event if recognized.
Source

pub fn handle_ime_commit(&mut self, text: String)

Dispatches committed HarmonyOS IME UTF-8 text into WindowEvent::TextInput.

§Arguments
  • &Self - Mutable HarmonyOS platform.
  • String - Committed UTF-8 text.
Source§

impl HarmonyPlatform

Source

pub fn get_profile(&self) -> HarmonyDeviceProfile

Source

pub fn get_mut_profile(&mut self) -> &mut HarmonyDeviceProfile

Source

pub fn set_profile(&mut self, val: HarmonyDeviceProfile) -> &mut Self

Source

pub fn get_fold_state(&self) -> HarmonyFoldState

Source

pub fn get_mut_fold_state(&mut self) -> &mut HarmonyFoldState

Source

pub fn set_fold_state(&mut self, val: HarmonyFoldState) -> &mut Self

Source

pub fn get_attached_native_window(&self) -> usize

Source

pub fn get_mut_attached_native_window(&mut self) -> &mut usize

Source

pub fn set_attached_native_window(&mut self, val: usize) -> &mut Self

Source

pub fn get_attached_xcomponent(&self) -> usize

Source

pub fn get_mut_attached_xcomponent(&mut self) -> &mut usize

Source

pub fn set_attached_xcomponent(&mut self, val: usize) -> &mut Self

Source

pub fn get_safe_area(&self) -> SafeAreaInsets

Source

pub fn get_mut_safe_area(&mut self) -> &mut SafeAreaInsets

Source

pub fn set_safe_area(&mut self, val: SafeAreaInsets) -> &mut Self

Source

pub fn get_lifecycle(&self) -> &MobileSessionLifecycle

Source

pub fn get_mut_lifecycle(&mut self) -> &mut MobileSessionLifecycle

Source

pub fn set_lifecycle(&mut self, val: MobileSessionLifecycle) -> &mut Self

Source

pub fn get_mut_primary_window(&mut self) -> &mut Option<WindowId>

Source

pub fn set_primary_window(&mut self, val: Option<WindowId>) -> &mut Self

Source

pub fn get_windows(&self) -> &HashMap<WindowId, HarmonyWindowRecord>

Source

pub fn get_mut_windows(&mut self) -> &mut HashMap<WindowId, HarmonyWindowRecord>

Source

pub fn set_windows( &mut self, val: HashMap<WindowId, HarmonyWindowRecord>, ) -> &mut Self

Source

pub fn get_pending_events(&self) -> &Vec<WindowEvent>

Source

pub fn get_mut_pending_events(&mut self) -> &mut Vec<WindowEvent>

Source

pub fn set_pending_events(&mut self, val: Vec<WindowEvent>) -> &mut Self

Source

pub fn get_mut_clipboard(&mut self) -> &mut Option<String>

Source

pub fn set_clipboard(&mut self, val: Option<String>) -> &mut Self

Source

pub fn get_storage(&self) -> &HashMap<String, String>

Source

pub fn get_mut_storage(&mut self) -> &mut HashMap<String, String>

Source

pub fn set_storage(&mut self, val: HashMap<String, String>) -> &mut Self

Source

pub fn get_route_stack(&self) -> &Vec<String>

Source

pub fn get_mut_route_stack(&mut self) -> &mut Vec<String>

Source

pub fn set_route_stack(&mut self, val: Vec<String>) -> &mut Self

Source

pub fn get_theme(&self) -> ThemeMode

Source

pub fn get_mut_theme(&mut self) -> &mut ThemeMode

Source

pub fn set_theme(&mut self, val: ThemeMode) -> &mut Self

Source

pub fn get_pump_paused(&self) -> bool

Source

pub fn get_mut_pump_paused(&mut self) -> &mut bool

Source

pub fn set_pump_paused(&mut self, val: bool) -> &mut Self

Trait Implementations§

Source§

impl Clone for HarmonyPlatform

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for HarmonyPlatform

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for HarmonyPlatform

Default HarmonyPlatform configured for HarmonyDeviceType::Phone.

Source§

fn default() -> Self

Creates a default HarmonyOS smartphone platform backend.

§Returns
  • Self - Default HarmonyPlatform.
Source§

impl PlatformBackend for HarmonyPlatform

PlatformBackend implementation for HarmonyPlatform.

Source§

fn kind(&self) -> PlatformKind

Returns PlatformKind::HarmonyOs.

§Arguments
  • &Self - HarmonyOS platform reference.
§Returns
  • PlatformKind - PlatformKind::HarmonyOs.
Source§

fn capabilities(&self) -> PlatformCapabilities

Returns HarmonyOS capabilities refined by the concrete HarmonyDeviceType.

§Arguments
  • &Self - HarmonyOS platform reference.
§Returns
  • PlatformCapabilities - Device-specific HarmonyOS capabilities.
Source§

fn create_window( &mut self, config: &WindowConfig, ) -> Result<WindowState, PlatformError>

Creates an ArkUI XComponent window state configured for the active HarmonyOS device profile.

§Arguments
  • &Self - Mutable HarmonyOS platform.
  • &WindowConfig - Declarative window config.
§Returns
  • Result<WindowState, PlatformError> - Created window state.
Source§

fn window_state(&self, id: WindowId) -> Option<WindowState>

Queries live WindowState for id.

§Arguments
  • &Self - HarmonyOS platform reference.
  • WindowId - Window identifier.
§Returns
  • Option<WindowState> - Window state if active.
Source§

fn raw_window_handle(&self, id: WindowId) -> RawWindowHandle

Returns RawWindowHandle::HarmonyXComponent carrying OHNativeWindow* and OH_NativeXComponent*.

§Arguments
  • &Self - HarmonyOS platform reference.
  • WindowId - Window identifier.
§Returns
  • RawWindowHandle - HarmonyOS XComponent handle.
Source§

fn poll_events(&mut self) -> Vec<WindowEvent>

Drains queued HarmonyOS XComponent, avoidArea, and UIAbility lifecycle events.

§Arguments
  • &Self - Mutable HarmonyOS platform.
§Returns
  • Vec<WindowEvent> - Pending events.
Source§

fn set_frame_pump_paused(&mut self, paused: bool)

Pauses or resumes the HarmonyOS OH_NativeVSync frame pump flag.

§Arguments
  • &Self - Mutable HarmonyOS platform.
  • bool - true to pause for background freeze.
Source§

fn is_frame_pump_paused(&self) -> bool

Returns whether the HarmonyOS frame pump is currently paused.

§Arguments
  • &Self - HarmonyOS platform reference.
§Returns
  • bool - Pause state.
Source§

fn present_framebuffer( &mut self, id: WindowId, framebuffer: &Framebuffer, ) -> Result<(), PlatformError>

Presents framebuffer to the attached OHNativeWindow* buffer or offscreen fallback snapshot.

§Arguments
  • &Self - Mutable HarmonyOS platform.
  • WindowId - Window identifier.
  • &Framebuffer - Rendered RGBA8 framebuffer.
§Returns
  • Result<(), PlatformError> - Presentation status.
Source§

fn read_clipboard(&self) -> Option<String>

Reads cached HarmonyOS pasteboard text.

§Arguments
  • &Self - HarmonyOS platform reference.
§Returns
  • Option<String> - Cached clipboard string.
Source§

fn write_clipboard(&mut self, text: &str) -> Result<(), PlatformError>

Writes text to the HarmonyOS pasteboard cache and native action bridge.

§Arguments
  • &Self - Mutable HarmonyOS platform.
  • &str - Clipboard text.
§Returns
  • Result<(), PlatformError> - Write status.
Source§

fn system_theme(&self) -> ThemeMode

Returns the active HarmonyOS appearance mode.

§Arguments
  • &Self - HarmonyOS platform reference.
§Returns
  • ThemeMode - Active appearance mode.
Source§

fn display_refresh_rate_hz(&self) -> f32

Returns the active HarmonyOS hardware display refresh rate in Hertz.

§Arguments
  • &Self - HarmonyOS platform reference.
§Returns
  • f32 - Active display refresh rate in Hertz.
Source§

fn wait_for_events(&mut self) -> Vec<WindowEvent>

Blocks with zero CPU usage until at least one OS or lifecycle event arrives, then drains all pending events. Read more
Source§

fn present_framebuffer_region( &mut self, id: WindowId, framebuffer: &Framebuffer, _damage: DamageRegion, ) -> Result<(), PlatformError>

Presents a damaged sub-region of a CPU-rendered RGBA8 Framebuffer when supported by the backend. Read more
Source§

impl PlatformHostAdapter for HarmonyPlatform

PlatformHostAdapter implementation for HarmonyPlatform.

Source§

fn device_form_factor(&self) -> DeviceFormFactor

Returns the concrete DeviceFormFactor matching this HarmonyOS device category.

§Arguments
  • &Self - HarmonyOS platform reference.
§Returns
  • DeviceFormFactor - Active HarmonyOS form factor.
Source§

fn host_vendor_name(&self) -> &'static str

Returns the canonical HarmonyOS device type string ("phone", "tablet", "2in1", "foldable", "wearable", "tv", "car").

§Arguments
  • &Self - HarmonyOS platform reference.
§Returns
  • &'static str - Canonical HarmonyOS device identifier.
Source§

impl PlatformLifecycleBridge for HarmonyPlatform

PlatformLifecycleBridge implementation for HarmonyPlatform.

Source§

fn freeze_surface(&mut self) -> Vec<WindowEvent>

Maps HarmonyOS onBackground into unified freeze semantics.

§Arguments
  • &Self - Mutable HarmonyOS platform.
§Returns
  • Vec<WindowEvent> - Normalized freeze events.
Source§

fn resume_surface(&mut self) -> Vec<WindowEvent>

Maps HarmonyOS onForeground into unified resume semantics.

§Arguments
  • &Self - Mutable HarmonyOS platform.
§Returns
  • Vec<WindowEvent> - Normalized resume events.
Source§

fn destroy_surface(&mut self) -> Vec<WindowEvent>

Maps HarmonyOS onDestroy into unified destroy semantics.

§Arguments
  • &Self - Mutable HarmonyOS platform.
§Returns
  • Vec<WindowEvent> - Normalized teardown events.
Source§

impl PlatformNavigation for HarmonyPlatform

PlatformNavigation implementation for HarmonyPlatform.

Source§

fn navigate_to(&mut self, route: &str) -> Result<(), PlatformError>

Navigates to route on the HarmonyOS UIAbility route stack.

§Arguments
  • &Self - Mutable HarmonyOS platform.
  • &str - Logical route path.
§Returns
  • Result<(), PlatformError> - Navigation status.
Source§

fn navigate_back(&mut self, delta: u32) -> Result<(), PlatformError>

Pops delta entries from the HarmonyOS route stack.

§Arguments
  • &Self - Mutable HarmonyOS platform.
  • u32 - Pages to pop.
§Returns
  • Result<(), PlatformError> - Navigation status.
Source§

fn current_route(&self) -> &str

Returns the active HarmonyOS logical route path.

§Arguments
  • &Self - HarmonyOS platform reference.
§Returns
  • &str - Active route path.
Source§

impl PlatformStorage for HarmonyPlatform

PlatformStorage implementation for HarmonyPlatform.

Source§

fn storage_get(&self, key: &str) -> Option<String>

Reads a key from HarmonyOS preferences storage.

§Arguments
  • &Self - HarmonyOS platform reference.
  • &str - Storage key.
§Returns
  • Option<String> - Stored value, if present.
Source§

fn storage_set(&mut self, key: &str, value: &str) -> Result<(), PlatformError>

Writes a key-value pair into HarmonyOS preferences storage.

§Arguments
  • &Self - Mutable HarmonyOS platform.
  • &str - Storage key.
  • &str - UTF-8 value.
§Returns
  • Result<(), PlatformError> - Persistence status.
Source§

fn storage_remove(&mut self, key: &str) -> Result<(), PlatformError>

Removes key from HarmonyOS preferences storage.

§Arguments
  • &Self - Mutable HarmonyOS platform.
  • &str - Storage key.
§Returns
  • Result<(), PlatformError> - Removal status.
Source§

fn storage_clear(&mut self) -> Result<(), PlatformError>

Clears all keys from HarmonyOS preferences storage.

§Arguments
  • &Self - Mutable HarmonyOS platform.
§Returns
  • Result<(), PlatformError> - Clear status.
Source§

impl WindowController for HarmonyPlatform

WindowController implementation for HarmonyPlatform.

Source§

fn apply_command(&mut self, command: WindowCommand) -> Result<(), PlatformError>

Applies a WindowCommand against the HarmonyOS XComponent window record.

§Arguments
  • &Self - Mutable HarmonyOS platform.
  • WindowCommand - Command to execute.
§Returns
  • Result<(), PlatformError> - Execution status.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.