Skip to main content

euv_core/platform/info/
impl.rs

1use super::*;
2
3/// Metadata queries for `PlatformKind`.
4impl PlatformKind {
5    /// Returns the canonical lowercase name of this platform.
6    ///
7    /// # Arguments
8    ///
9    /// - `&Self` - Platform kind.
10    ///
11    /// # Returns
12    ///
13    /// - `&'static str` - Canonical platform name string.
14    #[must_use]
15    pub const fn as_str(&self) -> &'static str {
16        match *self {
17            Self::Web => PLATFORM_NAME_WEB,
18            Self::Android => PLATFORM_NAME_ANDROID,
19            Self::Ios => PLATFORM_NAME_IOS,
20            Self::IpadOs => PLATFORM_NAME_IPADOS,
21            Self::MacOs => PLATFORM_NAME_MACOS,
22            Self::Windows => PLATFORM_NAME_WINDOWS,
23            Self::Linux => PLATFORM_NAME_LINUX,
24            Self::Headless => PLATFORM_NAME_HEADLESS,
25        }
26    }
27
28    /// Returns the default `DeviceFormFactor` associated with this platform.
29    ///
30    /// # Arguments
31    ///
32    /// - `&Self` - Platform kind.
33    ///
34    /// # Returns
35    ///
36    /// - `DeviceFormFactor` - Device form factor.
37    #[must_use]
38    pub const fn form_factor(&self) -> DeviceFormFactor {
39        match *self {
40            Self::MacOs | Self::Windows | Self::Linux => DeviceFormFactor::Desktop,
41            Self::IpadOs => DeviceFormFactor::Tablet,
42            Self::Ios | Self::Android => DeviceFormFactor::Phone,
43            Self::Web => DeviceFormFactor::Browser,
44            Self::Headless => DeviceFormFactor::Headless,
45        }
46    }
47
48    /// Returns true for mobile or tablet touch-first platforms (`Android`, `Ios`, `IpadOs`).
49    ///
50    /// # Arguments
51    ///
52    /// - `&Self` - Platform kind.
53    ///
54    /// # Returns
55    ///
56    /// - `bool` - True for mobile/tablet targets.
57    #[must_use]
58    pub const fn is_mobile_or_tablet(&self) -> bool {
59        matches!(*self, Self::Android | Self::Ios | Self::IpadOs)
60    }
61
62    /// Returns the list of all 7 production platforms supported by euv.
63    ///
64    /// # Returns
65    ///
66    /// - `[Self; 7]` - Array containing Web, Android, iOS, iPadOS, macOS, Windows, and Linux.
67    #[must_use]
68    pub const fn all_targets() -> [Self; 7] {
69        [
70            Self::Web,
71            Self::Android,
72            Self::Ios,
73            Self::IpadOs,
74            Self::MacOs,
75            Self::Windows,
76            Self::Linux,
77        ]
78    }
79}
80
81/// Capability matrix factory for `PlatformCapabilities`.
82impl PlatformCapabilities {
83    /// Returns the canonical capability matrix for `platform`.
84    ///
85    /// # Arguments
86    ///
87    /// - `PlatformKind` - Target platform.
88    ///
89    /// # Returns
90    ///
91    /// - `Self` - Normalized platform capabilities.
92    #[must_use]
93    pub fn for_platform(platform: PlatformKind) -> Self {
94        match platform {
95            PlatformKind::MacOs => Self {
96                multi_window: true,
97                hover_pointer: true,
98                touch: false,
99                stylus: false,
100                hardware_keyboard: true,
101                safe_area_insets: false,
102                hardware_gpu: true,
103                software_blit: true,
104                clipboard: true,
105                ime: true,
106                dynamic_island: false,
107                live_activities: false,
108                system_tray: true,
109                biometrics: true,
110                haptics: true,
111                protocol_handler: true,
112                accessibility_bridge: true,
113            },
114            PlatformKind::Windows => Self {
115                multi_window: true,
116                hover_pointer: true,
117                touch: false,
118                stylus: false,
119                hardware_keyboard: true,
120                safe_area_insets: false,
121                hardware_gpu: true,
122                software_blit: true,
123                clipboard: true,
124                ime: true,
125                dynamic_island: false,
126                live_activities: false,
127                system_tray: true,
128                biometrics: true,
129                haptics: false,
130                protocol_handler: true,
131                accessibility_bridge: true,
132            },
133            PlatformKind::Linux => Self {
134                multi_window: true,
135                hover_pointer: true,
136                touch: false,
137                stylus: false,
138                hardware_keyboard: true,
139                safe_area_insets: false,
140                hardware_gpu: true,
141                software_blit: true,
142                clipboard: true,
143                ime: true,
144                dynamic_island: false,
145                live_activities: false,
146                system_tray: true,
147                biometrics: false,
148                haptics: false,
149                protocol_handler: true,
150                accessibility_bridge: true,
151            },
152            PlatformKind::IpadOs => Self {
153                multi_window: true,
154                hover_pointer: true,
155                touch: true,
156                stylus: true,
157                hardware_keyboard: true,
158                safe_area_insets: true,
159                hardware_gpu: true,
160                software_blit: true,
161                clipboard: true,
162                ime: true,
163                dynamic_island: false,
164                live_activities: true,
165                system_tray: false,
166                biometrics: true,
167                haptics: true,
168                protocol_handler: true,
169                accessibility_bridge: true,
170            },
171            PlatformKind::Ios => Self {
172                multi_window: false,
173                hover_pointer: false,
174                touch: true,
175                stylus: true,
176                hardware_keyboard: false,
177                safe_area_insets: true,
178                hardware_gpu: true,
179                software_blit: true,
180                clipboard: true,
181                ime: true,
182                dynamic_island: true,
183                live_activities: true,
184                system_tray: false,
185                biometrics: true,
186                haptics: true,
187                protocol_handler: true,
188                accessibility_bridge: true,
189            },
190            PlatformKind::Android => Self {
191                multi_window: false,
192                hover_pointer: false,
193                touch: true,
194                stylus: true,
195                hardware_keyboard: false,
196                safe_area_insets: true,
197                hardware_gpu: true,
198                software_blit: true,
199                clipboard: true,
200                ime: true,
201                dynamic_island: false,
202                live_activities: true,
203                system_tray: false,
204                biometrics: true,
205                haptics: true,
206                protocol_handler: true,
207                accessibility_bridge: true,
208            },
209            PlatformKind::Web => Self {
210                multi_window: false,
211                hover_pointer: true,
212                touch: true,
213                stylus: true,
214                hardware_keyboard: true,
215                safe_area_insets: true,
216                hardware_gpu: true,
217                software_blit: true,
218                clipboard: true,
219                ime: true,
220                dynamic_island: false,
221                live_activities: false,
222                system_tray: false,
223                biometrics: true,
224                haptics: true,
225                protocol_handler: true,
226                accessibility_bridge: true,
227            },
228            PlatformKind::Headless => Self {
229                multi_window: true,
230                hover_pointer: true,
231                touch: true,
232                stylus: false,
233                hardware_keyboard: true,
234                safe_area_insets: true,
235                hardware_gpu: false,
236                software_blit: true,
237                clipboard: true,
238                ime: true,
239                dynamic_island: false,
240                live_activities: false,
241                system_tray: true,
242                biometrics: false,
243                haptics: false,
244                protocol_handler: true,
245                accessibility_bridge: true,
246            },
247        }
248    }
249}