2023-02-25 14:05:25 -06:00
|
|
|
package main
|
|
|
|
|
2023-03-01 11:35:36 -06:00
|
|
|
import "git.wit.org/wit/gui/toolkit"
|
2023-02-25 14:05:25 -06:00
|
|
|
|
|
|
|
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
|
2023-03-01 11:35:36 -06:00
|
|
|
var debugPlugin bool
|
|
|
|
var debugError bool = true
|
2023-02-25 14:05:25 -06:00
|
|
|
// 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 {
|
2023-03-01 11:35:36 -06:00
|
|
|
log(debugToolkit, "GetText() Enter debugToolkit=", debugToolkit)
|
2023-02-25 14:05:25 -06:00
|
|
|
if (t.uiEntry != nil) {
|
2023-03-01 11:35:36 -06:00
|
|
|
log(debugToolkit, "uiEntry.Text() =", t.uiEntry.Text())
|
2023-02-25 14:05:25 -06:00
|
|
|
return t.uiEntry.Text()
|
|
|
|
}
|
|
|
|
if (t.uiMultilineEntry != nil) {
|
2023-03-01 11:35:36 -06:00
|
|
|
log(debugToolkit, "uiMultilineEntry.Text() =", t.uiMultilineEntry.Text())
|
2023-02-25 14:05:25 -06:00
|
|
|
text := t.uiMultilineEntry.Text()
|
2023-03-01 11:35:36 -06:00
|
|
|
log(debugToolkit, "uiMultilineEntry.Text() =", text)
|
2023-02-25 14:05:25 -06:00
|
|
|
t.text = text
|
|
|
|
return text
|
|
|
|
}
|
|
|
|
if (t.uiCombobox != nil) {
|
2023-03-01 11:35:36 -06:00
|
|
|
log(debugToolkit, "uiCombobox() =", t.text)
|
2023-02-25 14:05:25 -06:00
|
|
|
return t.text
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *andlabsT) SetText(s string) bool {
|
2023-03-01 11:35:36 -06:00
|
|
|
log(debugToolkit, "Text() SetText() Enter")
|
2023-02-25 14:05:25 -06:00
|
|
|
if (t.uiEntry != nil) {
|
2023-03-01 11:35:36 -06:00
|
|
|
log(debugToolkit, "Value() =", t.uiEntry.Text)
|
2023-02-25 14:05:25 -06:00
|
|
|
t.uiEntry.SetText(s)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if (t.uiMultilineEntry != nil) {
|
2023-03-01 11:35:36 -06:00
|
|
|
log(debugToolkit, "Value() =", t.uiMultilineEntry.Text)
|
2023-02-25 14:05:25 -06:00
|
|
|
t.uiMultilineEntry.SetText(s)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func sanity(t *andlabsT) bool {
|
|
|
|
if (debugToolkit) {
|
2023-03-01 11:35:36 -06:00
|
|
|
log(debugToolkit, "Value() Enter")
|
2023-02-25 14:05:25 -06:00
|
|
|
scs := spew.ConfigState{MaxDepth: 1}
|
|
|
|
scs.Dump(t)
|
|
|
|
}
|
|
|
|
if (t.uiEntry == nil) {
|
2023-03-01 11:35:36 -06:00
|
|
|
log(debugToolkit, "Value() =", t.uiEntry.Text)
|
2023-02-25 14:05:25 -06:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *andlabsT) SetValue(i int) bool {
|
2023-03-01 11:35:36 -06:00
|
|
|
log(debugToolkit, "SetValue() START")
|
2023-02-25 14:05:25 -06:00
|
|
|
if (sanity(t)) {
|
|
|
|
return false
|
|
|
|
}
|
2023-03-01 11:35:36 -06:00
|
|
|
t.Dump(debugToolkit)
|
2023-02-25 14:05:25 -06:00
|
|
|
// panic("got to toolkit.SetValue")
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *andlabsT) Value() int {
|
|
|
|
if (debugToolkit) {
|
2023-03-01 11:35:36 -06:00
|
|
|
log(debugToolkit, "Value() Enter")
|
2023-02-25 14:05:25 -06:00
|
|
|
scs := spew.ConfigState{MaxDepth: 1}
|
|
|
|
scs.Dump(t)
|
|
|
|
}
|
|
|
|
if (t == nil) {
|
2023-03-01 11:35:36 -06:00
|
|
|
log(debugToolkit, "Value() can not get value t == nil")
|
2023-02-25 14:05:25 -06:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
if (t.uiSlider != nil) {
|
2023-03-01 11:35:36 -06:00
|
|
|
log(debugToolkit, "Value() =", t.uiSlider.Value)
|
2023-02-25 14:05:25 -06:00
|
|
|
return t.uiSlider.Value()
|
|
|
|
}
|
|
|
|
if (t.uiSpinbox != nil) {
|
2023-03-01 11:35:36 -06:00
|
|
|
log(debugToolkit, "Value() =", t.uiSpinbox.Value)
|
2023-02-25 14:05:25 -06:00
|
|
|
return t.uiSpinbox.Value()
|
|
|
|
}
|
2023-03-01 11:35:36 -06:00
|
|
|
log(debugToolkit, "Value() Could not find a ui element to get a value from")
|
2023-02-25 14:05:25 -06:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2023-03-01 11:35:36 -06:00
|
|
|
func (t *andlabsT) Dump(b bool) {
|
|
|
|
if ! b {
|
2023-02-25 14:05:25 -06:00
|
|
|
return
|
|
|
|
}
|
2023-03-01 11:35:36 -06:00
|
|
|
log(b, "Name = ", t.Name, t.Width, t.Height)
|
2023-02-25 14:05:25 -06:00
|
|
|
if (t.uiBox != nil) {
|
2023-03-01 11:35:36 -06:00
|
|
|
log(b, "uiBox =", t.uiBox)
|
2023-02-25 14:05:25 -06:00
|
|
|
}
|
|
|
|
if (t.uiButton != nil) {
|
2023-03-01 11:35:36 -06:00
|
|
|
log(b, "uiButton =", t.uiButton)
|
2023-02-25 14:05:25 -06:00
|
|
|
}
|
|
|
|
if (t.uiCombobox != nil) {
|
2023-03-01 11:35:36 -06:00
|
|
|
log(b, "uiCombobox =", t.uiCombobox)
|
2023-02-25 14:05:25 -06:00
|
|
|
}
|
|
|
|
if (t.uiWindow != nil) {
|
2023-03-01 11:35:36 -06:00
|
|
|
log(b, "uiWindow =", t.uiWindow)
|
2023-02-25 14:05:25 -06:00
|
|
|
}
|
|
|
|
if (t.uiTab != nil) {
|
2023-03-01 11:35:36 -06:00
|
|
|
log(b, "uiTab =", t.uiTab)
|
2023-02-25 14:05:25 -06:00
|
|
|
}
|
|
|
|
if (t.uiGroup != nil) {
|
2023-03-01 11:35:36 -06:00
|
|
|
log(b, "uiGroup =", t.uiGroup)
|
2023-02-25 14:05:25 -06:00
|
|
|
}
|
|
|
|
if (t.uiEntry != nil) {
|
2023-03-01 11:35:36 -06:00
|
|
|
log(b, "uiEntry =", t.uiEntry)
|
2023-02-25 14:05:25 -06:00
|
|
|
}
|
|
|
|
if (t.uiMultilineEntry != nil) {
|
2023-03-01 11:35:36 -06:00
|
|
|
log(b, "uiMultilineEntry =", t.uiMultilineEntry)
|
2023-02-25 14:05:25 -06:00
|
|
|
}
|
|
|
|
if (t.uiSlider != nil) {
|
2023-03-01 11:35:36 -06:00
|
|
|
log(b, "uiSlider =", t.uiSlider)
|
2023-02-25 14:05:25 -06:00
|
|
|
}
|
|
|
|
if (t.uiCheckbox != nil) {
|
2023-03-01 11:35:36 -06:00
|
|
|
log(b, "uiCheckbox =", t.uiCheckbox)
|
2023-02-25 14:05:25 -06:00
|
|
|
}
|
2023-03-01 11:35:36 -06:00
|
|
|
widgetDump(b, t.tw)
|
|
|
|
}
|
|
|
|
|
|
|
|
func widgetDump(b bool, w *toolkit.Widget) {
|
|
|
|
if (w == nil) {
|
|
|
|
log(b, "widget = nil")
|
|
|
|
return
|
2023-02-25 14:05:25 -06:00
|
|
|
}
|
2023-03-01 11:35:36 -06:00
|
|
|
|
|
|
|
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)
|
2023-02-25 14:05:25 -06:00
|
|
|
}
|