-
Notifications
You must be signed in to change notification settings - Fork 158
Expand file tree
/
Copy pathstyle_layouts.v
More file actions
207 lines (180 loc) · 5.18 KB
/
style_layouts.v
File metadata and controls
207 lines (180 loc) · 5.18 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
module ui
import gg
import x.json2
// CanvasLayout
pub struct CanvasLayoutShapeStyle {
pub mut:
bg_radius f32
bg_color gg.Color = no_color
}
pub struct CanvasLayoutStyle {
CanvasLayoutShapeStyle // 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 CanvasLayoutStyleParams {
WidgetTextStyleParams
pub mut:
style string = no_style
bg_radius f32
bg_color gg.Color = no_color
}
pub fn canvaslayout_style(p CanvasLayoutStyleParams) CanvasLayoutStyleParams {
return p
}
pub fn (ls CanvasLayoutStyle) to_json_any() json2.Any {
mut obj := map[string]json2.Any{}
obj['bg_radius'] = ls.bg_radius
obj['bg_color'] = hex_color(ls.bg_color)
return obj
}
pub fn (mut ls CanvasLayoutStyle) from_json(a json2.Any) {
m := a.as_map()
ls.bg_radius = (m['bg_radius'] or { json2.Any(0) }).f32()
ls.bg_color = HexColor((m['bg_color'] or { json2.Any('') }).str()).color()
}
fn (mut l CanvasLayout) load_style() {
// println("pgbar load style $l.theme_style")
mut style := if l.theme_style == '' { l.ui.window.theme_style } else { l.theme_style }
if l.style_params.style != no_style {
style = l.style_params.style
}
l.update_theme_style(style)
// forced overload default style
l.update_style(l.style_params)
}
pub fn (mut l CanvasLayout) update_theme_style(theme string) {
// println("$l.id update_theme_style <$theme>")
style := if theme == '' { 'default' } else { theme }
if style != no_style && style in l.ui.styles {
ls := l.ui.styles[style].cl
l.theme_style = theme
l.update_shape_theme_style(ls)
mut dtw := DrawTextWidget(l)
dtw.update_theme_style(ls)
}
}
pub fn (mut l CanvasLayout) update_style(p CanvasLayoutStyleParams) {
// println("$l.id update_style <$p>")
l.update_shape_style(p)
mut dtw := DrawTextWidget(l)
dtw.update_theme_style_params(p)
}
pub fn (mut l CanvasLayout) update_shape_theme_style(ls CanvasLayoutStyle) {
l.style.bg_radius = ls.bg_radius
l.style.bg_color = ls.bg_color
}
pub fn (mut l CanvasLayout) update_shape_style(p CanvasLayoutStyleParams) {
if p.bg_radius > 0 {
l.style.bg_radius = p.bg_radius
}
if p.bg_color != no_color {
l.style.bg_color = p.bg_color
}
}
pub fn (mut l CanvasLayout) update_style_params(p CanvasLayoutStyleParams) {
if p.bg_radius > 0 {
l.style_params.bg_radius = p.bg_radius
}
if p.bg_color != no_color {
l.style_params.bg_color = p.bg_color
}
mut dtw := DrawTextWidget(l)
dtw.update_theme_style_params(p)
}
// Stack
pub struct StackShapeStyle {
pub mut:
bg_radius f32
bg_color gg.Color = no_color
}
pub struct StackStyle {
StackShapeStyle // 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 StackStyleParams {
pub mut:
style string = no_style
bg_radius f32
bg_color gg.Color = no_color
// text_style TextStyle
text_font_name string
text_color gg.Color = no_color
text_size f64
text_align TextHorizontalAlign = .@none
text_vertical_align TextVerticalAlign = .@none
}
pub fn stack_style(p StackStyleParams) StackStyleParams {
return p
}
pub fn (ls StackStyle) to_json_any() json2.Any {
mut obj := map[string]json2.Any{}
obj['bg_radius'] = ls.bg_radius
obj['bg_color'] = hex_color(ls.bg_color)
return obj
}
pub fn (mut ls StackStyle) from_json(a json2.Any) {
m := a.as_map()
ls.bg_radius = (m['bg_radius'] or { json2.Any(0) }).f32()
ls.bg_color = HexColor((m['bg_color'] or { json2.Any('') }).str()).color()
}
fn (mut l Stack) load_style() {
// println("stack load style $l.theme_style")
mut style := if l.theme_style == '' { l.ui.window.theme_style } else { l.theme_style }
if l.style_params.style != no_style {
style = l.style_params.style
}
l.update_theme_style(style)
// forced overload default style
l.update_style(l.style_params)
// println("s ls $l.theme_style $l.style $l.style_params")
}
pub fn (mut l Stack) update_theme_style(theme string) {
// println("update_style <$p.style>")
style := if theme == '' { 'default' } else { theme }
if style != no_style && style in l.ui.styles {
ls := l.ui.styles[style].stack
l.theme_style = theme
l.update_shape_theme_style(ls)
mut dtw := DrawTextWidget(l)
dtw.update_theme_style(ls)
}
}
pub fn (mut l Stack) update_style(p StackStyleParams) {
l.update_shape_style(p)
mut dtw := DrawTextWidget(l)
dtw.update_theme_style_params(p)
}
pub fn (mut l Stack) update_shape_theme_style(ls StackStyle) {
l.style.bg_radius = ls.bg_radius
l.style.bg_color = ls.bg_color
}
pub fn (mut l Stack) update_shape_style(p StackStyleParams) {
if p.bg_radius > 0 {
l.style.bg_radius = p.bg_radius
}
if p.bg_color != no_color {
l.style.bg_color = p.bg_color
}
}
pub fn (mut l Stack) update_style_params(p StackStyleParams) {
if p.bg_radius > 0 {
l.style_params.bg_radius = p.bg_radius
}
if p.bg_color != no_color {
l.style_params.bg_color = p.bg_color
}
mut dtw := DrawTextWidget(l)
dtw.update_theme_style_params(p)
}