-
Notifications
You must be signed in to change notification settings - Fork 158
Expand file tree
/
Copy pathstyle_slider.v
More file actions
84 lines (74 loc) · 2.52 KB
/
style_slider.v
File metadata and controls
84 lines (74 loc) · 2.52 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
module ui
import gg
import x.json2
// Slider
pub struct SliderStyle {
pub mut:
thumb_color gg.Color = gg.rgb(87, 153, 245)
bg_color gg.Color = gg.rgb(219, 219, 219)
bg_border_color gg.Color = gg.rgb(191, 191, 191)
focused_bg_border_color gg.Color = gg.rgb(255, 0, 0)
}
@[params]
pub struct SliderStyleParams {
pub mut:
style string = no_style
thumb_color gg.Color = no_color
bg_color gg.Color = no_color
bg_border_color gg.Color = no_color
focused_bg_border_color gg.Color = no_color
}
pub fn slider_style(p SliderStyleParams) SliderStyleParams {
return p
}
pub fn (ss SliderStyle) to_json_any() json2.Any {
mut obj := map[string]json2.Any{}
obj['thumb_color'] = hex_color(ss.thumb_color)
obj['bg_color'] = hex_color(ss.bg_color)
obj['bg_border_color'] = hex_color(ss.bg_border_color)
obj['focused_bg_border_color'] = hex_color(ss.focused_bg_border_color)
return obj
}
pub fn (mut ss SliderStyle) from_json(a json2.Any) {
m := a.as_map()
ss.thumb_color = HexColor((m['thumb_color'] or { json2.Any('') }).str()).color()
ss.bg_color = HexColor((m['bg_color'] or { json2.Any('') }).str()).color()
ss.bg_border_color = HexColor((m['bg_border_color'] or { json2.Any('') }).str()).color()
ss.focused_bg_border_color = HexColor((m['focused_bg_border_color'] or { json2.Any('') }).str()).color()
}
fn (mut s Slider) load_style() {
// println("pgbar load style $s.theme_style")
mut style := if s.theme_style == '' { s.ui.window.theme_style } else { s.theme_style }
if s.style_params.style != no_style {
style = s.style_params.style
}
s.update_theme_style(style)
// forced overload default style
s.update_style(s.style_params)
}
pub fn (mut s Slider) update_theme_style(theme string) {
// println("update_style <$p.style>")
style := if theme == '' { 'default' } else { theme }
if style != no_style && style in s.ui.styles {
ss := s.ui.styles[style].slider
s.theme_style = theme
s.style.thumb_color = ss.thumb_color
s.style.bg_color = ss.bg_color
s.style.bg_border_color = ss.bg_border_color
s.style.focused_bg_border_color = ss.focused_bg_border_color
}
}
pub fn (mut s Slider) update_style(p SliderStyleParams) {
if p.thumb_color != no_color {
s.style.thumb_color = p.thumb_color
}
if p.bg_color != no_color {
s.style.bg_color = p.bg_color
}
if p.bg_border_color != no_color {
s.style.bg_border_color = p.bg_border_color
}
if p.focused_bg_border_color != no_color {
s.style.focused_bg_border_color = p.focused_bg_border_color
}
}