1use crate::{App, Global, Rgba, Window, WindowAppearance, rgb};
2use std::ops::Deref;
3use std::sync::Arc;
4
5#[derive(Clone, Debug)]
9pub struct Colors {
10 pub text: Rgba,
12 pub selected_text: Rgba,
14 pub background: Rgba,
16 pub disabled: Rgba,
18 pub selected: Rgba,
20 pub border: Rgba,
22 pub separator: Rgba,
24 pub container: Rgba,
26}
27
28impl Default for Colors {
29 fn default() -> Self {
30 Self::light()
31 }
32}
33
34impl Colors {
35 pub fn for_appearance(window: &Window) -> Self {
37 match window.appearance() {
38 WindowAppearance::Light | WindowAppearance::VibrantLight => Self::light(),
39 WindowAppearance::Dark | WindowAppearance::VibrantDark => Self::dark(),
40 }
41 }
42
43 pub fn dark() -> Self {
45 Self {
46 text: rgb(0xffffff),
47 selected_text: rgb(0xffffff),
48 disabled: rgb(0x565656),
49 selected: rgb(0x2457ca),
50 background: rgb(0x222222),
51 border: rgb(0x000000),
52 separator: rgb(0xd9d9d9),
53 container: rgb(0x262626),
54 }
55 }
56
57 pub fn light() -> Self {
59 Self {
60 text: rgb(0x252525),
61 selected_text: rgb(0xffffff),
62 background: rgb(0xffffff),
63 disabled: rgb(0xb0b0b0),
64 selected: rgb(0x2a63d9),
65 border: rgb(0xd9d9d9),
66 separator: rgb(0xe6e6e6),
67 container: rgb(0xf4f5f5),
68 }
69 }
70
71 pub fn get_global(cx: &App) -> &Arc<Colors> {
73 &cx.global::<GlobalColors>().0
74 }
75}
76
77#[derive(Clone, Debug)]
79pub struct GlobalColors(pub Arc<Colors>);
80
81impl Deref for GlobalColors {
82 type Target = Arc<Colors>;
83
84 fn deref(&self) -> &Self::Target {
85 &self.0
86 }
87}
88
89impl Global for GlobalColors {}
90
91pub trait DefaultColors {
93 fn default_colors(&self) -> &Arc<Colors>;
95}
96
97impl DefaultColors for App {
98 fn default_colors(&self) -> &Arc<Colors> {
99 &self.global::<GlobalColors>().0
100 }
101}
102
103#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
107pub enum DefaultAppearance {
108 #[default]
110 Light,
111 Dark,
113}
114
115impl From<WindowAppearance> for DefaultAppearance {
116 fn from(appearance: WindowAppearance) -> Self {
117 match appearance {
118 WindowAppearance::Light | WindowAppearance::VibrantLight => Self::Light,
119 WindowAppearance::Dark | WindowAppearance::VibrantDark => Self::Dark,
120 }
121 }
122}