lgui_widgets/theme/
tokens.rs1use std::sync::Arc;
2
3use crate::core::Color;
4
5#[derive(Clone, Copy, Debug, PartialEq, Eq)]
6pub struct ColorTokens {
7 pub surface: Color,
8 pub surface_raised: Color,
9 pub surface_interactive: Color,
10 pub surface_hover: Color,
11 pub border: Color,
12 pub border_subtle: Color,
13 pub text: Color,
14 pub text_secondary: Color,
15 pub text_muted: Color,
16 pub accent: Color,
17 pub accent_contrast: Color,
18}
19
20impl Default for ColorTokens {
21 fn default() -> Self {
22 Self {
23 surface: Color(0x15181D),
24 surface_raised: Color(0x242931),
25 surface_interactive: Color(0x2B313A),
26 surface_hover: Color(0x353D48),
27 border: Color(0x53606F),
28 border_subtle: Color(0x3C4653),
29 text: Color(0xF3F5F7),
30 text_secondary: Color(0xC4CBD4),
31 text_muted: Color(0x8F9AA8),
32 accent: Color(0x3CB8C5),
33 accent_contrast: Color(0x071416),
34 }
35 }
36}
37
38#[derive(Clone, Copy, Debug, PartialEq, Eq)]
39pub struct SpacingTokens {
40 pub xs: i32,
41 pub sm: i32,
42 pub md: i32,
43 pub lg: i32,
44 pub xl: i32,
45}
46
47impl Default for SpacingTokens {
48 fn default() -> Self {
49 Self {
50 xs: 4,
51 sm: 8,
52 md: 12,
53 lg: 16,
54 xl: 24,
55 }
56 }
57}
58
59#[derive(Clone, Copy, Debug, PartialEq, Eq)]
60pub struct TypographyTokens {
61 pub body_size: i32,
62 pub label_size: i32,
63 pub body_weight: u16,
64 pub strong_weight: u16,
65}
66
67impl Default for TypographyTokens {
68 fn default() -> Self {
69 Self {
70 body_size: -14,
71 label_size: -12,
72 body_weight: 400,
73 strong_weight: 700,
74 }
75 }
76}
77
78#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
79pub struct ThemeTokens {
80 pub colors: ColorTokens,
81 pub spacing: SpacingTokens,
82 pub typography: TypographyTokens,
83}
84
85#[derive(Clone)]
86pub struct ThemeContext {
87 tokens: Arc<ThemeTokens>,
88}
89
90impl ThemeContext {
91 pub fn new(tokens: ThemeTokens) -> Self {
92 Self {
93 tokens: Arc::new(tokens),
94 }
95 }
96
97 pub fn tokens(&self) -> &ThemeTokens {
98 &self.tokens
99 }
100}
101
102impl Default for ThemeContext {
103 fn default() -> Self {
104 Self::new(ThemeTokens::default())
105 }
106}
107
108impl PartialEq for ThemeContext {
109 fn eq(&self, other: &Self) -> bool {
110 self.tokens == other.tokens
111 }
112}