forked from vlang/ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui_extra_theme.v
58 lines (45 loc) · 1.39 KB
/
ui_extra_theme.v
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
module ui
import gx
// No color is defined when alpha = 0 at least
const no_color = gx.Color{0, 0, 0, 0}
enum ColorType {
button_normal = 1 // see button.v
button_pressed
}
struct Color {
id ColorType
color gx.Color
}
type ColorTheme = map[int]gx.Color
type ColorThemes = map[string]ColorTheme
type ColorThemeCfg = ColorTheme | string
// create new color theme
pub fn color_theme(items ...Color) ColorTheme {
mut theme := map[int]gx.Color{}
for item in items {
theme[int(item.id)] = item.color
}
return theme
}
// register color theme
pub fn (mut w Window) register_color_theme(name string, theme ColorTheme) {
w.color_themes[name] = theme
}
fn (mut w Window) register_default_color_themes() {
w.color_themes['classic'] = color_theme(Color{.button_normal, gx.white}, Color{.button_pressed, gx.rgb(219,
219, 219)})
w.color_themes['red'] = color_theme(Color{.button_normal, gx.light_red}, Color{.button_pressed, gx.rgb(219,
0, 0)})
w.color_themes['blue'] = color_theme(Color{.button_normal, gx.light_blue}, Color{.button_pressed, gx.blue})
}
pub fn color(theme map[int]gx.Color, id ColorType) gx.Color {
return theme[int(id)]
}
pub fn set_color(mut theme map[int]gx.Color, id ColorType, color gx.Color) {
theme[int(id)] = color
}
pub fn update_colors_from(mut theme map[int]gx.Color, theme2 map[int]gx.Color, ids []ColorType) {
for id in ids {
theme[int(id)] = theme2[int(id)]
}
}