Skip to main content

densa_ui/
theme.rs

1use densa_core::Color;
2
3/// Colors and sizes widgets share, so an application restyles every widget in one place.
4/// Sizes are in logical pixels.
5#[derive(Debug, Clone, PartialEq)]
6#[non_exhaustive]
7pub struct Theme {
8    /// Behind everything: the window.
9    pub background: Color,
10    /// Panels and toolbars.
11    pub surface: Color,
12    /// Controls: buttons, inputs.
13    pub raised: Color,
14    /// A control under the pointer.
15    pub hover: Color,
16    /// A control being pressed.
17    pub pressed: Color,
18    /// Lines between and around things.
19    pub border: Color,
20    /// Text.
21    pub text: Color,
22    /// Secondary text: hints, labels of lesser weight.
23    pub text_dim: Color,
24    /// The accent: default buttons, selected items.
25    pub accent: Color,
26    /// Text on the accent color.
27    pub on_accent: Color,
28    /// Selected text's background.
29    pub selection: Color,
30    /// The ring around the focused control.
31    pub focus: Color,
32    /// Body text size.
33    pub font_size: f32,
34    /// The base unit of spacing.
35    pub spacing: f32,
36}
37
38impl Theme {
39    /// Light text on dark surfaces.
40    pub fn dark() -> Self {
41        Self {
42            background: Color::srgb(0x0B1220),
43            surface: Color::srgb(0x111A2B),
44            raised: Color::srgb(0x1A2540),
45            hover: Color::srgb(0x22304A),
46            pressed: Color::srgb(0x2A3A5C),
47            border: Color::srgb(0x22304A),
48            text: Color::srgb(0xE6EDF7),
49            text_dim: Color::srgb(0x9AA8BE),
50            accent: Color::srgb(0x2F5BEA),
51            on_accent: Color::WHITE,
52            selection: Color::srgb(0x2F5BEA).with_alpha(0.45),
53            focus: Color::srgb(0x6B9BFF),
54            font_size: 13.0,
55            spacing: 4.0,
56        }
57    }
58
59    /// Dark text on light surfaces.
60    pub fn light() -> Self {
61        Self {
62            background: Color::srgb(0xF4F6FA),
63            surface: Color::srgb(0xFFFFFF),
64            raised: Color::srgb(0xFFFFFF),
65            hover: Color::srgb(0xEEF2F8),
66            pressed: Color::srgb(0xE2E8F2),
67            border: Color::srgb(0xD5DCE6),
68            text: Color::srgb(0x0B1220),
69            text_dim: Color::srgb(0x5B6B82),
70            accent: Color::srgb(0x2F5BEA),
71            on_accent: Color::WHITE,
72            selection: Color::srgb(0x2F5BEA).with_alpha(0.25),
73            focus: Color::srgb(0x2F5BEA),
74            font_size: 13.0,
75            spacing: 4.0,
76        }
77    }
78}
79
80impl Default for Theme {
81    /// [`Theme::dark`]: data-dense screens are mostly read in dark rooms.
82    fn default() -> Self {
83        Self::dark()
84    }
85}