egui_charts/tokens/semantic.rs
1//! Semantic color tokens -- domain-organized color definitions.
2//!
3//! These structs hold the color values of [`DESIGN_TOKENS`](super::DESIGN_TOKENS).
4//! They supply component defaults and fallbacks. Theme presets define their
5//! own palettes in the [`theme`](crate::theme) module.
6//!
7//! For most use cases, prefer reading colors from the applied theme
8//! ([`ThemeExt::active_theme`](crate::theme::ThemeExt::active_theme)) rather than
9//! from these structs directly.
10
11use egui::Color32;
12
13/// Complete set of semantic color tokens, organized by domain.
14///
15/// This is the top-level color token structure within [`DesignTokens`](super::DesignTokens).
16/// Each field groups defaults and fallbacks for a specific domain, including chart
17/// rendering and drawing tools. UI chrome reads the applied theme.
18#[derive(Clone, Debug)]
19pub struct SemanticTokens {
20 /// Neutral engine fallback; UI chrome reads the applied theme.
21 pub ui: UiSemanticTokens,
22 /// Chart area colors (background, grid, candles, crosshair, volume).
23 pub chart: ChartSemanticTokens,
24 /// Brand accent colors.
25 pub brand: BrandSemanticTokens,
26 /// Status defaults.
27 pub status: StatusSemanticTokens,
28 /// Footprint defaults.
29 pub footprint: FootprintSemanticTokens,
30 /// Indicators defaults.
31 pub indicators: IndicatorSemanticTokens,
32 /// Drawings defaults.
33 pub drawings: DrawingSemanticTokens,
34 /// Additional component color defaults.
35 pub extended: ExtendedSemanticTokens,
36 /// TPO (Market Profile) chart colors
37 pub tpo: TpoSemanticTokens,
38}
39
40/// Neutral fallback still used by volume bubbles. UI chrome reads the applied theme.
41#[derive(Clone, Debug)]
42pub struct UiSemanticTokens {
43 /// Neutral default retained for engine volume bubbles.
44 pub text_muted_dark: Color32,
45 /// Tooltip outline fallback when no theme has been applied.
46 pub border_dark: Color32,
47}
48
49/// Chart area color tokens for default and fallback rendering.
50///
51/// Defines colors for the chart background, grid lines, axis text, crosshair,
52/// candle/bar colors (bullish/bearish), volume bar alpha, and watermark.
53#[derive(Clone, Debug)]
54pub struct ChartSemanticTokens {
55 /// Background color.
56 pub bg: Color32,
57 /// Background axis color.
58 pub bg_axis: Color32,
59 /// Grid line color.
60 pub grid_line: Color32,
61 /// Grid line major color.
62 pub grid_line_major: Color32,
63 /// Axis text color.
64 pub axis_text: Color32,
65 /// Axis text secondary color.
66 pub axis_text_secondary: Color32,
67 /// Crosshair line color.
68 pub crosshair_line: Color32,
69 /// Crosshair label background color.
70 pub crosshair_label_bg: Color32,
71 /// Crosshair label text color.
72 pub crosshair_label_text: Color32,
73 /// Bullish color.
74 pub bullish: Color32,
75 /// Bearish color.
76 pub bearish: Color32,
77 /// Volume up alpha, from transparent (0) to opaque (255).
78 pub volume_up_alpha: u8,
79 /// Volume down alpha, from transparent (0) to opaque (255).
80 pub volume_down_alpha: u8,
81 /// Watermark alpha, from transparent (0) to opaque (255).
82 pub watermark_alpha: u8,
83 /// Selection text color.
84 pub selection_text: Color32,
85}
86
87/// Brand accent colors (consistent across light/dark themes).
88#[derive(Clone, Debug)]
89pub struct BrandSemanticTokens {
90 /// Accent color.
91 pub accent: Color32,
92 /// Accent hover color.
93 pub accent_hover: Color32,
94 /// Accent active color.
95 pub accent_active: Color32,
96}
97
98/// Status and feedback colors (error, info, disabled, caution).
99#[derive(Clone, Debug)]
100pub struct StatusSemanticTokens {
101 /// Error color.
102 pub error: Color32,
103 /// Caution color.
104 pub caution: Color32,
105}
106
107/// Footprint (order flow) chart colors.
108#[derive(Clone, Debug)]
109pub struct FootprintSemanticTokens {
110 /// Point of control color.
111 pub poc: Color32,
112 /// Value area color.
113 pub value_area: Color32,
114 /// Imbalance buy color.
115 pub imbalance_buy: Color32,
116 /// Imbalance sell color.
117 pub imbalance_sell: Color32,
118}
119
120/// TPO (Market Profile) chart colors
121#[derive(Clone, Debug)]
122pub struct TpoSemanticTokens {
123 /// Point of Control row color
124 pub poc: Color32,
125 /// Value Area tone for value-area coloring
126 pub value_area: Color32,
127 /// Initial Balance bar color
128 pub initial_balance: Color32,
129 /// Single prints highlight color
130 pub single_print: Color32,
131 /// Session separator line color
132 pub session_separator: Color32,
133 /// Default TPO letter color
134 pub letter_default: Color32,
135 /// TPO grid line color
136 pub grid: Color32,
137 /// First stop of the gradient across a session's periods.
138 pub period_1: Color32,
139 /// Period 2 color.
140 pub period_2: Color32,
141 /// Period 3 color.
142 pub period_3: Color32,
143 /// Period 4 color.
144 pub period_4: Color32,
145 /// Period 5 color.
146 pub period_5: Color32,
147 /// Period 6 color.
148 pub period_6: Color32,
149 /// Period 7 color.
150 pub period_7: Color32,
151 /// Period 8 color.
152 pub period_8: Color32,
153 /// Period 9 color.
154 pub period_9: Color32,
155 /// Period 10 color.
156 pub period_10: Color32,
157 /// Period 11 color.
158 pub period_11: Color32,
159 /// Period 12 color.
160 pub period_12: Color32,
161}
162
163/// Legacy moving average colours still used by drawing defaults. Studies use `studies::palette`.
164#[derive(Clone, Debug)]
165pub struct IndicatorSemanticTokens {
166 /// Generic moving average line color.
167 pub ma: Color32,
168 /// Exponential moving average line color.
169 pub ema: Color32,
170}
171
172/// Drawing label and Fibonacci level colors.
173#[derive(Clone, Debug)]
174pub struct DrawingSemanticTokens {
175 /// Drawing label text color.
176 pub label_text: Color32,
177 /// Fibonacci retracement 50% level color.
178 pub fib_50: Color32,
179 /// Fibonacci retracement 100% level color.
180 pub fib_100: Color32,
181}
182
183/// Extended semantic tokens providing flat access to commonly used colors.
184///
185/// This is a convenience collection that gathers the most frequently accessed
186/// colors across domains (UI backgrounds, borders, text, accent, status,
187/// Material Design palette colors, chart colors, and trading colors) into
188/// a single flat namespace.
189#[derive(Clone, Debug)]
190pub struct ExtendedSemanticTokens {
191 /// Accent/brand color.
192 pub accent: Color32,
193 /// Success status color.
194 pub success: Color32,
195 /// Error status color.
196 pub error: Color32,
197 /// Caution status color (softer warning).
198 pub caution: Color32,
199 /// Info status color.
200 pub info: Color32,
201 /// Disabled/inactive state color.
202 pub disabled: Color32,
203 /// Material Design purple.
204 pub purple: Color32,
205 /// Gray color.
206 pub gray: Color32,
207 /// Light gray color.
208 pub light_gray: Color32,
209 /// Favorite/star gold color.
210 pub favorite_gold: Color32,
211 /// Chart area background.
212 pub chart_bg: Color32,
213 /// Chart axis background.
214 pub chart_axis_bg: Color32,
215 /// Chart tooltip background.
216 pub chart_tooltip_bg: Color32,
217 /// Chart text color.
218 pub chart_text: Color32,
219 /// Chart secondary text color.
220 pub chart_text_secondary: Color32,
221 /// Chart muted text color.
222 pub chart_text_muted: Color32,
223 /// Chart crosshair label background.
224 pub chart_crosshair_label_bg: Color32,
225 /// Bullish (up) trading color.
226 pub bullish: Color32,
227 /// Bearish (down) trading color.
228 pub bearish: Color32,
229}