NODE: almost out of the rabbit hole

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2021-10-28 04:10:48 -05:00
parent 2c470f86c9
commit 6a477695ef
9 changed files with 99 additions and 4 deletions

3
.gitignore vendored
View File

@ -1,2 +1,3 @@
*.swp
gui-example/gui-example
cmds/gui-example/gui-example
cmds/gui-demo/gui-demo

5
cmds/gui-demo/Makefile Normal file
View File

@ -0,0 +1,5 @@
run: build
./gui-demo
build:
GO111MODULE="off" go build

View File

@ -0,0 +1,17 @@
package main
import "git.wit.org/wit/gui"
func addDemoTab(n *gui.Node, title string) {
newNode := n.AddTab(title, nil)
if (gui.Config.Debug) {
newNode.Dump()
}
newNode.ListChildren(false)
groupNode1 := newNode.AddGroup("group 1")
groupNode1.AddComboBox("demoCombo1", "foo", "bar", "stuff")
groupNode2 := newNode.AddGroup("group 2")
groupNode2.AddComboBox("demoCombo2", "more 1", "more 2", "more 3")
}

68
cmds/gui-demo/main.go Normal file
View File

@ -0,0 +1,68 @@
package main
import (
"log"
"os"
"time"
"git.wit.org/wit/gui"
)
// This initializes the first window
//
// Then starts a goroutine to demonstrate how to
// inject things into the GUI
func main() {
log.Println("Starting my Control Panel")
go gui.Main(initGUI)
watchGUI()
}
// This initializes the first window
func initGUI() {
gui.Config.Title = "WIT GUI Window Demo 1"
gui.Config.Width = 640
gui.Config.Height = 480
gui.Config.Exit = myExit
node1 := gui.NewWindow()
addDemoTab(node1, "A Simple Tab Demo")
gui.Config.Title = "WIT GUI Window Demo 2"
gui.Config.Width = 640
gui.Config.Height = 240
gui.Config.Exit = myExit
node2 := gui.NewWindow()
node2.AddDemoAndlabsUiTab("A Simple andlabs/ui Tab Demo")
}
// This demonstrates how to properly interact with the GUI
// You can not involke the GUI from external goroutines in most cases.
func watchGUI() {
var i = 1
for {
log.Println("Waiting", i, "seconds")
i += 1
time.Sleep(1 * time.Second)
if i == 4 {
log.Println("Opening a Debug Window via the gui.Queue()")
gui.Config.Width = 800
gui.Config.Height = 300
gui.Config.Exit = myDebugExit
gui.Queue(gui.DebugWindow)
}
}
}
func myExit(n *gui.Node) {
log.Println()
log.Println("Entered myExit() on node.Name =", n.Name)
log.Println()
os.Exit(0)
}
func myDebugExit(n *gui.Node) {
log.Println("Entered myDebugExit() on node.Name =", n.Name)
log.Println("Don't actually os.Exit()")
}

View File

@ -238,6 +238,7 @@ func makeWindowDebug() *ui.Box {
}
})
/*
n1 = addButton(vbox, "Node.DemoTab")
n1.OnClicked(func(*ui.Button) {
y := nodeCombo.Selected()
@ -248,6 +249,7 @@ func makeWindowDebug() *ui.Box {
node.AddDemoTab("ran gui.AddDemoTab() " + strconv.Itoa(Config.counter))
}
})
*/
n1 = addButton(vbox, "Node.DemoAndlabsUiTab")
n1.OnClicked(func(*ui.Button) {

View File

@ -6,6 +6,7 @@ import _ "github.com/andlabs/ui/winmanifest"
var mybox *ui.Box
/*
func (n *Node) AddDemoTab(title string) {
newNode := n.AddTab(title, makeDemoTab())
if (Config.DebugNode) {
@ -16,7 +17,7 @@ func (n *Node) AddDemoTab(title string) {
newNode.ListChildren(false)
addDemoGroup(newNode, "new group 1")
addDemoGroup(newNode, "new group 2")
groupNode := newNode.AddGroup("new group 3")
groupNode.AddComboBox("testing", "foo", "man", "blah")
}
@ -75,6 +76,7 @@ func addDemoGroup(n *Node, title string) {
vbox.Append(ecbox, false)
}
*/
func (n *Node) AddGroup(title string) *Node {
hbox := n.uiBox
@ -94,7 +96,7 @@ func (n *Node) AddGroup(title string) *Node {
return newNode
}
func (n *Node) GetText(title string) string {
func (n *Node) GetText(name string) string {
if (n.uiText != nil) {
return n.uiText.Text()
}

View File

@ -240,12 +240,12 @@ func (parent *Node) AddTab(title string, uiC *ui.Box) *Node {
uiC = hbox
}
tab.Append(title, uiC)
tab.SetMargined(0, true)
// panic("gui.AddTab() before makeNode()")
newNode := parent.makeNode(title, 555, 600 + Config.counter)
newNode.uiTab = tab
newNode.uiBox = uiC
// panic("gui.AddTab() after makeNode()")
tabSetMargined(newNode.uiTab)
return newNode
}