Skip to main content

cranpose_platform_web/
lib.rs

1use cranpose_foundation::{PointerEvent, PointerEventKind};
2use cranpose_ui_graphics::Point;
3
4pub struct WebPlatform {
5    scale_factor: f64,
6}
7
8impl WebPlatform {
9    pub fn new(scale_factor: f64) -> Self {
10        Self { scale_factor }
11    }
12
13    pub fn set_scale_factor(&mut self, factor: f64) {
14        self.scale_factor = factor;
15    }
16
17    pub fn pointer_position(&self, x: f64, y: f64) -> Point {
18        // offset_x/offset_y are already in CSS pixels (logical coordinates)
19        // so we don't need to divide by scale_factor
20        Point {
21            x: x as f32,
22            y: y as f32,
23        }
24    }
25
26    pub fn pointer_event(&self, kind: PointerEventKind, x: f64, y: f64) -> PointerEvent {
27        let logical = self.pointer_position(x, y);
28        PointerEvent::new(kind, logical, logical)
29    }
30}
31
32impl Default for WebPlatform {
33    fn default() -> Self {
34        Self::new(1.0)
35    }
36}