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
|
package main
import "git.wit.org/wit/gui/toolkit"
import "github.com/davecgh/go-spew/spew"
var defaultBehavior bool = true
var bookshelf bool // do you want things arranged in the box like a bookshelf or a stack?
var canvas bool // if set to true, the windows are a raw canvas
var menubar bool // for windows
var stretchy bool // expand things like buttons to the maximum size
var padded bool // add space between things like buttons
var margin bool // add space around the frames of windows
var debugToolkit bool
var debugChange bool
var debugPlugin bool
var debugError bool = true
// var DebugToolkit bool
// This is important. This sets the defaults for the gui. Without this, there isn't correct padding, etc
func setDefaultBehavior(s bool) {
defaultBehavior = s
if (defaultBehavior) {
log(debugToolkit, "Setting this toolkit to use the default behavior.")
log(debugToolkit, "This is the 'guessing' part as defined by the wit/gui 'Principles'. Refer to the docs.")
stretchy = false
padded = true
menubar = true
margin = true
canvas = false
bookshelf = true // 99% of the time, things make a vertical stack of objects
} else {
log(debugToolkit, "This toolkit is set to ignore the default behavior.")
}
}
func SetDebugToolkit (s bool) {
debugToolkit = s
log(true, "debugToolkit =", debugToolkit)
log(true, "debugChange =", debugChange)
}
func SetDebugChange (s bool) {
debugChange = s
log(true, "debugToolkit =", debugToolkit)
log(true, "debugChange =", debugChange)
}
func ShowDebug () {
log(true, "debugToolkit =", debugToolkit)
log(true, "debugChange =", debugChange)
}
func GetDebugToolkit () bool {
return debugToolkit
}
func (t *andlabsT) String() string {
return t.GetText()
}
func (t *andlabsT) GetText() string {
log(debugToolkit, "GetText() Enter debugToolkit=", debugToolkit)
if (t.uiEntry != nil) {
log(debugToolkit, "uiEntry.Text() =", t.uiEntry.Text())
return t.uiEntry.Text()
}
if (t.uiMultilineEntry != nil) {
log(debugToolkit, "uiMultilineEntry.Text() =", t.uiMultilineEntry.Text())
text := t.uiMultilineEntry.Text()
log(debugToolkit, "uiMultilineEntry.Text() =", text)
t.text = text
return text
}
if (t.uiCombobox != nil) {
log(debugToolkit, "uiCombobox() =", t.text)
return t.text
}
return ""
}
func (t *andlabsT) SetText(s string) bool {
log(debugToolkit, "Text() SetText() Enter")
if (t.uiEntry != nil) {
log(debugToolkit, "Value() =", t.uiEntry.Text)
t.uiEntry.SetText(s)
return true
}
if (t.uiMultilineEntry != nil) {
log(debugToolkit, "Value() =", t.uiMultilineEntry.Text)
t.uiMultilineEntry.SetText(s)
return true
}
return false
}
func sanity(t *andlabsT) bool {
if (debugToolkit) {
log(debugToolkit, "Value() Enter")
scs := spew.ConfigState{MaxDepth: 1}
scs.Dump(t)
}
if (t.uiEntry == nil) {
log(debugToolkit, "Value() =", t.uiEntry.Text)
return false
}
return true
}
func (t *andlabsT) SetValue(i int) bool {
log(debugToolkit, "SetValue() START")
if (sanity(t)) {
return false
}
t.Dump(debugToolkit)
// panic("got to toolkit.SetValue")
return true
}
func (t *andlabsT) Value() int {
if (debugToolkit) {
log(debugToolkit, "Value() Enter")
scs := spew.ConfigState{MaxDepth: 1}
scs.Dump(t)
}
if (t == nil) {
log(debugToolkit, "Value() can not get value t == nil")
return 0
}
if (t.uiSlider != nil) {
log(debugToolkit, "Value() =", t.uiSlider.Value)
return t.uiSlider.Value()
}
if (t.uiSpinbox != nil) {
log(debugToolkit, "Value() =", t.uiSpinbox.Value)
return t.uiSpinbox.Value()
}
log(debugToolkit, "Value() Could not find a ui element to get a value from")
return 0
}
func (t *andlabsT) Dump(b bool) {
if ! b {
return
}
log(b, "Name = ", t.Name, t.Width, t.Height)
if (t.uiBox != nil) {
log(b, "uiBox =", t.uiBox)
}
if (t.uiButton != nil) {
log(b, "uiButton =", t.uiButton)
}
if (t.uiCombobox != nil) {
log(b, "uiCombobox =", t.uiCombobox)
}
if (t.uiWindow != nil) {
log(b, "uiWindow =", t.uiWindow)
}
if (t.uiTab != nil) {
log(b, "uiTab =", t.uiTab)
}
if (t.uiGroup != nil) {
log(b, "uiGroup =", t.uiGroup)
}
if (t.uiEntry != nil) {
log(b, "uiEntry =", t.uiEntry)
}
if (t.uiMultilineEntry != nil) {
log(b, "uiMultilineEntry =", t.uiMultilineEntry)
}
if (t.uiSlider != nil) {
log(b, "uiSlider =", t.uiSlider)
}
if (t.uiCheckbox != nil) {
log(b, "uiCheckbox =", t.uiCheckbox)
}
widgetDump(b, t.tw)
}
func widgetDump(b bool, w *toolkit.Widget) {
if (w == nil) {
log(b, "widget = nil")
return
}
log(b, "widget.Name =", w.Name)
log(b, "widget.Action =", w.Action)
log(b, "widget.Type =", w.Type)
log(b, "widget.Custom =", w.Custom)
log(b, "widget.B =", w.B)
log(b, "widget.I =", w.I)
log(b, "widget.Width =", w.Width)
log(b, "widget.Height =", w.Height)
log(b, "widget.X =", w.X)
log(b, "widget.Y =", w.Y)
}
|