-
Notifications
You must be signed in to change notification settings - Fork 158
Expand file tree
/
Copy pathstyle_4colors.v
More file actions
150 lines (138 loc) · 3.62 KB
/
style_4colors.v
File metadata and controls
150 lines (138 loc) · 3.62 KB
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
module ui
import gg
import math
pub fn (mut w Window) load_4colors_style(colors []gg.Color) {
w.ui.update_4colors_style(colors)
mut l := Layout(w)
l.update_theme_style('4colors')
}
pub fn (mut l Layout) load_4colors_style(colors []gg.Color) {
mut gui := l.get_ui()
gui.update_4colors_style(colors)
l.update_theme_style('4colors')
}
pub fn (mut gui UI) update_4colors_style(colors []gg.Color) {
gui.style_colors = colors
gui.update_style_from_4colors()
}
pub fn (mut gui UI) update_style_from_4colors() {
colors := gui.style_colors
println(gui.style_colors)
mode := if colors[3] == gg.black { '' } else { '_white' }
gui.styles['4colors'] = Style{
// window
win: WindowStyle{
bg_color: colors[0]
}
// label
label: LabelStyle{
text_color: colors[3]
}
// button
btn: ButtonStyle{
radius: .1
border_color: button_border_color
bg_color: colors[2]
bg_color_pressed: colors[0]
bg_color_hover: colors[1]
text_color: colors[3]
}
// textbox
tb: TextBoxStyle{
bg_color: colors[2]
text_color: colors[3]
}
// checkbox
cb: CheckBoxStyle{
border_color: colors[1]
bg_color: colors[2]
check_mode: 'check' + mode
text_color: colors[3]
}
// radio
radio: RadioStyle{
border_color: colors[1]
bg_color: colors[2]
radio_mode: 'radio' + mode
text_color: colors[3]
}
// progressbar
pgbar: ProgressBarStyle{
color: colors[2]
border_color: colors[3]
bg_color: colors[1]
bg_border_color: colors[0]
}
// slider
slider: SliderStyle{
thumb_color: colors[3]
bg_color: colors[1]
bg_border_color: colors[0]
focused_bg_border_color: colors[2]
}
// menu
menu: MenuStyle{
border_color: colors[0]
bar_color: colors[2]
bg_color: colors[1]
bg_color_hover: colors[0]
text_color: colors[3]
}
// listbox
lb: ListBoxStyle{
border_color: colors[0]
bg_color: colors[1]
bg_color_pressed: colors[0]
bg_color_hover: colors[2]
text_color: colors[3]
}
// dropdown
dd: DropdownStyle{
bg_color: colors[1]
border_color: colors[0]
focus_color: colors[2]
drawer_color: colors[2]
text_color: colors[3]
}
}
gui.cb_image = gui.img('check' + mode)
gui.down_arrow = gui.img('arrow' + mode)
gui.radio_selected_image = gui.img('radio' + mode + '_selected')
}
// Accent colors as a particular case of 4 colors style
pub fn (mut w Window) load_accent_color_style(accent_color []int) {
w.ui.update_accent_color_style(accent_color)
mut l := Layout(w)
l.update_theme_style('4colors')
}
pub fn (mut l Layout) load_accent_color_style(accent_color []int) {
mut gui := l.get_ui()
gui.update_accent_color_style(accent_color)
l.update_theme_style('4colors')
}
pub fn (mut gui UI) update_accent_color_style(accent_color []int) {
// gui.accent_color = accent_color
gui.style_colors = color_scheme_from_accent_color(accent_color)
gui.update_style_from_4colors()
}
pub fn color_scheme_from_accent_color(accent_color []int) []gg.Color {
mut font_color := [0, 0, 0]
if accent_color[0] + accent_color[1] + accent_color[2] / 3 < 255 * 3 / 2 {
font_color = [255, 255, 255]
}
color_scheme := [
[accent_color[0] / 3, accent_color[1] / 3, accent_color[2] / 3],
accent_color,
[accent_color[0] * 5 / 3, accent_color[1] * 5 / 3, accent_color[2] * 5 / 3],
font_color,
]
mut colors := []gg.Color{}
for color in color_scheme {
colors << gg.Color{
r: u8(math.max(math.min(color[0], 255), 0))
g: u8(math.max(math.min(color[1], 255), 0))
b: u8(math.max(math.min(color[2], 255), 0))
}
}
return colors
}