Skip to main content

lumen_runtime/
skins.rs

1//! Embedded user-agent stylesheets.
2//!
3//! [`DEFAULT`] / [`MACOS`] / [`WINDOWS`] / [`LINUX`] are opt-in, activated
4//! via `<root skin="<name>">` or `lumen.toml` `[skin] name = "..."`; when
5//! neither opts in, none of them is applied.
6//!
7//! [`UA`] is different: it is not selected by name and applies to every
8//! app unconditionally, beneath whichever named skin (if any) and
9//! beneath the app's own CSS - see its own doc comment.
10
11/// The always-on user-agent baseline: per-tag sizing floors (button /
12/// input / toggle / switch / slider / progress minimums, root / title-bar
13/// fill) applied beneath any opt-in skin and beneath app CSS. Folded into
14/// the combined cascade by `run::loading::load_ir` for every app, skinned
15/// or not - the framework's equivalent of a browser's built-in
16/// stylesheet.
17pub const UA: &str = include_str!("skins/ua.css");
18
19/// Default (neutral, dark-first) skin CSS for buttons, inputs,
20/// toggles, sliders, and tiles.
21pub const DEFAULT: &str = include_str!("skins/default.css");
22/// macOS-flavoured skin (macOS 14/15-era Aqua): 20px buttons, no
23/// hover feedback, pill switch, soft accent focus halo.
24pub const MACOS: &str = include_str!("skins/macos.css");
25/// Windows 11 / WinUI 3 (Fluent 2) skin: 4px radii, accent primary
26/// buttons, elevation bottom edge, keyboard-only focus ring.
27pub const WINDOWS: &str = include_str!("skins/windows.css");
28/// Linux (libadwaita-leaning neutral) skin: flat fg-alpha fills,
29/// bold accent, 12px popovers, 46x26 pill switches.
30pub const LINUX: &str = include_str!("skins/linux.css");
31
32/// The list of recognised skin names (excluding `auto`).
33pub const NAMES: [&str; 4] = ["default", "macos", "windows", "linux"];
34
35/// Returns the embedded CSS source for `name`, or `None` for an
36/// unknown skin. `"auto"` resolves to the current OS per
37/// [`resolve_auto`], so forcing any concrete name on any OS works
38/// (cross-platform preview).
39pub fn lookup(name: &str) -> Option<&'static str> {
40    match name {
41        "default" => Some(DEFAULT),
42        "macos" => Some(MACOS),
43        "windows" => Some(WINDOWS),
44        "linux" => Some(LINUX),
45        "auto" => lookup(resolve_auto()),
46        _ => None,
47    }
48}
49
50/// Maps `std::env::consts::OS` onto a concrete skin name:
51/// `"macos"` / `"windows"` / everything else -> `"linux"` (the
52/// adwaita-leaning neutral degrades gracefully across desktops).
53pub fn resolve_auto() -> &'static str {
54    match std::env::consts::OS {
55        "macos" => "macos",
56        "windows" => "windows",
57        _ => "linux",
58    }
59}