DEMO: add andlabs/ui demo window

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2022-10-17 11:56:43 -05:00
parent 12d232ba62
commit 412b287403
5 changed files with 130 additions and 49 deletions

View File

@ -15,6 +15,9 @@ var nodeNames = make([]string, 100)
func DebugWindow() {
Config.Title = "git.wit.org/wit/gui debug"
Config.Width = 640
Config.Height = 480
Config.Exit = StandardClose
node := NewWindow()
node.DebugTab("WIT GUI Debug Tab")
}

23
toolkit/andlabs/entry.go Normal file
View File

@ -0,0 +1,23 @@
package toolkit
import "log"
import "github.com/andlabs/ui"
import _ "github.com/andlabs/ui/winmanifest"
func NewEntry(b *ui.Box, name string) *Toolkit {
// make new node here
log.Println("gui.Toolbox.NewEntry", name)
var t Toolkit
if (b == nil) {
log.Println("gui.ToolboxNode.NewEntry() node.UiBox == nil. I can't add a range UI element without a place to put it")
return &t
}
l := ui.NewEntry()
t.uiEntry = l
t.uiBox = b
t.uiBox.Append(l, false)
return &t
}

View File

@ -7,55 +7,6 @@ import _ "github.com/andlabs/ui/winmanifest"
import "github.com/davecgh/go-spew/spew"
var DebugToolkit bool = false
// stores the raw toolkit internals
type Toolkit struct {
id string
Name string
Width int
Height int
OnChanged func(*Toolkit)
uiBox *ui.Box
uiButton *ui.Button
uiControl *ui.Control
uiLabel *ui.Label
uiSlider *ui.Slider
uiSpinbox *ui.Spinbox
uiTab *ui.Tab
uiText *ui.EditableCombobox
uiWindow *ui.Window
}
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
}
func NewSpinbox(b *ui.Box, name string, x int, y int) *Toolkit {
// make new node here
log.Println("gui.Toolbox.NewSpinbox()", x, y)

View File

@ -0,0 +1,89 @@
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
// stores the raw toolkit internals
type Toolkit struct {
id string
Name string
Width int
Height int
OnChanged func(*Toolkit)
uiBox *ui.Box
uiButton *ui.Button
uiControl *ui.Control
uiEntry *ui.Entry
uiLabel *ui.Label
uiSlider *ui.Slider
uiSpinbox *ui.Spinbox
uiTab *ui.Tab
uiText *ui.EditableCombobox
uiWindow *ui.Window
}
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()
}
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
}
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
}

View File

@ -4,6 +4,21 @@ import "log"
import "github.com/andlabs/ui"
import _ "github.com/andlabs/ui/winmanifest"
func ToolkitDemoWindow() {
var w *Node
log.Println("ToolkitDemoWindow() START")
Config.Title = "Demo the GUI Toolkit"
Config.Width = 640
Config.Height = 480
Config.Exit = StandardClose
w = NewWindow()
w.DemoAndlabsUiTab("ran AddDemoAndlabsUiTab()")
log.Println("ToolkitDemoWindow() END")
}
// This will create a tab in a window using direct
// calls to andlabs/ui. This can be used to bypass
// the obvuscation added in this package if it is desired