Skip to main content

truce_gui_types/
theme.rs

1/// Color as RGBA (0.0–1.0).
2#[derive(Clone, Copy, Debug)]
3pub struct Color {
4    pub r: f32,
5    pub g: f32,
6    pub b: f32,
7    pub a: f32,
8}
9
10impl Color {
11    #[must_use]
12    pub const fn rgba(r: f32, g: f32, b: f32, a: f32) -> Self {
13        Self { r, g, b, a }
14    }
15
16    #[must_use]
17    pub const fn rgb(r: f32, g: f32, b: f32) -> Self {
18        Self { r, g, b, a: 1.0 }
19    }
20}
21
22// `Color::to_skia` / `Color::to_premultiplied` (tiny-skia
23// conversions) live in `truce-gui` - they're rasterizer-specific
24// helpers, and putting them here would pull tiny-skia into the
25// light crate. Backends that need them call the conversion at the
26// raster boundary instead.
27
28/// Visual theme for the built-in GUI.
29#[derive(Clone, Debug)]
30pub struct Theme {
31    pub background: Color,
32    pub surface: Color,
33    pub primary: Color,
34    pub accent: Color,
35    pub text: Color,
36    pub text_dim: Color,
37    pub knob_track: Color,
38    pub knob_fill: Color,
39    pub knob_pointer: Color,
40    pub header_bg: Color,
41    pub header_text: Color,
42}
43
44impl Theme {
45    #[must_use]
46    pub fn dark() -> Self {
47        Self {
48            background: Color::rgb(0.12, 0.12, 0.14),
49            surface: Color::rgb(0.18, 0.18, 0.22),
50            primary: Color::rgb(0.30, 0.60, 0.95),
51            accent: Color::rgb(0.45, 0.45, 0.45),
52            text: Color::rgb(0.90, 0.90, 0.92),
53            text_dim: Color::rgb(0.55, 0.55, 0.60),
54            knob_track: Color::rgb(0.25, 0.25, 0.30),
55            knob_fill: Color::rgb(0.30, 0.60, 0.95),
56            knob_pointer: Color::rgb(0.95, 0.95, 0.97),
57            header_bg: Color::rgb(0.08, 0.08, 0.10),
58            header_text: Color::rgb(0.75, 0.75, 0.80),
59        }
60    }
61}