use cranpose_ui_graphics::Point;
#[derive(Debug, Clone)]
pub struct AndroidPlatform {
scale_factor: f64,
input_surface_offset_x_px: f64,
input_surface_offset_y_px: f64,
}
impl Default for AndroidPlatform {
fn default() -> Self {
Self {
scale_factor: 1.0,
input_surface_offset_x_px: 0.0,
input_surface_offset_y_px: 0.0,
}
}
}
impl AndroidPlatform {
pub fn new() -> Self {
Self::default()
}
pub fn set_scale_factor(&mut self, scale_factor: f64) {
self.scale_factor = scale_factor;
}
pub fn set_input_surface_offset_px(&mut self, x_px: f64, y_px: f64) {
self.input_surface_offset_x_px = x_px;
self.input_surface_offset_y_px = y_px;
}
pub fn input_surface_offset_px(&self) -> (f64, f64) {
(
self.input_surface_offset_x_px,
self.input_surface_offset_y_px,
)
}
pub fn pointer_position(&self, physical_x: f64, physical_y: f64) -> Point {
let scale = self.scale_factor;
Point {
x: ((physical_x + self.input_surface_offset_x_px) / scale) as f32,
y: ((physical_y + self.input_surface_offset_y_px) / scale) as f32,
}
}
pub fn scale_factor(&self) -> f32 {
self.scale_factor as f32
}
}
#[cfg(test)]
#[path = "tests/android_tests.rs"]
mod tests;