1use std::rc::Rc;
2
3pub use mundy::{
4 AccentColor,
5 Srgba,
6};
7use torin::prelude::Size2D;
8
9use crate::{
10 accessibility::id::AccessibilityId,
11 prelude::{
12 State,
13 consume_root_context,
14 },
15 user_event::UserEvent,
16};
17
18#[derive(Clone, Copy, PartialEq, Eq, Default, Debug, Hash)]
19pub enum NavigationMode {
20 #[default]
21 NotKeyboard,
22 Keyboard,
23}
24
25#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
26pub enum PreferredTheme {
27 #[default]
28 Light,
29 Dark,
30}
31
32#[derive(Clone)]
37pub struct Platform {
38 pub focused_accessibility_id: State<AccessibilityId>,
40 pub focused_accessibility_node: State<accesskit::Node>,
42 pub root_size: State<Size2D>,
44 pub scale_factor: State<f64>,
46 pub custom_scale_factor: State<f64>,
48 pub navigation_mode: State<NavigationMode>,
50 pub preferred_theme: State<PreferredTheme>,
52 pub is_app_focused: State<bool>,
54 pub accent_color: State<AccentColor>,
56 pub sender: Rc<dyn Fn(UserEvent)>,
58}
59
60impl Platform {
61 pub fn get() -> Self {
63 consume_root_context()
64 }
65
66 pub fn send(&self, event: UserEvent) {
68 (self.sender)(event)
69 }
70
71 pub fn set_custom_scale_factor(&self, custom_scale_factor: f64) {
74 self.send(UserEvent::SetCustomScaleFactor(custom_scale_factor));
75 }
76}