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
use std::rc::Rc;
use torin::prelude::Size2D;
use crate::{
accessibility::id::AccessibilityId,
prelude::{
State,
consume_root_context,
},
};
#[derive(Clone, Copy, PartialEq, Eq, Default, Debug, Hash)]
pub enum NavigationMode {
#[default]
NotKeyboard,
Keyboard,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
pub enum PreferredTheme {
#[default]
Light,
Dark,
}
use crate::user_event::UserEvent;
/// Access point to different Freya-managed states such as the focused node,
/// root window size, navigation mode, and theme preference.
///
/// Retrieve it from any component with [`Platform::get`].
#[derive(Clone)]
pub struct Platform {
/// The [`AccessibilityId`] of the currently focused node.
pub focused_accessibility_id: State<AccessibilityId>,
/// The accessibility node data of the currently focused node.
pub focused_accessibility_node: State<accesskit::Node>,
/// The size of the root window.
pub root_size: State<Size2D>,
/// The current [`NavigationMode`].
pub navigation_mode: State<NavigationMode>,
/// The OS-level [`PreferredTheme`].
pub preferred_theme: State<PreferredTheme>,
/// Internal sender used to dispatch [`UserEvent`]s.
pub sender: Rc<dyn Fn(UserEvent)>,
}
impl Platform {
/// Retrieve the [`Platform`] from the root context.
pub fn get() -> Self {
consume_root_context()
}
/// Send a [`UserEvent`] through the platform.
pub fn send(&self, event: UserEvent) {
(self.sender)(event)
}
}