use self::ability::{Configuration, OpenHarmonyApp, Rect};
use crate::application::ApplicationHandler;
use crate::event_loop::{self, ActiveEventLoop, EventLoop, EventLoopBuilder};
use crate::window::{Window, WindowAttributes};
pub trait EventLoopExtOpenHarmony {
type UserEvent: 'static;
fn spawn_app<A: ApplicationHandler<Self::UserEvent> + 'static>(self, app: A);
fn openharmony_app(&self) -> &OpenHarmonyApp;
}
impl<T> EventLoopExtOpenHarmony for EventLoop<T> {
type UserEvent = T;
fn spawn_app<A: ApplicationHandler<Self::UserEvent> + 'static>(self, app: A) {
let app = Box::leak(Box::new(app));
let event_looper = Box::leak(Box::new(self));
event_looper
.event_loop
.run(|event, event_loop| event_loop::dispatch_event_for_app(app, event_loop, event));
}
fn openharmony_app(&self) -> &OpenHarmonyApp {
&self.event_loop.openharmony_app
}
}
pub trait ActiveEventLoopExtOpenHarmony {
fn openharmony_app(&self) -> &OpenHarmonyApp;
}
pub trait WindowExtOpenHarmony {
fn content_rect(&self) -> Rect;
fn config(&self) -> Configuration;
}
impl WindowExtOpenHarmony for Window {
fn content_rect(&self) -> Rect {
self.window.content_rect()
}
fn config(&self) -> Configuration {
self.window.config()
}
}
impl ActiveEventLoopExtOpenHarmony for ActiveEventLoop {
fn openharmony_app(&self) -> &OpenHarmonyApp {
&self.p.app
}
}
pub trait WindowAttributesExtOpenHarmony {}
impl WindowAttributesExtOpenHarmony for WindowAttributes {}
pub trait EventLoopBuilderExtOpenHarmony {
fn with_openharmony_app(&mut self, app: OpenHarmonyApp) -> &mut Self;
}
impl<T> EventLoopBuilderExtOpenHarmony for EventLoopBuilder<T> {
fn with_openharmony_app(&mut self, app: OpenHarmonyApp) -> &mut Self {
self.platform_specific.openharmony_app = Some(app);
self
}
}
pub mod ability {
#[doc(no_inline)]
#[cfg(ohos_platform)]
pub use openharmony_ability::*;
#[doc(no_inline)]
#[cfg(ohos_platform)]
pub use openharmony_ability_derive::*;
#[cfg(not(ohos_platform))]
#[doc(hidden)]
pub struct Rect;
#[cfg(not(ohos_platform))]
#[doc(hidden)]
pub struct ConfigurationRef;
#[cfg(not(ohos_platform))]
#[doc(hidden)]
pub struct OpenHarmonyApp;
}