1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
use crate::{App, Global, Rgba, Window, WindowAppearance, rgb};
use std::ops::Deref;
use std::sync::Arc;
/// The default set of colors for wgpui.
///
/// These are used for styling base components, examples and more.
#[derive(Clone, Debug)]
pub struct Colors {
/// Primary text color
pub text: Rgba,
/// Muted/secondary text color
pub text_muted: Rgba,
/// Selected text color
pub selected_text: Rgba,
/// Background color (root level)
pub background: Rgba,
/// Surface color (cards, panels, elevated containers)
pub surface: Rgba,
/// Surface color on hover
pub surface_hover: Rgba,
/// Disabled color
pub disabled: Rgba,
/// Selected color
pub selected: Rgba,
/// Border color
pub border: Rgba,
/// Separator color
pub separator: Rgba,
/// Container color
pub container: Rgba,
/// Accent/primary action color (macOS blue)
pub accent: Rgba,
/// Accent color on hover
pub accent_hover: Rgba,
/// Accent color when active/pressed
pub accent_active: Rgba,
/// Success/positive color
pub success: Rgba,
/// Success color on hover
pub success_hover: Rgba,
/// Warning/caution color
pub warning: Rgba,
/// Warning color on hover
pub warning_hover: Rgba,
/// Error/destructive color
pub error: Rgba,
/// Error color on hover
pub error_hover: Rgba,
}
impl Default for Colors {
fn default() -> Self {
Self::light()
}
}
impl Colors {
/// Returns the default colors for the given window appearance.
pub fn for_appearance(window: &Window) -> Self {
match window.appearance() {
WindowAppearance::Light | WindowAppearance::VibrantLight => Self::light(),
WindowAppearance::Dark | WindowAppearance::VibrantDark => Self::dark(),
}
}
/// Returns the default dark colors
pub fn dark() -> Self {
Self {
// Text
text: rgb(0xffffff),
text_muted: rgb(0x98989d),
selected_text: rgb(0xffffff),
disabled: rgb(0x565656),
// Backgrounds
background: rgb(0x1e1e1e),
surface: rgb(0x2d2d2d),
surface_hover: rgb(0x3d3d3d),
container: rgb(0x262626),
// Borders
border: rgb(0x3d3d3d),
separator: rgb(0x3d3d3d),
// Selection
selected: rgb(0x0058d0),
// Accent (macOS blue)
accent: rgb(0x0a84ff),
accent_hover: rgb(0x409cff),
accent_active: rgb(0x0071e3),
// Success (green)
success: rgb(0x30d158),
success_hover: rgb(0x28cd52),
// Warning (yellow/orange)
warning: rgb(0xffd60a),
warning_hover: rgb(0xffcc00),
// Error (red)
error: rgb(0xff453a),
error_hover: rgb(0xff6961),
}
}
/// Returns the default light colors
pub fn light() -> Self {
Self {
// Text
text: rgb(0x1d1d1f),
text_muted: rgb(0x86868b),
selected_text: rgb(0xffffff),
disabled: rgb(0xb0b0b0),
// Backgrounds
background: rgb(0xffffff),
surface: rgb(0xf5f5f7),
surface_hover: rgb(0xe8e8ed),
container: rgb(0xf5f5f7),
// Borders
border: rgb(0xd2d2d7),
separator: rgb(0xd2d2d7),
// Selection
selected: rgb(0x0066cc),
// Accent (macOS blue)
accent: rgb(0x007aff),
accent_hover: rgb(0x0071e3),
accent_active: rgb(0x0058d0),
// Success (green)
success: rgb(0x28cd41),
success_hover: rgb(0x23b839),
// Warning (yellow/orange)
warning: rgb(0xff9f0a),
warning_hover: rgb(0xe68f09),
// Error (red)
error: rgb(0xff3b30),
error_hover: rgb(0xe6352b),
}
}
/// Get [Colors] from the global state
pub fn get_global(cx: &App) -> &Arc<Colors> {
&cx.global::<GlobalColors>().0
}
}
/// Get [Colors] from the global state
#[derive(Clone, Debug)]
pub struct GlobalColors(pub Arc<Colors>);
impl Deref for GlobalColors {
type Target = Arc<Colors>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl Global for GlobalColors {}
/// Implement this trait to allow global [Colors] access via `cx.default_colors()`.
pub trait DefaultColors {
/// Returns the default [`Colors`]
fn default_colors(&self) -> &Arc<Colors>;
}
impl DefaultColors for App {
fn default_colors(&self) -> &Arc<Colors> {
&self.global::<GlobalColors>().0
}
}
/// The appearance of the base WGPUI colors, used to style WGPUI elements
///
/// Varies based on the system's current [`WindowAppearance`].
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
pub enum DefaultAppearance {
/// Use the set of colors for light appearances.
#[default]
Light,
/// Use the set of colors for dark appearances.
Dark,
}
impl From<WindowAppearance> for DefaultAppearance {
fn from(appearance: WindowAppearance) -> Self {
match appearance {
WindowAppearance::Light | WindowAppearance::VibrantLight => Self::Light,
WindowAppearance::Dark | WindowAppearance::VibrantDark => Self::Dark,
}
}
}