i_slint_core/
lib.rs

1// Copyright © SixtyFPS GmbH <info@slint.dev>
2// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
3
4// cSpell: ignore sharedvector textlayout
5
6#![doc = include_str!("README.md")]
7#![doc(html_logo_url = "https://slint.dev/logo/slint-logo-square-light.svg")]
8#![deny(unsafe_code)]
9#![no_std]
10
11extern crate alloc;
12#[cfg(feature = "std")]
13extern crate std;
14
15#[cfg(all(not(feature = "std"), feature = "unsafe-single-threaded"))]
16pub(crate) mod unsafe_single_threaded;
17#[cfg(all(not(feature = "std"), not(feature = "unsafe-single-threaded")))]
18compile_error!(
19    "At least one of the following feature need to be enabled: `std` or `unsafe-single-threaded`"
20);
21use crate::items::OperatingSystemType;
22#[cfg(all(not(feature = "std"), feature = "unsafe-single-threaded"))]
23use crate::unsafe_single_threaded::thread_local;
24#[cfg(feature = "std")]
25use std::thread_local;
26
27pub mod accessibility;
28pub mod animations;
29pub mod api;
30pub mod callbacks;
31pub mod component_factory;
32pub mod context;
33pub mod date_time;
34pub mod future;
35pub mod graphics;
36pub mod input;
37pub mod item_focus;
38pub mod item_rendering;
39pub mod item_tree;
40pub mod items;
41pub mod layout;
42pub mod lengths;
43pub mod menus;
44pub mod model;
45pub mod platform;
46pub mod properties;
47pub mod renderer;
48#[cfg(feature = "rtti")]
49pub mod rtti;
50pub mod sharedvector;
51pub mod slice;
52#[cfg(feature = "software-renderer")]
53pub mod software_renderer;
54pub mod string;
55pub mod tests;
56pub mod textlayout;
57pub mod timers;
58pub mod translations;
59pub mod window;
60
61#[doc(inline)]
62pub use string::SharedString;
63
64#[doc(inline)]
65pub use sharedvector::SharedVector;
66
67#[doc(inline)]
68pub use graphics::{ImageInner, StaticTextures};
69
70#[doc(inline)]
71pub use properties::Property;
72
73#[doc(inline)]
74pub use callbacks::Callback;
75
76#[doc(inline)]
77pub use graphics::Color;
78
79#[doc(inline)]
80pub use graphics::Brush;
81
82#[doc(inline)]
83pub use graphics::RgbaColor;
84
85#[cfg(feature = "std")]
86#[doc(inline)]
87pub use graphics::PathData;
88
89#[doc(inline)]
90pub use graphics::BorderRadius;
91
92pub use context::{with_global_context, SlintContext};
93
94#[cfg(not(slint_int_coord))]
95pub type Coord = f32;
96#[cfg(slint_int_coord)]
97pub type Coord = i32;
98
99/// This type is not exported from the public API crate, so function having this
100/// parameter cannot be called from the public API without naming it
101pub struct InternalToken;
102
103#[cfg(not(target_family = "wasm"))]
104pub fn detect_operating_system() -> OperatingSystemType {
105    if cfg!(target_os = "android") {
106        OperatingSystemType::Android
107    } else if cfg!(target_os = "ios") {
108        OperatingSystemType::Ios
109    } else if cfg!(target_os = "macos") {
110        OperatingSystemType::Macos
111    } else if cfg!(target_os = "windows") {
112        OperatingSystemType::Windows
113    } else if cfg!(target_os = "linux") {
114        OperatingSystemType::Linux
115    } else {
116        OperatingSystemType::Other
117    }
118}
119
120#[cfg(target_family = "wasm")]
121pub fn detect_operating_system() -> OperatingSystemType {
122    let mut user_agent =
123        web_sys::window().and_then(|w| w.navigator().user_agent().ok()).unwrap_or_default();
124    user_agent.make_ascii_lowercase();
125    let mut platform =
126        web_sys::window().and_then(|w| w.navigator().platform().ok()).unwrap_or_default();
127    platform.make_ascii_lowercase();
128
129    if user_agent.contains("ipad") || user_agent.contains("iphone") {
130        OperatingSystemType::Ios
131    } else if user_agent.contains("android") {
132        OperatingSystemType::Android
133    } else if platform.starts_with("mac") {
134        OperatingSystemType::Macos
135    } else if platform.starts_with("win") {
136        OperatingSystemType::Windows
137    } else if platform.starts_with("linux") {
138        OperatingSystemType::Linux
139    } else {
140        OperatingSystemType::Other
141    }
142}