2022-10-17 11:56:43 -05:00
|
|
|
package toolkit
|
|
|
|
|
|
|
|
import "log"
|
|
|
|
|
|
|
|
import "github.com/andlabs/ui"
|
|
|
|
import _ "github.com/andlabs/ui/winmanifest"
|
|
|
|
|
|
|
|
import "github.com/davecgh/go-spew/spew"
|
|
|
|
|
|
|
|
var DebugToolkit bool = false
|
|
|
|
|
2022-10-19 13:23:22 -05:00
|
|
|
var streachy = true
|
|
|
|
var border = true
|
|
|
|
|
|
|
|
|
2022-10-17 11:56:43 -05:00
|
|
|
// stores the raw toolkit internals
|
|
|
|
type Toolkit struct {
|
|
|
|
id string
|
|
|
|
|
|
|
|
Name string
|
|
|
|
Width int
|
|
|
|
Height int
|
|
|
|
|
|
|
|
OnChanged func(*Toolkit)
|
2022-10-19 13:23:22 -05:00
|
|
|
OnExit func(*Toolkit)
|
|
|
|
|
|
|
|
Custom func()
|
2022-10-17 11:56:43 -05:00
|
|
|
|
|
|
|
uiBox *ui.Box
|
2022-10-19 13:23:22 -05:00
|
|
|
uiBox2 *ui.Box // temporary hack while implementing tabs
|
2022-10-17 11:56:43 -05:00
|
|
|
uiButton *ui.Button
|
|
|
|
uiControl *ui.Control
|
2022-10-20 06:55:42 -05:00
|
|
|
uiCombobox *ui.Combobox
|
2022-10-17 11:56:43 -05:00
|
|
|
uiEntry *ui.Entry
|
2022-10-17 22:39:03 -05:00
|
|
|
uiGroup *ui.Group
|
2022-10-17 11:56:43 -05:00
|
|
|
uiLabel *ui.Label
|
|
|
|
uiSlider *ui.Slider
|
|
|
|
uiSpinbox *ui.Spinbox
|
|
|
|
uiTab *ui.Tab
|
|
|
|
uiText *ui.EditableCombobox
|
|
|
|
uiWindow *ui.Window
|
2022-10-19 13:23:22 -05:00
|
|
|
UiWindowBad *ui.Window
|
2022-10-20 06:55:42 -05:00
|
|
|
|
|
|
|
// used as a counter to work around limitations of widgets like combobox
|
|
|
|
// this is probably fucked up and in many ways wrong because of unsafe goroutine threading
|
|
|
|
// but it's working for now due to the need for need for a correct interaction layer betten toolkits
|
|
|
|
c int
|
|
|
|
val map[int]string
|
|
|
|
text string
|
2022-10-17 22:39:03 -05:00
|
|
|
}
|
|
|
|
|
2022-10-17 11:56:43 -05:00
|
|
|
func (t *Toolkit) GetText() string {
|
|
|
|
if (DebugToolkit) {
|
|
|
|
log.Println("gui.Toolkit.Text() Enter")
|
|
|
|
scs := spew.ConfigState{MaxDepth: 1}
|
|
|
|
scs.Dump(t)
|
|
|
|
}
|
|
|
|
if (t.uiEntry != nil) {
|
|
|
|
if (DebugToolkit) {
|
|
|
|
log.Println("gui.Toolkit.Value() =", t.uiEntry.Text)
|
|
|
|
}
|
|
|
|
return t.uiEntry.Text()
|
|
|
|
}
|
2022-10-20 06:55:42 -05:00
|
|
|
if (t.uiCombobox != nil) {
|
|
|
|
if (DebugToolkit) {
|
|
|
|
log.Println("gui.Toolkit.GetText() =", t.text)
|
|
|
|
}
|
|
|
|
return t.text
|
|
|
|
}
|
2022-10-17 11:56:43 -05:00
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *Toolkit) SetText(s string) bool {
|
|
|
|
if (DebugToolkit) {
|
|
|
|
log.Println("gui.Toolkit.Text() Enter")
|
|
|
|
scs := spew.ConfigState{MaxDepth: 1}
|
|
|
|
scs.Dump(t)
|
|
|
|
}
|
|
|
|
if (t.uiEntry != nil) {
|
|
|
|
if (DebugToolkit) {
|
|
|
|
log.Println("gui.Toolkit.Value() =", t.uiEntry.Text)
|
|
|
|
}
|
|
|
|
t.uiEntry.SetText(s)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2022-10-19 13:23:22 -05:00
|
|
|
func sanity(t *Toolkit) bool {
|
|
|
|
if (DebugToolkit) {
|
|
|
|
log.Println("gui.Toolkit.Value() Enter")
|
|
|
|
scs := spew.ConfigState{MaxDepth: 1}
|
|
|
|
scs.Dump(t)
|
|
|
|
}
|
|
|
|
if (t.uiEntry == nil) {
|
|
|
|
if (DebugToolkit) {
|
|
|
|
log.Println("gui.Toolkit.Value() =", t.uiEntry.Text)
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *Toolkit) SetValue(i int) bool {
|
|
|
|
log.Println("gui.Toolkit.SetValue() START")
|
|
|
|
if (sanity(t)) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
t.Dump()
|
|
|
|
// panic("got to toolkit.SetValue")
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2022-10-17 11:56:43 -05:00
|
|
|
func (t *Toolkit) Value() int {
|
|
|
|
if (DebugToolkit) {
|
|
|
|
log.Println("gui.Toolkit.Value() Enter")
|
|
|
|
scs := spew.ConfigState{MaxDepth: 1}
|
|
|
|
scs.Dump(t)
|
|
|
|
}
|
|
|
|
if (t == nil) {
|
|
|
|
log.Println("gui.Toolkit.Value() can not get value t == nil")
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
if (t.uiSlider != nil) {
|
|
|
|
if (DebugToolkit) {
|
|
|
|
log.Println("gui.Toolkit.Value() =", t.uiSlider.Value)
|
|
|
|
}
|
|
|
|
return t.uiSlider.Value()
|
|
|
|
}
|
|
|
|
if (t.uiSpinbox != nil) {
|
|
|
|
if (DebugToolkit) {
|
|
|
|
log.Println("gui.Toolkit.Value() =", t.uiSpinbox.Value)
|
|
|
|
}
|
|
|
|
return t.uiSpinbox.Value()
|
|
|
|
}
|
|
|
|
log.Println("gui.Toolkit.Value() Could not find a ui element to get a value from")
|
|
|
|
return 0
|
|
|
|
}
|
2022-10-19 13:23:22 -05:00
|
|
|
|
|
|
|
func (t *Toolkit) Dump() {
|
|
|
|
log.Println("gui.Toolkit.Dump()", t.Name, t.Width, t.Height)
|
|
|
|
if (t.uiBox != nil) {
|
|
|
|
log.Println("gui.Toolkit.Dump() uiBox =", t.uiBox)
|
|
|
|
}
|
|
|
|
if (t.uiButton != nil) {
|
|
|
|
log.Println("gui.Toolkit.Dump() uiButton =", t.uiButton)
|
|
|
|
}
|
2022-10-20 06:55:42 -05:00
|
|
|
if (t.uiCombobox != nil) {
|
|
|
|
log.Println("gui.Toolkit.Dump() uiCombobox =", t.uiCombobox)
|
|
|
|
}
|
2022-10-19 13:23:22 -05:00
|
|
|
if (t.uiWindow != nil) {
|
|
|
|
log.Println("gui.Toolkit.Dump() uiWindow =", t.uiWindow)
|
|
|
|
}
|
|
|
|
if (t.uiTab != nil) {
|
|
|
|
log.Println("gui.Toolkit.Dump() uiTab =", t.uiTab)
|
|
|
|
}
|
|
|
|
if (t.uiGroup != nil) {
|
|
|
|
log.Println("gui.Toolkit.Dump() uiGroup =", t.uiGroup)
|
|
|
|
}
|
|
|
|
if (t.uiSlider != nil) {
|
|
|
|
log.Println("gui.Toolkit.Dump() uiSlider =", t.uiSlider)
|
|
|
|
}
|
|
|
|
if (t.OnExit != nil) {
|
2022-10-20 06:55:42 -05:00
|
|
|
log.Println("gui.Toolkit.Dump() OnExit =", t.OnExit)
|
|
|
|
}
|
|
|
|
if (t.Custom != nil) {
|
|
|
|
log.Println("gui.Toolkit.Dump() Custom =", t.Custom)
|
2022-10-19 13:23:22 -05:00
|
|
|
}
|
2022-10-20 06:55:42 -05:00
|
|
|
log.Println("gui.Toolkit.Dump() c =", t.c)
|
|
|
|
log.Println("gui.Toolkit.Dump() val =", t.val)
|
2022-10-19 13:23:22 -05:00
|
|
|
}
|