1#[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 pub const fn rgba(r: f32, g: f32, b: f32, a: f32) -> Self {
12 Self { r, g, b, a }
13 }
14
15 pub const fn rgb(r: f32, g: f32, b: f32) -> Self {
16 Self { r, g, b, a: 1.0 }
17 }
18
19 pub fn to_skia(&self) -> tiny_skia::Color {
20 tiny_skia::Color::from_rgba(self.r, self.g, self.b, self.a)
21 .unwrap_or(tiny_skia::Color::BLACK)
22 }
23
24 pub fn to_premultiplied(&self) -> tiny_skia::PremultipliedColorU8 {
25 self.to_skia().premultiply().to_color_u8()
26 }
27}
28
29#[derive(Clone, Debug)]
31pub struct Theme {
32 pub background: Color,
33 pub surface: Color,
34 pub primary: Color,
35 pub accent: Color,
36 pub text: Color,
37 pub text_dim: Color,
38 pub knob_track: Color,
39 pub knob_fill: Color,
40 pub knob_pointer: Color,
41 pub header_bg: Color,
42 pub header_text: Color,
43}
44
45impl Theme {
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}