1use super::{Resettable, Settings};
2
3use simple_color::Color;
4
5#[derive(Clone, Debug)]
6pub struct BoxColors<T> {
7 pub text_line: T,
8 pub text_fill: T,
9 pub name_line: T,
10 pub name_fill: T,
11}
12
13impl<T: From<Color>> BoxColors<T> {
14 pub fn common() -> Self {
15 Self {
16 text_line: Color::WHITE.into(),
17 text_fill: Color::BLACK.into(),
18 name_line: Color::WHITE.into(),
19 name_fill: Color::BLACK.into(),
20 }
21 }
22}
23
24#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
25pub enum BoxColorParameter {
26 TextLine,
27 TextFill,
28 NameLine,
29 NameFill,
30}
31
32impl<T> Settings<BoxColorParameter> for BoxColors<T> {
33 type Value = T;
34
35 fn get_mut(&mut self, parameter: &BoxColorParameter) -> &mut T {
36 use BoxColorParameter::*;
37 match parameter {
38 TextLine => &mut self.text_line,
39 TextFill => &mut self.text_fill,
40 NameLine => &mut self.name_line,
41 NameFill => &mut self.name_fill,
42 }
43 }
44}
45
46impl<T: Resettable> Resettable for BoxColors<T> {
47 fn reset(&mut self) {
48 self.text_line.reset();
49 self.text_fill.reset();
50 self.name_line.reset();
51 self.name_fill.reset();
52 }
53
54 fn reset_aspects(&mut self) {
55 self.text_line.reset_aspects();
56 self.text_fill.reset_aspects();
57 self.name_line.reset_aspects();
58 self.name_fill.reset_aspects();
59 }
60}
61
62#[derive(Clone, Debug)]
63pub struct SelectableBoxColors<T> {
64 pub default: BoxColors<T>,
65 pub selected: BoxColors<T>,
66}
67
68impl<T: From<Color>> SelectableBoxColors<T> {
69 pub fn common() -> Self {
70 Self {
71 default: BoxColors::common(),
72 selected: BoxColors {
73 text_fill: Color::gray(64).into(),
74 ..BoxColors::common()
75 },
76 }
77 }
78}
79
80#[derive(Clone, Debug, PartialEq, Eq, Hash)]
81pub struct SelectableBoxColorParameter {
82 pub selected: bool,
83 pub parameter: BoxColorParameter,
84}
85
86impl<T> Settings<SelectableBoxColorParameter> for SelectableBoxColors<T> {
87 type Value = T;
88
89 fn get_mut(&mut self, parameter: &SelectableBoxColorParameter) -> &mut T {
90 if parameter.selected {
91 &mut self.selected
92 } else {
93 &mut self.default
94 }
95 .get_mut(¶meter.parameter)
96 }
97}
98
99impl<T: Resettable> Resettable for SelectableBoxColors<T> {
100 fn reset(&mut self) {
101 self.default.reset();
102 self.selected.reset();
103 }
104
105 fn reset_aspects(&mut self) {
106 self.default.reset_aspects();
107 self.selected.reset_aspects();
108 }
109}
110
111#[derive(Clone)]
112pub struct ColorSettings<T> {
113 pub background: T,
114 pub foreground: T,
115 pub dialog_box: BoxColors<T>,
116 pub select_box: SelectableBoxColors<T>,
117 pub revert_box: SelectableBoxColors<T>,
118}
119
120impl<T: From<Color>> ColorSettings<T> {
121 pub fn common() -> Self {
122 Self {
123 background: Color::BLACK.into(),
124 foreground: Color::BLACK.a(0).into(),
125 dialog_box: BoxColors::common(),
126 select_box: SelectableBoxColors::common(),
127 revert_box: SelectableBoxColors::common(),
128 }
129 }
130}
131
132#[derive(Clone, Debug, PartialEq, Eq, Hash)]
133pub enum ColorParameter {
134 Background,
135 Foreground,
136 Dialog(BoxColorParameter),
137 Choice(SelectableBoxColorParameter),
138 Revert(SelectableBoxColorParameter),
139}
140
141impl<T> Settings<ColorParameter> for ColorSettings<T> {
142 type Value = T;
143
144 fn get_mut(&mut self, parameter: &ColorParameter) -> &mut T {
145 use ColorParameter::*;
146 match parameter {
147 Background => &mut self.background,
148 Foreground => &mut self.foreground,
149 Dialog(parameter) => self.dialog_box.get_mut(parameter),
150 Choice(parameter) => self.select_box.get_mut(parameter),
151 Revert(parameter) => self.revert_box.get_mut(parameter),
152 }
153 }
154}
155
156impl<T: Resettable> Resettable for ColorSettings<T> {
157 fn reset(&mut self) {
158 self.background.reset();
159 self.foreground.reset();
160 self.dialog_box.reset();
161 self.select_box.reset();
162 self.revert_box.reset();
163 }
164
165 fn reset_aspects(&mut self) {
166 self.background.reset_aspects();
167 self.foreground.reset_aspects();
168 self.dialog_box.reset_aspects();
169 self.select_box.reset_aspects();
170 self.revert_box.reset_aspects();
171 }
172}