2020-05-06 15:27:49 +02:00
|
|
|
use crate::{
|
2022-11-10 16:55:19 +00:00
|
|
|
event_loop::{EventLoop, EventLoopBuilder, EventLoopWindowTarget},
|
2020-05-06 15:27:49 +02:00
|
|
|
window::{Window, WindowBuilder},
|
|
|
|
|
};
|
2022-11-10 16:55:19 +00:00
|
|
|
|
|
|
|
|
use android_activity::{AndroidApp, ConfigurationRef, Rect};
|
2016-04-19 19:31:36 +02:00
|
|
|
|
2022-06-11 18:57:19 +02:00
|
|
|
/// Additional methods on [`EventLoop`] that are specific to Android.
|
2020-05-06 15:27:49 +02:00
|
|
|
pub trait EventLoopExtAndroid {}
|
2018-02-15 14:09:14 +01:00
|
|
|
|
2020-05-06 15:27:49 +02:00
|
|
|
impl<T> EventLoopExtAndroid for EventLoop<T> {}
|
|
|
|
|
|
2022-06-11 18:57:19 +02:00
|
|
|
/// Additional methods on [`EventLoopWindowTarget`] that are specific to Android.
|
2020-05-06 15:27:49 +02:00
|
|
|
pub trait EventLoopWindowTargetExtAndroid {}
|
2018-02-15 14:09:14 +01:00
|
|
|
|
2022-06-11 18:57:19 +02:00
|
|
|
/// Additional methods on [`Window`] that are specific to Android.
|
2019-02-05 10:30:33 -05:00
|
|
|
pub trait WindowExtAndroid {
|
2020-05-06 15:27:49 +02:00
|
|
|
fn content_rect(&self) -> Rect;
|
|
|
|
|
|
2022-11-10 16:55:19 +00:00
|
|
|
fn config(&self) -> ConfigurationRef;
|
2016-04-19 19:31:36 +02:00
|
|
|
}
|
|
|
|
|
|
2019-02-05 10:30:33 -05:00
|
|
|
impl WindowExtAndroid for Window {
|
2020-05-06 15:27:49 +02:00
|
|
|
fn content_rect(&self) -> Rect {
|
|
|
|
|
self.window.content_rect()
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-10 16:55:19 +00:00
|
|
|
fn config(&self) -> ConfigurationRef {
|
2020-05-06 15:27:49 +02:00
|
|
|
self.window.config()
|
2016-04-19 19:31:36 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-06 15:27:49 +02:00
|
|
|
impl<T> EventLoopWindowTargetExtAndroid for EventLoopWindowTarget<T> {}
|
|
|
|
|
|
2022-06-11 18:57:19 +02:00
|
|
|
/// Additional methods on [`WindowBuilder`] that are specific to Android.
|
2019-06-21 11:33:15 -04:00
|
|
|
pub trait WindowBuilderExtAndroid {}
|
2016-04-19 19:31:36 +02:00
|
|
|
|
2019-06-21 11:33:15 -04:00
|
|
|
impl WindowBuilderExtAndroid for WindowBuilder {}
|
2022-11-10 16:55:19 +00:00
|
|
|
|
|
|
|
|
pub trait EventLoopBuilderExtAndroid {
|
|
|
|
|
/// Associates the `AndroidApp` that was passed to `android_main()` with the event loop
|
|
|
|
|
///
|
|
|
|
|
/// This must be called on Android since the `AndroidApp` is not global state.
|
|
|
|
|
fn with_android_app(&mut self, app: AndroidApp) -> &mut Self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T> EventLoopBuilderExtAndroid for EventLoopBuilder<T> {
|
|
|
|
|
fn with_android_app(&mut self, app: AndroidApp) -> &mut Self {
|
|
|
|
|
self.platform_specific.android_app = Some(app);
|
|
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Re-export of the `android_activity` API
|
|
|
|
|
///
|
|
|
|
|
/// Winit re-exports the `android_activity` API for convenience so that most
|
|
|
|
|
/// applications can rely on the Winit crate to resolve the required version of
|
|
|
|
|
/// `android_activity` and avoid any chance of a conflict between Winit and the
|
|
|
|
|
/// application crate.
|
|
|
|
|
///
|
|
|
|
|
/// Unlike most libraries there can only be a single implementation
|
|
|
|
|
/// of the `android_activity` glue crate linked with an application because
|
|
|
|
|
/// it is responsible for the application's `android_main()` entry point.
|
|
|
|
|
///
|
|
|
|
|
/// Since Winit depends on a specific version of `android_activity` the simplest
|
|
|
|
|
/// way to avoid creating a conflict is for applications to avoid explicitly
|
|
|
|
|
/// depending on the `android_activity` crate, and instead consume the API that
|
|
|
|
|
/// is re-exported by Winit.
|
|
|
|
|
///
|
|
|
|
|
/// For compatibility applications should then import the `AndroidApp` type for
|
|
|
|
|
/// their `android_main(app: AndroidApp)` function like:
|
|
|
|
|
/// ```rust
|
|
|
|
|
/// #[cfg(target_os="android")]
|
|
|
|
|
/// use winit::platform::android::activity::AndroidApp;
|
|
|
|
|
/// ```
|
|
|
|
|
pub mod activity {
|
|
|
|
|
pub use android_activity::*;
|
|
|
|
|
}
|