1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use accesskit::NodeId as AccessibilityId;
use torin::prelude::Size2D;
use winit::window::Window;

/// State consumed by components and updated by the platform.
#[derive(Clone, Debug)]
pub struct NativePlatformState {
    pub focused_id: AccessibilityId,
    pub preferred_theme: PreferredTheme,
    pub navigation_mode: NavigationMode,
    pub information: PlatformInformation,
    pub scale_factor: f64,
}

#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
pub enum PreferredTheme {
    #[default]
    /// Use the light variant.
    Light,

    /// Use the dark variant.
    Dark,
}

impl From<winit::window::Theme> for PreferredTheme {
    fn from(value: winit::window::Theme) -> Self {
        match value {
            winit::window::Theme::Light => Self::Light,
            winit::window::Theme::Dark => Self::Dark,
        }
    }
}

#[derive(Clone, Copy, PartialEq, Eq, Default, Debug)]
pub enum NavigationMode {
    #[default]
    NotKeyboard,

    Keyboard,
}

/// Information about the platform.
#[derive(Clone, PartialEq, Debug, Copy)]
pub struct PlatformInformation {
    pub viewport_size: Size2D,
    pub is_minimized: bool,
    pub is_maximized: bool,
    pub is_fullscreen: bool,
}

impl PlatformInformation {
    pub fn from_winit(winit: &Window) -> Self {
        let window_size = winit.inner_size();
        Self {
            viewport_size: Size2D::new(window_size.width as f32, window_size.height as f32),
            is_minimized: winit.is_minimized().unwrap_or_default(),
            is_maximized: winit.is_maximized(),
            is_fullscreen: winit.fullscreen().is_some(),
        }
    }

    pub fn new(
        viewport_size: Size2D,
        is_minimized: bool,
        is_maximized: bool,
        is_fullscreen: bool,
    ) -> Self {
        Self {
            viewport_size,
            is_minimized,
            is_maximized,
            is_fullscreen,
        }
    }
}