-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmodifier.go
More file actions
309 lines (269 loc) · 7.32 KB
/
Copy pathmodifier.go
File metadata and controls
309 lines (269 loc) · 7.32 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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
package gova
import "image/color"
type modifierSet struct {
padding *paddingModifier
font *FontStyle
bold bool
italic bool
strikethrough bool
color any // color.Color or themeColor sentinel
background any // color.Color or themeColor sentinel
disabled bool
opacity float64
hasOpacity bool
frame *frameModifier
onTap func()
cornerRadius float32
hasCorner bool
shadow *shadowModifier
stroke *strokeModifier
a11yLabel string
a11yHint string
a11yRole AccessibilityRole
hasA11y bool
navTitle string
hasNavTitle bool
navToolbar *navToolbarData
grow bool
noWrap bool
}
type paddingModifier struct {
top, right, bottom, left float32
}
type frameModifier struct {
width, height float32
minWidth, minHeight float32
maxWidth, maxHeight float32
}
type shadowModifier struct {
color any
radius float32
offsetX, offsetY float32
}
type strokeModifier struct {
color any
width float32
}
// AccessibilityRole is a semantic role hint for assistive technologies.
type AccessibilityRole int
const (
RoleNone AccessibilityRole = iota
RoleButton
RoleLink
RoleImage
RoleHeader
)
// FontStyle represents a named font style.
type FontStyle int
const (
Body FontStyle = iota
Title
Title2
Title3
Caption
Mono
)
// Static colors: plain RGBA, do not adapt to theme.
var (
Red color.Color = color.NRGBA{R: 255, G: 59, B: 48, A: 255}
Blue color.Color = color.NRGBA{R: 0, G: 122, B: 255, A: 255}
Green color.Color = color.NRGBA{R: 52, G: 199, B: 89, A: 255}
Orange color.Color = color.NRGBA{R: 255, G: 149, B: 0, A: 255}
Purple color.Color = color.NRGBA{R: 175, G: 82, B: 222, A: 255}
Gray color.Color = color.NRGBA{R: 142, G: 142, B: 147, A: 255}
White color.Color = color.NRGBA{R: 255, G: 255, B: 255, A: 255}
Black color.Color = color.NRGBA{R: 0, G: 0, B: 0, A: 255}
)
// Spacing tokens: use instead of hard-coded numbers for visual consistency.
const (
SpaceXS float32 = 4
SpaceSM float32 = 8
SpaceMD float32 = 16
SpaceLG float32 = 24
SpaceXL float32 = 32
)
func (n *viewNode) Padding(all float32) *viewNode {
n.modifier.padding = &paddingModifier{all, all, all, all}
return n
}
func (n *viewNode) PaddingEdges(top, right, bottom, left float32) *viewNode {
n.modifier.padding = &paddingModifier{top, right, bottom, left}
return n
}
// PaddingH sets horizontal padding (leading + trailing).
func (n *viewNode) PaddingH(v float32) *viewNode {
p := n.modifier.padding
if p == nil {
p = &paddingModifier{}
}
p.left, p.right = v, v
n.modifier.padding = p
return n
}
// PaddingV sets vertical padding (top + bottom).
func (n *viewNode) PaddingV(v float32) *viewNode {
p := n.modifier.padding
if p == nil {
p = &paddingModifier{}
}
p.top, p.bottom = v, v
n.modifier.padding = p
return n
}
func (n *viewNode) PaddingTop(v float32) *viewNode {
p := n.modifier.padding
if p == nil {
p = &paddingModifier{}
}
p.top = v
n.modifier.padding = p
return n
}
func (n *viewNode) PaddingBottom(v float32) *viewNode {
p := n.modifier.padding
if p == nil {
p = &paddingModifier{}
}
p.bottom = v
n.modifier.padding = p
return n
}
func (n *viewNode) PaddingLeading(v float32) *viewNode {
p := n.modifier.padding
if p == nil {
p = &paddingModifier{}
}
p.left = v
n.modifier.padding = p
return n
}
func (n *viewNode) PaddingTrailing(v float32) *viewNode {
p := n.modifier.padding
if p == nil {
p = &paddingModifier{}
}
p.right = v
n.modifier.padding = p
return n
}
func (n *viewNode) Font(style FontStyle) *viewNode {
n.modifier.font = &style
return n
}
func (n *viewNode) Bold() *viewNode {
n.modifier.bold = true
return n
}
func (n *viewNode) Italic() *viewNode {
n.modifier.italic = true
return n
}
// Strikethrough draws a horizontal line through text. Applied via the
// Unicode combining long stroke overlay (\u0336) so it works in any
// font; has no effect on non-text nodes.
func (n *viewNode) Strikethrough(on bool) *viewNode {
n.modifier.strikethrough = on
return n
}
// Color sets the foreground color. Accepts a plain color.Color (fixed)
// or a semantic color constant (g.Primary, g.Accent, etc.) which resolves
// against the active theme at render time.
func (n *viewNode) Color(c any) *viewNode {
n.modifier.color = c
return n
}
func (n *viewNode) Background(c any) *viewNode {
n.modifier.background = c
return n
}
func (n *viewNode) Disabled(d bool) *viewNode {
n.modifier.disabled = d
return n
}
func (n *viewNode) Opacity(o float64) *viewNode {
n.modifier.opacity = o
n.modifier.hasOpacity = true
return n
}
// Frame sets the preferred minimum size. Pass 0 to leave an axis unconstrained.
func (n *viewNode) Frame(width, height float32) *viewNode {
if n.modifier.frame == nil {
n.modifier.frame = &frameModifier{}
}
n.modifier.frame.width = width
n.modifier.frame.height = height
return n
}
// MinWidth sets the minimum width.
func (n *viewNode) MinWidth(w float32) *viewNode {
if n.modifier.frame == nil {
n.modifier.frame = &frameModifier{}
}
n.modifier.frame.minWidth = w
return n
}
// MinHeight sets the minimum height.
func (n *viewNode) MinHeight(h float32) *viewNode {
if n.modifier.frame == nil {
n.modifier.frame = &frameModifier{}
}
n.modifier.frame.minHeight = h
return n
}
// Grow marks a child of an HStack/VStack to expand and fill available
// space on the stack's primary axis. Siblings pack at their natural size.
// In an HStack: children before the grow child become leading, children
// after become trailing, and the grow child fills the remainder.
func (n *viewNode) Grow() *viewNode {
n.modifier.grow = true
return n
}
func (n *viewNode) NoWrap() *viewNode {
n.modifier.noWrap = true
return n
}
// OnTap makes any view tappable. Panics if applied to a Button (which
// already has a handler via its constructor).
func (n *viewNode) OnTap(fn func()) *viewNode {
if n.kind == viewKindButton {
panic("gova: OnTap cannot be applied to a Button; pass the handler to Button() instead")
}
n.modifier.onTap = fn
return n
}
// CornerRadius rounds the view's visual box.
func (n *viewNode) CornerRadius(r float32) *viewNode {
n.modifier.cornerRadius = r
n.modifier.hasCorner = true
return n
}
// Shadow casts a drop shadow from the view's visual box.
func (n *viewNode) Shadow(c any, radius, offsetX, offsetY float32) *viewNode {
n.modifier.shadow = &shadowModifier{color: c, radius: radius, offsetX: offsetX, offsetY: offsetY}
return n
}
// Stroke adds a colored border (stroke) around the view's visual box.
// Named Stroke (not Border) because "Border" was the name of the old
// layout primitive and would confuse readers.
func (n *viewNode) Stroke(c any, width float32) *viewNode {
n.modifier.stroke = &strokeModifier{color: c, width: width}
return n
}
// AccessibilityLabel sets the text read by screen readers for this view.
func (n *viewNode) AccessibilityLabel(s string) *viewNode {
n.modifier.a11yLabel = s
n.modifier.hasA11y = true
return n
}
// AccessibilityHint sets additional context read by screen readers.
func (n *viewNode) AccessibilityHint(s string) *viewNode {
n.modifier.a11yHint = s
n.modifier.hasA11y = true
return n
}
// AccessibilityRole hints the semantic role of this view.
func (n *viewNode) AccessibilityRole(r AccessibilityRole) *viewNode {
n.modifier.a11yRole = r
n.modifier.hasA11y = true
return n
}