-
Notifications
You must be signed in to change notification settings - Fork 160
Expand file tree
/
Copy pathstyle_textbox.v
More file actions
102 lines (88 loc) · 2.43 KB
/
style_textbox.v
File metadata and controls
102 lines (88 loc) · 2.43 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
module ui
import gg
import x.json2
// TextBox
pub struct TextBoxShapeStyle {
pub mut:
bg_radius f32
bg_color gg.Color = gg.white
}
pub struct TextBoxStyle {
TextBoxShapeStyle // text_style TextStyle
pub mut:
text_font_name string = 'system'
text_color gg.Color
text_size int = 16
text_align TextHorizontalAlign = .left
text_vertical_align TextVerticalAlign = .top
}
@[params]
pub struct TextBoxStyleParams {
WidgetTextStyleParams
pub mut:
style string = no_style
bg_radius f32
bg_color gg.Color = no_color
}
pub fn textbox_style(p TextBoxStyleParams) TextBoxStyleParams {
return p
}
pub fn (ts TextBoxStyle) to_json_any() json2.Any {
mut obj := map[string]json2.Any{}
obj['bg_radius'] = ts.bg_radius
obj['bg_color'] = hex_color(ts.bg_color)
return obj
}
pub fn (mut ts TextBoxStyle) from_json(a json2.Any) {
m := a.as_map()
ts.bg_radius = (m['bg_radius'] or { json2.Any(0) }).f32()
ts.bg_color = HexColor((m['bg_color'] or { json2.Any('') }).str()).color()
}
fn (mut t TextBox) load_style() {
// println("pgbar load style $t.theme_style")
mut style := if t.theme_style == '' { t.ui.window.theme_style } else { t.theme_style }
if t.style_params.style != no_style {
style = t.style_params.style
}
t.update_theme_style(style)
// forced overload default style
t.update_style(t.style_params)
}
pub fn (mut t TextBox) update_theme_style(theme string) {
// println("update_style <$p.style>")
style := if theme == '' { 'default' } else { theme }
if style != no_style && style in t.ui.styles {
ts := t.ui.styles[style].tb
t.theme_style = theme
t.update_shape_theme_style(ts)
mut dtw := DrawTextWidget(t)
dtw.update_theme_style(ts)
}
}
pub fn (mut t TextBox) update_style(p TextBoxStyleParams) {
t.update_shape_style(p)
mut dtw := DrawTextWidget(t)
dtw.update_theme_style_params(p)
}
pub fn (mut t TextBox) update_shape_theme_style(ts TextBoxStyle) {
t.style.bg_radius = ts.bg_radius
t.style.bg_color = ts.bg_color
}
pub fn (mut t TextBox) update_shape_style(p TextBoxStyleParams) {
if p.bg_radius > 0 {
t.style.bg_radius = p.bg_radius
}
if p.bg_color != no_color {
t.style.bg_color = p.bg_color
}
}
pub fn (mut t TextBox) update_style_params(p TextBoxStyleParams) {
if p.bg_radius > 0 {
t.style_params.bg_radius = p.bg_radius
}
if p.bg_color != no_color {
t.style_params.bg_color = p.bg_color
}
mut dtw := DrawTextWidget(t)
dtw.update_theme_style_params(p)
}