-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathadditional.go
160 lines (137 loc) · 2.95 KB
/
additional.go
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
package clay
import (
"fmt"
"iter"
"unsafe"
)
func (s String) String() string {
return unsafe.String(s.Chars, s.Length)
}
func (s StringSlice) String() string {
return unsafe.String(s.Chars, s.Length)
}
// confirm that ErrorData implements error type
var _ error = ErrorData{}
func (e ErrorData) Error() string {
return fmt.Sprintf("%s (code: %d)", e.ErrorText, e.ErrorType)
}
func toString(s string) String {
return String{Length: int32(len(s)), Chars: unsafe.StringData(s)}
}
func ID(label string) ElementId {
return __HashString(toString(label), 0, 0)
}
func PaddingAll(padding uint16) Padding {
return Padding{
padding,
padding,
padding,
padding,
}
}
func SizingGrow(sz float32) SizingAxis {
return SizingAxis{
Size: struct {
MinMax SizingMinMax
Percent float32
}{
MinMax: SizingMinMax{sz, sz},
},
Type: __SIZING_TYPE_GROW,
}
}
func SizingFixed(sz float32) SizingAxis {
return SizingAxis{
Size: struct {
MinMax SizingMinMax
Percent float32
}{
MinMax: SizingMinMax{sz, sz},
},
Type: __SIZING_TYPE_FIXED,
}
}
func SizingFit(min, max float32) SizingAxis {
return SizingAxis{
Size: struct {
MinMax SizingMinMax
Percent float32
}{
MinMax: SizingMinMax{min, max},
},
Type: __SIZING_TYPE_FIT,
}
}
func SizingPercent(percentOfParent float32) SizingAxis {
return SizingAxis{
Size: struct {
MinMax SizingMinMax
Percent float32
}{
Percent: percentOfParent,
},
Type: __SIZING_TYPE_PERCENT,
}
}
func CornerRadiusAll(radius float32) CornerRadius {
return CornerRadius{
radius,
radius,
radius,
radius,
}
}
func BorderOutside(width uint16) BorderWidth {
return BorderWidth{
width,
width,
width,
width,
0,
}
}
func BorderAll(width uint16) BorderWidth {
return BorderWidth{
width,
width,
width,
width,
width,
}
}
// TODO: add generic iterator functions for types with [type]_GetValue functions that are converted into methods
func UI() func(decl ElementDeclaration, children func()) {
__OpenElement()
return func(decl ElementDeclaration, children func()) {
__ConfigureOpenElement(decl)
defer __CloseElement()
if children != nil {
children()
}
}
}
func Text(text string, config *TextElementConfig) {
__OpenTextElement(toString(text), config)
}
func TextConfig(config TextElementConfig) *TextElementConfig {
return __StoreTextElementConfig(config)
}
func GetElementId(idString string) ElementId {
return getElementId(toString(idString))
}
func GetElementIdWithIndex(idString string, index uint32) ElementId {
return getElementIdWithIndex(toString(idString), index)
}
func (r *RenderCommandArray) Iter() iter.Seq[RenderCommand] {
return func(yield func(RenderCommand) bool) {
cmds := unsafe.Slice(r.InternalArray, r.Length)
for _, v := range cmds {
if !yield(v) {
return
}
}
}
}
func CreateArenaWithCapacityAndMemory(memory []byte) Arena {
return createArenaWithCapacityAndMemory(uint64(len(memory)), unsafe.Pointer(unsafe.SliceData(memory)))
}