Skip to main content

uzor_core/platform/
mod.rs

1//! Platform abstraction layer
2//!
3//! Defines traits that platform backends (desktop, web, mobile) must implement.
4
5pub mod types;
6pub mod backends;
7
8use crate::input::events::KeyCode;
9use crate::input::state::{ModifierKeys, MouseButton};
10
11// Re-export common types
12pub use types::*;
13pub use backends::PlatformBackend;
14
15// =============================================================================
16// Window Configuration
17// =============================================================================
18
19#[derive(Clone, Debug)]
20pub struct WindowConfig {
21    pub title: String,
22    pub width: u32,
23    pub height: u32,
24    pub resizable: bool,
25    pub decorations: bool,
26    pub transparent: bool,
27    pub visible: bool,
28}
29
30impl Default for WindowConfig {
31    fn default() -> Self {
32        Self {
33            title: "uzor".to_string(),
34            width: 800,
35            height: 600,
36            resizable: true,
37            decorations: true,
38            transparent: false,
39            visible: true,
40        }
41    }
42}
43
44impl WindowConfig {
45    pub fn new(title: impl Into<String>) -> Self {
46        Self {
47            title: title.into(),
48            ..Default::default()
49        }
50    }
51}
52
53// =============================================================================
54// Platform Events
55// =============================================================================
56
57#[derive(Clone, Debug)]
58pub enum PlatformEvent {
59    WindowCreated,
60    WindowResized { width: u32, height: u32 },
61    WindowMoved { x: i32, y: i32 },
62    WindowFocused(bool),
63    WindowCloseRequested,
64    WindowDestroyed,
65    RedrawRequested,
66    PointerEntered,
67    PointerLeft,
68    PointerMoved { x: f64, y: f64 },
69    PointerDown { x: f64, y: f64, button: MouseButton },
70    PointerUp { x: f64, y: f64, button: MouseButton },
71    TouchStart { id: u64, x: f64, y: f64 },
72    TouchMove { id: u64, x: f64, y: f64 },
73    TouchEnd { id: u64, x: f64, y: f64 },
74    TouchCancel { id: u64 },
75    Scroll { dx: f64, dy: f64 },
76    KeyDown { key: KeyCode, modifiers: ModifierKeys },
77    KeyUp { key: KeyCode, modifiers: ModifierKeys },
78    TextInput { text: String },
79    ModifiersChanged { modifiers: ModifierKeys },
80    ClipboardPaste { text: String },
81    FileDropped { path: std::path::PathBuf },
82    FileHovered { path: std::path::PathBuf },
83    FileCancelled,
84    Ime(ImeEvent),
85    ThemeChanged { dark_mode: bool },
86    ScaleFactorChanged { scale: f64 },
87}
88
89#[derive(Clone, Debug, PartialEq)]
90pub enum ImeEvent {
91    Enabled,
92    Preedit(String, Option<(usize, usize)>),
93    Commit(String),
94    Disabled,
95}
96
97#[derive(Clone, Copy, Debug, PartialEq, Eq)]
98pub enum SystemTheme {
99    Light,
100    Dark,
101}