/
windowComponent_gen.go
242 lines (215 loc) · 6 KB
/
windowComponent_gen.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
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
// Code generated by vitrum gencmd. DO NOT EDIT.
package gui
import (
"fmt"
vit "github.com/omniskop/vitrum/vit"
parse "github.com/omniskop/vitrum/vit/parse"
std "github.com/omniskop/vitrum/vit/std"
)
func newFileContextForWindowComponent(globalCtx *vit.GlobalContext) (*vit.FileContext, error) {
fileCtx := vit.NewFileContext(globalCtx)
var lib parse.Library
var err error
lib, err = parse.ResolveLibrary([]string{"Vit"})
if err != nil {
// The file used to generate the "WindowComponent" component imported a library called "Vit".
// If this error occurs that imported failed. Probably because the library is not known.
return nil, fmt.Errorf("unable to create file context for generated \"WindowComponent\" component: %w", err)
}
parse.AddLibraryToContainer(lib, &fileCtx.KnownComponents)
return fileCtx, nil
}
type WindowComponent struct {
*std.Item
id string
title vit.StringValue
maxWidth vit.FloatValue
maxHeight vit.FloatValue
minWidth vit.FloatValue
minHeight vit.FloatValue
}
// newWindowComponentInGlobal creates an appropriate file context for the component and then returns a new WindowComponent instance.
// The returned error will only be set if a library import that is required by the component fails.
func newWindowComponentInGlobal(id string, globalCtx *vit.GlobalContext, thisLibrary parse.Library) (*WindowComponent, error) {
fileCtx, err := newFileContextForWindowComponent(globalCtx)
if err != nil {
return nil, err
}
parse.AddLibraryToContainer(thisLibrary, &fileCtx.KnownComponents)
return NewWindowComponent(id, fileCtx), nil
}
func NewWindowComponent(id string, context *vit.FileContext) *WindowComponent {
w := &WindowComponent{
Item: std.NewItem("", context),
id: id,
title: *vit.NewEmptyStringValue(),
maxWidth: *vit.NewEmptyFloatValue(),
maxHeight: *vit.NewEmptyFloatValue(),
minWidth: *vit.NewEmptyFloatValue(),
minHeight: *vit.NewEmptyFloatValue(),
}
// property assignments on embedded components
// register listeners for when a property changes
// register event listeners
// register enumerations
// add child components
context.RegisterComponent("", w)
return w
}
func (w *WindowComponent) String() string {
return fmt.Sprintf("WindowComponent(%s)", w.id)
}
func (w *WindowComponent) Property(key string) (vit.Value, bool) {
switch key {
case "title":
return &w.title, true
case "maxWidth":
return &w.maxWidth, true
case "maxHeight":
return &w.maxHeight, true
case "minWidth":
return &w.minWidth, true
case "minHeight":
return &w.minHeight, true
default:
return w.Item.Property(key)
}
}
func (w *WindowComponent) MustProperty(key string) vit.Value {
v, ok := w.Property(key)
if !ok {
panic(fmt.Errorf("MustProperty called with unknown key %q", key))
}
return v
}
func (w *WindowComponent) SetProperty(key string, value interface{}) error {
var err error
switch key {
case "title":
err = w.title.SetValue(value)
case "maxWidth":
err = w.maxWidth.SetValue(value)
case "maxHeight":
err = w.maxHeight.SetValue(value)
case "minWidth":
err = w.minWidth.SetValue(value)
case "minHeight":
err = w.minHeight.SetValue(value)
default:
return w.Item.SetProperty(key, value)
}
if err != nil {
return vit.NewPropertyError("WindowComponent", key, w.id, err)
}
return nil
}
func (w *WindowComponent) SetPropertyCode(key string, code vit.Code) error {
switch key {
case "title":
w.title.SetCode(code)
case "maxWidth":
w.maxWidth.SetCode(code)
case "maxHeight":
w.maxHeight.SetCode(code)
case "minWidth":
w.minWidth.SetCode(code)
case "minHeight":
w.minHeight.SetCode(code)
default:
return w.Item.SetPropertyCode(key, code)
}
return nil
}
func (w *WindowComponent) Event(name string) (vit.Listenable, bool) {
switch name {
default:
return w.Item.Event(name)
}
}
func (w *WindowComponent) ResolveVariable(key string) (interface{}, bool) {
switch key {
case "title":
return &w.title, true
case "maxWidth":
return &w.maxWidth, true
case "maxHeight":
return &w.maxHeight, true
case "minWidth":
return &w.minWidth, true
case "minHeight":
return &w.minHeight, true
default:
return w.Item.ResolveVariable(key)
}
}
func (w *WindowComponent) AddChild(child vit.Component) {
child.SetParent(w)
w.AddChildButKeepParent(child)
}
func (w *WindowComponent) AddChildAfter(afterThis vit.Component, addThis vit.Component) {
var targetType vit.Component = afterThis
for ind, child := range w.Children() {
if child.As(&targetType) {
addThis.SetParent(w)
w.AddChildAtButKeepParent(addThis, ind+1)
return
}
}
w.AddChild(addThis)
}
func (w *WindowComponent) UpdateExpressions(context vit.Component) (int, vit.ErrorGroup) {
var sum int
var errs vit.ErrorGroup
if context == nil {
context = w
}
// properties
if changed, err := w.title.Update(context); changed || err != nil {
sum++
if err != nil {
errs.Add(vit.NewPropertyError("WindowComponent", "title", w.id, err))
}
}
if changed, err := w.maxWidth.Update(context); changed || err != nil {
sum++
if err != nil {
errs.Add(vit.NewPropertyError("WindowComponent", "maxWidth", w.id, err))
}
}
if changed, err := w.maxHeight.Update(context); changed || err != nil {
sum++
if err != nil {
errs.Add(vit.NewPropertyError("WindowComponent", "maxHeight", w.id, err))
}
}
if changed, err := w.minWidth.Update(context); changed || err != nil {
sum++
if err != nil {
errs.Add(vit.NewPropertyError("WindowComponent", "minWidth", w.id, err))
}
}
if changed, err := w.minHeight.Update(context); changed || err != nil {
sum++
if err != nil {
errs.Add(vit.NewPropertyError("WindowComponent", "minHeight", w.id, err))
}
}
// methods
n, err := w.Item.UpdateExpressions(context)
sum += n
errs.AddGroup(err)
return sum, errs
}
func (w *WindowComponent) As(target *vit.Component) bool {
if _, ok := (*target).(*WindowComponent); ok {
*target = w
return true
}
return w.Item.As(target)
}
func (w *WindowComponent) ID() string {
return w.id
}
func (w *WindowComponent) Finish() error {
return w.RootC().FinishInContext(w)
}