#[derive(Copy, Clone, Debug, Default, PartialEq, PartialOrd)]
pub struct Pixels(pub f32);
impl Pixels {
pub const ZERO: Self = Self(0.0);
}
impl From<f32> for Pixels {
fn from(v: f32) -> Self {
Self(v)
}
}
impl From<Pixels> for f32 {
fn from(p: Pixels) -> Self {
p.0
}
}
impl std::ops::Mul<f32> for Pixels {
type Output = Self;
fn mul(self, rhs: f32) -> Self {
Self(self.0 * rhs)
}
}
impl std::ops::Div<f32> for Pixels {
type Output = Self;
fn div(self, rhs: f32) -> Self {
Self(self.0 / rhs)
}
}
impl std::ops::Add for Pixels {
type Output = Self;
fn add(self, rhs: Self) -> Self {
Self(self.0 + rhs.0)
}
}
impl std::ops::Sub for Pixels {
type Output = Self;
fn sub(self, rhs: Self) -> Self {
Self(self.0 - rhs.0)
}
}
impl std::ops::Neg for Pixels {
type Output = Self;
fn neg(self) -> Self {
Self(-self.0)
}
}
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct DevicePixels(pub i32);
impl From<i32> for DevicePixels {
fn from(v: i32) -> Self {
Self(v)
}
}
impl From<DevicePixels> for i32 {
fn from(dp: DevicePixels) -> Self {
dp.0
}
}
#[derive(Copy, Clone, Debug, Default, PartialEq)]
pub struct Size<T> {
pub width: T,
pub height: T,
}
#[derive(Copy, Clone, Debug, Default, PartialEq)]
pub struct Point<T> {
pub x: T,
pub y: T,
}
#[derive(Copy, Clone, Debug, Default, PartialEq)]
pub struct Bounds<T> {
pub origin: Point<T>,
pub size: Size<T>,
}
pub fn point<T>(x: T, y: T) -> Point<T> {
Point { x, y }
}
pub fn size<T>(width: T, height: T) -> Size<T> {
Size { width, height }
}
pub mod atlas;
pub mod dispatcher;
pub mod display;
pub mod jni_entry;
pub mod keyboard;
pub mod platform;
pub mod renderer;
pub mod text;
pub mod window;
pub use dispatcher::AndroidDispatcher;
pub use display::AndroidDisplay;
pub use keyboard::*;
pub use platform::{AndroidPlatform, SharedPlatform};
pub use renderer::WgpuRenderer;
pub use text::AndroidTextSystem;
pub use window::{AndroidPlatformWindow, AndroidWindow, SafeAreaInsets};
use std::rc::Rc;
pub fn current_platform(headless: bool) -> Rc<dyn gpui::Platform> {
Rc::new(AndroidPlatform::new(headless))
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum AndroidBackend {
Vulkan,
Gles,
}
impl Default for AndroidBackend {
fn default() -> Self {
Self::Vulkan
}
}
impl std::fmt::Display for AndroidBackend {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Vulkan => write!(f, "Vulkan"),
Self::Gles => write!(f, "OpenGL ES"),
}
}
}
#[derive(Clone, Debug)]
pub struct AndroidKeyEvent {
pub key_code: i32,
pub action: i32,
pub meta_state: i32,
pub unicode_char: u32,
}
#[derive(Clone, Debug)]
pub struct TouchPoint {
pub id: i32,
pub x: f32,
pub y: f32,
pub action: u32,
}
pub fn init_logger() {
use std::sync::OnceLock;
static INIT: OnceLock<()> = OnceLock::new();
INIT.get_or_init(|| {
android_logger::init_once(
android_logger::Config::default()
.with_max_level(log::LevelFilter::Debug)
.with_tag("gpui-android"),
);
log::info!("gpui-android logger initialised");
});
}