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