summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2022-11-05 10:19:04 -0500
committerJeff Carr <[email protected]>2022-11-05 10:19:04 -0500
commit099efb6b24caf9eaad50d7386636a7ac23552bde (patch)
tree215685d7153e6d002c921d4f7ad2fa12d52fe323
parenta72d0ab2d0ff58704cc28993ea428b8c6c8825d7 (diff)
v0.4.2 more code cleanups and improvementsv0.4.2
Add command line argv handling using go-arg make hello world dumb stupid simple again more swtiching to common code move debugging options to support go-args more debugging output cleanup more debugging cleanups fix null pointer crash
-rw-r--r--.gitignore3
-rw-r--r--README.md25
-rw-r--r--button.go8
-rw-r--r--cmds/helloworld/main.go50
-rw-r--r--cmds/textbox/Makefile13
-rw-r--r--cmds/textbox/main.go104
-rw-r--r--dropdown.go20
-rw-r--r--main.go4
-rw-r--r--structs.go52
-rw-r--r--text.go4
-rw-r--r--textbox.go25
-rw-r--r--toolkit/andlabs/button.go32
-rw-r--r--toolkit/andlabs/common.go18
-rw-r--r--toolkit/andlabs/dropdown.go4
-rw-r--r--toolkit/andlabs/group.go4
-rw-r--r--toolkit/andlabs/slider.go22
-rw-r--r--toolkit/andlabs/spinner.go14
-rw-r--r--toolkit/andlabs/structs.go6
-rw-r--r--toolkit/andlabs/tab.go20
-rw-r--r--toolkit/andlabs/textbox.go4
-rw-r--r--toolkit/andlabs/window.go18
-rw-r--r--window-debug.go70
22 files changed, 345 insertions, 175 deletions
diff --git a/.gitignore b/.gitignore
index bb8ab57..33b4d57 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
*.swp
-cmds/gui-demo/gui-demo
cmds/helloworld/helloworld
+cmds/textbox/textbox
+cmds/gui-demo/gui-demo
cmds/consolemouse/consolemouse
diff --git a/README.md b/README.md
index e706d4b..50a359b 100644
--- a/README.md
+++ b/README.md
@@ -21,7 +21,7 @@ Principles:
* It's ok to guess. We will return something close.
* Hide complexity internally here
* Isolate the GUI toolkit
-* Function names should follow [[Graphical widget]]
+* Function names should follow [Wikipedia Graphical widget]
```
## Quick Start
@@ -107,12 +107,19 @@ information this uses spew.Dump()
-- manpage quote from the excellent minimalistic window manager 'evilwm'
-## External References
+## References
-Useful links and other external things which might be useful
+Useful links and other
+external things
+which might be useful
-* [Wikipedia Graphical widget](https://en.wikipedia.org/wiki/Graphical_widget)
-* [Github mirror](https://github.com/witorg/gui)
+[Wikipedia Graphical widget]: [https://en.wikipedia.org/wiki/Graphical_widget](https://en.wikipedia.org/wiki/Graphical_widget)
+[Github mirror]: [https://github.com/witorg/gui](https://github.com/witorg/gui)
+
+```go
+* [Wikipedia Graphical widget]
+* [Github mirror]
+```
## Functions
@@ -154,7 +161,7 @@ This creates a window that shows how this package works
`func GolangDebugWindow()`
-### func [IndentPrintln](/structs.go#L191)
+### func [IndentPrintln](/structs.go#L190)
`func IndentPrintln(a ...interface{})`
@@ -187,7 +194,7 @@ For example: gui.Queue(NewWindow())
## Types
-### type [GuiConfig](/structs.go#L43)
+### type [GuiConfig](/structs.go#L42)
`type GuiConfig struct { ... }`
@@ -197,7 +204,7 @@ For example: gui.Queue(NewWindow())
var Config GuiConfig
```
-### type [Node](/structs.go#L98)
+### type [Node](/structs.go#L97)
`type Node struct { ... }`
@@ -255,7 +262,7 @@ func main() {
You get a window
```
-### type [Widget](/structs.go#L68)
+### type [Widget](/structs.go#L67)
`type Widget int`
diff --git a/button.go b/button.go
index 03d1528..1ce7327 100644
--- a/button.go
+++ b/button.go
@@ -13,9 +13,13 @@ func (n *Node) NewButton(name string, custom func()) *Node {
// TODO: this is still confusing and probably wrong. This needs to communicate through a channel
newNode.toolkit.Custom = func() {
- log.Println("gui.AppendButton() Button Clicked. Running custom() from outside toolkit START")
+ if (Config.Options.Debug) {
+ log.Println("gui.AppendButton() Button Clicked. Running custom() from outside toolkit START")
+ }
custom()
- log.Println("gui.AppendButton() Button Clicked. Running custom() from outside toolkit END")
+ if (Config.Options.Debug) {
+ log.Println("gui.AppendButton() Button Clicked. Running custom() from outside toolkit END")
+ }
}
newNode.custom = custom
diff --git a/cmds/helloworld/main.go b/cmds/helloworld/main.go
index bc1ea5a..3ae3b07 100644
--- a/cmds/helloworld/main.go
+++ b/cmds/helloworld/main.go
@@ -8,57 +8,37 @@ import (
)
func main() {
- f, err := os.OpenFile("/tmp/guilogfile", os.O_RDWR | os.O_CREATE | os.O_APPEND, 0666)
- if err != nil {
- log.Fatalf("error opening file: %v", err)
- }
- defer f.Close()
-
- log.SetOutput(f)
- log.Println("This is a test log entry")
-
- gui.Main(initGUI)
+ gui.Main(myGUI)
}
// This initializes the first window
-func initGUI() {
+func myGUI() {
var w *gui.Node
gui.Config.Title = "Hello World golang wit/gui Window"
gui.Config.Width = 640
gui.Config.Height = 480
- gui.Config.Exit = myDefaultExit
+ gui.Config.Exit = myExit
w = gui.NewWindow()
- w.Dump()
- addDemoTab(w, "A Simple Tab Demo")
- addDemoTab(w, "A Second Tab")
+ addHelloWorld(w, "A Simple Tab")
}
-func addDemoTab(window *gui.Node, title string) {
- var newNode, g *gui.Node
+func addHelloWorld(window *gui.Node, title string) {
+ var newNode, g, tb *gui.Node
newNode = window.NewTab(title)
- log.Println("addDemoTab() newNode.Dump")
- log.Println("addDemoTab() newNode.Dump")
- log.Println("addDemoTab() newNode.Dump")
- log.Println("addDemoTab() newNode.Dump")
- newNode.Dump()
- g = newNode.NewGroup("group 1")
- log.Println("addDemoTab() g.Dump")
- log.Println("addDemoTab() g.Dump")
- log.Println("addDemoTab() g.Dump")
- log.Println("addDemoTab() g.Dump")
- g.Dump()
- // os.Exit(0)
- dd := g.NewDropdown("demoCombo2")
- dd.AddDropdown("more 1")
- dd.AddDropdown("more 2")
- dd.AddDropdown("more 3")
+ g = newNode.NewGroup("hello")
+ tb = g.NewTextbox("hello world box") // when debugging, this string will be used
+ tb.OnChanged = func(*gui.Node) {
+ s := tb.GetText()
+ log.Println("text box =", s)
+ }
+ tb.SetText("world")
}
-func myDefaultExit(n *gui.Node) {
- log.Println("You can Do exit() things here")
+func myExit(n *gui.Node) {
+ log.Println("exit() here")
os.Exit(0)
}
diff --git a/cmds/textbox/Makefile b/cmds/textbox/Makefile
new file mode 100644
index 0000000..de22345
--- /dev/null
+++ b/cmds/textbox/Makefile
@@ -0,0 +1,13 @@
+run: build
+ ./textbox --guidebug
+
+build-release:
+ go get -v -u -x .
+ go build
+
+build:
+ GO111MODULE="off" go get -v -x .
+ GO111MODULE="off" go build
+
+update:
+ GO111MODULE="off" go get -v -u -x .
diff --git a/cmds/textbox/main.go b/cmds/textbox/main.go
new file mode 100644
index 0000000..faf8b86
--- /dev/null
+++ b/cmds/textbox/main.go
@@ -0,0 +1,104 @@
+// This creates a simple hello world window
+package main
+
+import (
+ "os"
+ "log"
+ "fmt"
+ "git.wit.org/wit/gui"
+ arg "github.com/alexflint/go-arg"
+)
+
+type LogOptions struct {
+ LogFile string
+ Verbose bool
+ GuiDebug bool `help:"open up the wit/gui Debugging Window"`
+ GuiDemo bool `help:"open the wit/gui Demo Window"`
+ User string `arg:"env:USER"`
+}
+
+var args struct {
+ Foo string
+ Bar bool
+ LogOptions
+ gui.GuiOptions
+}
+
+
+func main() {
+ arg.MustParse(&args)
+ fmt.Println(args.Foo, args.Bar, args.User)
+
+ gui.Config.Options.Debug = args.Debug
+ gui.Config.Options.DebugChange = args.DebugChange
+ gui.Config.Options.DebugDump = args.DebugDump
+ gui.Config.Options.DebugNode = args.DebugNode
+ gui.Config.Options.DebugTabs = args.DebugTabs
+
+ /*
+ f, err := os.OpenFile("/tmp/guilogfile", os.O_RDWR | os.O_CREATE | os.O_APPEND, 0666)
+ if err != nil {
+ log.Fatalf("error opening file: %v", err)
+ }
+ defer f.Close()
+
+ log.SetOutput(f)
+ log.Println("This is a test log entry")
+ */
+
+ gui.Main(initGUI)
+}
+
+// This initializes the first window
+func initGUI() {
+ var w *gui.Node
+ gui.Config.Title = "Hello World golang wit/gui Window"
+ gui.Config.Width = 640
+ gui.Config.Height = 480
+ gui.Config.Exit = myDefaultExit
+
+ w = gui.NewWindow()
+ w.Dump()
+ addDemoTab(w, "A Simple Tab Demo")
+ addDemoTab(w, "A Second Tab")
+
+ if (args.GuiDemo) {
+ gui.DemoToolkitWindow()
+ }
+
+ if (args.GuiDebug) {
+ gui.DebugWindow()
+ }
+}
+
+func addDemoTab(window *gui.Node, title string) {
+ var newNode, g, g2, tb *gui.Node
+
+ newNode = window.NewTab(title)
+ log.Println("addDemoTab() newNode.Dump")
+ newNode.Dump()
+
+ g = newNode.NewGroup("group 1")
+ dd := g.NewDropdown("demoCombo2")
+ dd.AddDropdown("more 1")
+ dd.AddDropdown("more 2")
+ dd.AddDropdown("more 3")
+ dd.OnChanged = func(*gui.Node) {
+ s := dd.GetText()
+ tb.SetText("hello world " + args.User + "\n" + s)
+ }
+
+ g2 = newNode.NewGroup("group 2")
+ tb = g2.NewTextbox("tb")
+ log.Println("tb =", tb.GetText())
+ tb.OnChanged = func(*gui.Node) {
+ s := tb.GetText()
+ log.Println("text =", s)
+ }
+}
+
+func myDefaultExit(n *gui.Node) {
+ log.Println("You can Do exit() things here")
+ os.Exit(0)
+}
+
diff --git a/dropdown.go b/dropdown.go
index de59fac..583ea25 100644
--- a/dropdown.go
+++ b/dropdown.go
@@ -7,16 +7,24 @@ import toolkit "git.wit.org/wit/gui/toolkit/andlabs"
func commonCallback(n *Node) {
// TODO: make all of this common code to all the widgets
if (n.OnChanged == nil) {
- log.Println("Not Running n.OnChanged(n) == nil")
+ if (Config.Options.DebugChange) {
+ log.Println("Not Running n.OnChanged(n) == nil")
+ }
} else {
- log.Println("Running n.OnChanged(n)")
+ if (Config.Options.DebugChange) {
+ log.Println("Running n.OnChanged(n)")
+ }
n.OnChanged(n)
}
if (n.custom == nil) {
- log.Println("Not Running n.custom(n) == nil")
+ if (Config.Options.DebugChange) {
+ log.Println("Not Running n.custom(n) == nil")
+ }
} else {
- log.Println("Running n.custom()")
+ if (Config.Options.DebugChange) {
+ log.Println("Running n.custom()")
+ }
n.custom()
}
}
@@ -25,7 +33,9 @@ func (n *Node) NewDropdown(name string) *Node {
var newT *toolkit.Toolkit
var sNode *Node
- log.Println("toolkit.NewDropdown() START", name)
+ if (Config.Options.Debug) {
+ log.Println("toolkit.NewDropdown() START", name)
+ }
n.verify()
diff --git a/main.go b/main.go
index 91a42d4..e87f6c2 100644
--- a/main.go
+++ b/main.go
@@ -17,8 +17,8 @@ func init() {
Config.counter = 0
Config.prefix = "wit"
- Config.DebugNode = false
- Config.DebugTabs = false
+ Config.Options.DebugNode = false
+ Config.Options.DebugTabs = false
title := "master"
w := 640
diff --git a/structs.go b/structs.go
index 4b4fa33..e72e28a 100644
--- a/structs.go
+++ b/structs.go
@@ -30,16 +30,29 @@ func GetDebugToolkit () bool {
}
func ShowDebugValues() {
- log.Println("\t wit/gui Debug =", Config.Debug)
- log.Println("\t wit/gui DebugDump =", Config.DebugDump)
- log.Println("\t wit/gui DebugNode =", Config.DebugNode)
- log.Println("\t wit/gui DebugTabs =", Config.DebugTabs)
- log.Println("\t wit/gui DebugTable =", Config.DebugTable)
- log.Println("\t wit/gui DebugWindow =", Config.DebugWindow)
- log.Println("\t wit/gui DebugWindow =", Config.DebugWindow)
+ log.Println("\t wit/gui Debug =", Config.Options.Debug)
+ log.Println("\t wit/gui DebugDump =", Config.Options.DebugDump)
+ log.Println("\t wit/gui DebugNode =", Config.Options.DebugNode)
+ log.Println("\t wit/gui DebugTabs =", Config.Options.DebugTabs)
+// log.Println("\t wit/gui DebugTable =", Config.Options.DebugTable)
+// log.Println("\t wit/gui DebugWindow =", Config.Options.DebugWindow)
+ log.Println("\t wit/gui DebugChange =", Config.Options.DebugChange)
+
log.Println("\t wit/gui DebugToolkit =", toolkit.DebugToolkit)
}
+type GuiOptions struct {
+ // These are global debugging settings
+ // TODO: move to a standard logging system
+ Debug bool
+ DebugDump bool
+ DebugNode bool
+ DebugTabs bool
+// DebugTable bool
+// DebugWindow bool
+ DebugChange bool `help:"debug mouse clicks and keyboard input"`
+}
+
type GuiConfig struct {
// This is the master node. The Binary Tree starts here
master *Node
@@ -50,14 +63,7 @@ type GuiConfig struct {
Height int
Exit func(*Node)
- // These are global debugging settings
- // TODO: move to a standard logging system
- Debug bool
- DebugDump bool
- DebugNode bool
- DebugTabs bool
- DebugTable bool
- DebugWindow bool
+ Options GuiOptions
// hacks
depth int
@@ -124,7 +130,7 @@ func (n *Node) Window() *Node {
}
func (n *Node) Dump() {
- if ! Config.DebugDump {
+ if ! Config.Options.DebugDump {
return
}
IndentPrintln("NODE DUMP START")
@@ -162,14 +168,16 @@ func (n *Node) Dump() {
IndentPrintln("NODE DUMP END")
}
+/*
func (n *Node) SetName(name string) {
n.toolkit.SetWindowTitle(name)
return
}
+*/
func (n *Node) Append(child *Node) {
n.children = append(n.children, child)
- if (Config.Debug) {
+ if (Config.Options.Debug) {
log.Println("child node:")
child.Dump()
log.Println("parent node:")
@@ -212,11 +220,11 @@ func (n *Node) ListChildren(dump bool) {
if len(n.children) == 0 {
if (n.parent == nil) {
} else {
- if (Config.DebugNode) {
+ if (Config.Options.DebugNode) {
log.Println("\t\t\tparent =",n.parent.id)
}
if (listChildrenParent != nil) {
- if (Config.DebugNode) {
+ if (Config.Options.DebugNode) {
log.Println("\t\t\tlistChildrenParent =",listChildrenParent.id)
}
if (listChildrenParent.id != n.parent.id) {
@@ -225,7 +233,7 @@ func (n *Node) ListChildren(dump bool) {
}
}
}
- if (Config.DebugNode) {
+ if (Config.Options.DebugNode) {
log.Println("\t\t", n.id, "has no children")
}
return
@@ -233,7 +241,7 @@ func (n *Node) ListChildren(dump bool) {
for _, child := range n.children {
// log.Println("\t\t", child.id, child.Width, child.Height, child.Name)
if (child.parent != nil) {
- if (Config.DebugNode) {
+ if (Config.Options.DebugNode) {
log.Println("\t\t\tparent =",child.parent.id)
}
} else {
@@ -243,7 +251,7 @@ func (n *Node) ListChildren(dump bool) {
if (dump == true) {
child.Dump()
}
- if (Config.DebugNode) {
+ if (Config.Options.DebugNode) {
if (child.children == nil) {
log.Println("\t\t", child.id, "has no children")
} else {
diff --git a/text.go b/text.go
index 169f3ec..9603bff 100644
--- a/text.go
+++ b/text.go
@@ -18,7 +18,9 @@ func (n *Node) NewLabel(text string) *Node {
}
func (n *Node) SetText(str string) bool {
- log.Println("gui.SetText() value =", str)
+ if (Config.Options.DebugChange) {
+ log.Println("gui.SetText() value =", str)
+ }
if (n.toolkit == nil) {
return false
}
diff --git a/textbox.go b/textbox.go
index e3b4201..94f0d9e 100644
--- a/textbox.go
+++ b/textbox.go
@@ -22,13 +22,26 @@ func (n *Node) NewTextbox(name string) *Node {
newt.Name = name
// newt.Custom = func () {
newt.OnChanged = func (*toolkit.Toolkit) {
- println("AM IN CALLBACK. SETTING NODE.checked START")
+ if (Config.Options.DebugChange) {
+ log.Println("AM IN CALLBACK. SETTING NODE.checked START")
+ c.Dump()
+ c.toolkit.Dump()
+ }
c.text = c.toolkit.GetText()
- c.Dump()
- c.toolkit.Dump()
- c.OnChanged(n)
- println("n.toolkit.GetText() =", c.text)
- println("AM IN CALLBACK. SETTING NODE.checked END")
+ if (c.OnChanged == nil) {
+ if (Config.Options.DebugChange) {
+ log.Println("this is println?")
+ }
+ } else {
+ if (Config.Options.DebugChange) {
+ log.Println("this is println? running c.OnChanged() here")
+ }
+ c.OnChanged(n)
+ }
+ if (Config.Options.DebugChange) {
+ log.Println("n.toolkit.GetText() =", c.text)
+ log.Println("AM IN CALLBACK. SETTING NODE.checked END")
+ }
}
return c
diff --git a/toolkit/andlabs/button.go b/toolkit/andlabs/button.go
index 07b33aa..4e6ff52 100644
--- a/toolkit/andlabs/button.go
+++ b/toolkit/andlabs/button.go
@@ -18,7 +18,9 @@ func (t Toolkit) NewButton(name string) *Toolkit {
return nil
}
- log.Println("gui.Toolbox.NewGroup() create", name)
+ if (DebugToolkit) {
+ log.Println("gui.Toolbox.NewGroup() create", name)
+ }
b = ui.NewButton(name)
newt.uiButton = b
@@ -26,20 +28,34 @@ func (t Toolkit) NewButton(name string) *Toolkit {
log.Println("TODO: IN TOOLKIT GOROUTINE. SHOULD LEAVE HERE VIA channels. button name =", name)
t.Dump()
newt.Dump()
- log.Println("wit/gui/toolkit NewButton() Should do something here")
+ if (DebugToolkit) {
+ log.Println("wit/gui/toolkit NewButton() Should do something here")
+ }
if (newt.Custom == nil) {
- log.Println("wit/gui/toolkit NewButton() toolkit.Custom == nil")
+ if (DebugToolkit) {
+ log.Println("wit/gui/toolkit NewButton() toolkit.Custom == nil")
+ }
} else {
- log.Println("wit/gui/toolkit NewButton() toolkit.Custom() START")
+ if (DebugToolkit) {
+ log.Println("wit/gui/toolkit NewButton() toolkit.Custom() START")
+ }
newt.Custom()
- log.Println("wit/gui/toolkit NewButton() toolkit.Custom() END")
+ if (DebugToolkit) {
+ log.Println("wit/gui/toolkit NewButton() toolkit.Custom() END")
+ }
}
if (t.Custom == nil) {
- log.Println("wit/gui/toolkit NewButton() parent toolkit.Custom == nil")
+ if (DebugToolkit) {
+ log.Println("wit/gui/toolkit NewButton() parent toolkit.Custom == nil")
+ }
} else {
- log.Println("wit/gui/toolkit NewButton() running parent toolkit.Custom() START (IS THIS A BAD IDEA?)")
+ if (DebugToolkit) {
+ log.Println("wit/gui/toolkit NewButton() running parent toolkit.Custom() START (IS THIS A BAD IDEA?)")
+ }
t.Custom()
- log.Println("wit/gui/toolkit NewButton() running parent toolkit.Custom() END (IS THIS A BAD IDEA?)")
+ if (DebugToolkit) {
+ log.Println("wit/gui/toolkit NewButton() running parent toolkit.Custom() END (IS THIS A BAD IDEA?)")
+ }
}
log.Println("TODO: LEFT TOOLKIT GOROUTINE button name =", name)
})
diff --git a/toolkit/andlabs/common.go b/toolkit/andlabs/common.go
index 75f7444..569621d 100644
--- a/toolkit/andlabs/common.go
+++ b/toolkit/andlabs/common.go
@@ -12,30 +12,38 @@ func init() {
func (t Toolkit) commonChange(widget string) {
s := t.String()
- log.Println("gui.Toolkit.ui.OnChanged() =", s)
if (DebugToolkit) {
log.Println("gui.Toolkit.ui.OnChanged() =", s)
}
if (t.OnChanged != nil) {
- log.Println("gui.Toolkit.OnChanged() trying to run toolkit.OnChanged() entered val =", s)
+ if (DebugToolkit) {
+ log.Println("gui.Toolkit.OnChanged() trying to run toolkit.OnChanged() entered val =", s)
+ }
t.OnChanged(&t)
return
}
if (t.Custom != nil) {
- log.Println("gui.Toolkit.OnChanged() Running toolkit.Custom()")
- t.Dump()
+ if (DebugToolkit) {
+ log.Println("gui.Toolkit.OnChanged() Running toolkit.Custom()")
+ t.Dump()
+ }
t.Custom()
return
}
- log.Println("gui.Toolkit.OnChanged() ENDED without finding any callback")
+ if (DebugToolkit) {
+ log.Println("gui.Toolkit.OnChanged() ENDED without finding any callback")
+ }
}
+// does some sanity checks on the internal structs of the binary tree
+// TODO: probably this should not panic unless it's running in devel mode (?)
func (t Toolkit) broken() bool {
if (t.uiBox == nil) {
log.Println("gui.Toolkit.UiBox == nil. I can't add a widget without a place to put it")
// log.Println("probably could just make a box here?")
// corruption or something horrible?
panic("wit/gui toolkit/andlabs func broken() invalid goroutine access into this toolkit?")
+ panic("wit/gui toolkit/andlabs func broken() this probably should not cause the app to panic here (?)")
return true
}
if (t.uiWindow == nil) {
diff --git a/toolkit/andlabs/dropdown.go b/toolkit/andlabs/dropdown.go
index 51d618d..ca09a99 100644
--- a/toolkit/andlabs/dropdown.go
+++ b/toolkit/andlabs/dropdown.go
@@ -9,7 +9,9 @@ import _ "github.com/andlabs/ui/winmanifest"
func (t *Toolkit) NewDropdown(title string) *Toolkit {
// make new node here
- log.Println("gui.Toolbox.NewDropdownCombobox()")
+ if (DebugToolkit) {
+ log.Println("gui.Toolbox.NewDropdownCombobox()", title)
+ }
var newt Toolkit
if t.broken() {
diff --git a/toolkit/andlabs/group.go b/toolkit/andlabs/group.go
index c42ac0d..f48a78d 100644
--- a/toolkit/andlabs/group.go
+++ b/toolkit/andlabs/group.go
@@ -17,7 +17,9 @@ func (t Toolkit) NewGroup(title string) *Toolkit {
return nil
}
- log.Println("gui.Toolbox.NewGroup() create", title)
+ if (DebugToolkit) {
+ log.Println("gui.Toolbox.NewGroup() create", title)
+ }
g := ui.NewGroup(title)
g.SetMargined(margin)
t.uiBox.Append(g, stretchy)
diff --git a/toolkit/andlabs/slider.go b/toolkit/andlabs/slider.go
index 7d4f42a..ad801f8 100644
--- a/toolkit/andlabs/slider.go
+++ b/toolkit/andlabs/slider.go
@@ -6,9 +6,6 @@ import "os"
import "github.com/andlabs/ui"
import _ "github.com/andlabs/ui/winmanifest"
-import "github.com/davecgh/go-spew/spew"
-
-// func NewSlider(b *ui.Box, name string *Toolkit {
func (t Toolkit) NewSlider(title string, x int, y int) *Toolkit {
// make new node here
log.Println("gui.Toolkit.NewSpinbox()", x, y)
@@ -27,24 +24,7 @@ func (t Toolkit) NewSlider(title string, x int, y int) *Toolkit {
t.uiBox.Append(s, stretchy)
s.OnChanged(func(spin *ui.Slider) {
- i := spin.Value()
- log.Println("gui.Toolkit.ui.Slider.OnChanged() val =", i)
- if (DebugToolkit) {
- log.Println("gui.Toolkit.ui.OnChanged() val =", i)
- scs := spew.ConfigState{MaxDepth: 1}
- scs.Dump(newt)
- }
- if (newt.OnChanged != nil) {
- log.Println("gui.Toolkit.OnChanged() trying to run toolkit.OnChanged() entered val =", i)
- newt.OnChanged(&newt)
- return
- }
- if (newt.Custom != nil) {
- log.Println("gui.Toolkit.OnChanged() Running toolkit.Custom()")
- newt.Custom()
- return
- }
- log.Println("gui.Toolkit.OnChanged() ENDED without finding any callback")
+ newt.commonChange("Slider")
})
return &newt
diff --git a/toolkit/andlabs/spinner.go b/toolkit/andlabs/spinner.go
index f147205..885192c 100644
--- a/toolkit/andlabs/spinner.go
+++ b/toolkit/andlabs/spinner.go
@@ -6,9 +6,6 @@ import "os"
import "github.com/andlabs/ui"
import _ "github.com/andlabs/ui/winmanifest"
-import "github.com/davecgh/go-spew/spew"
-
-// func NewSlider(b *ui.Box, name string *Toolkit {
func (t Toolkit) NewSpinner(title string, x int, y int) *Toolkit {
// make new node here
log.Println("gui.Toolkit.NewSpinner()", x, y)
@@ -26,16 +23,7 @@ func (t Toolkit) NewSpinner(title string, x int, y int) *Toolkit {
t.uiBox.Append(s, stretchy)
s.OnChanged(func(s *ui.Spinbox) {
- i := s.Value()
- if (DebugToolkit) {
- log.Println("gui.Toolkit.ui.OnChanged() val =", i)
- scs := spew.ConfigState{MaxDepth: 1}
- scs.Dump(newt)
- }
- if (t.OnChanged != nil) {
- log.Println("gui.Toolkit.OnChanged() entered val =", i)
- newt.OnChanged(&newt)
- }
+ newt.commonChange("Spinner")
})
return &newt
diff --git a/toolkit/andlabs/structs.go b/toolkit/andlabs/structs.go
index edad27e..90f9409 100644
--- a/toolkit/andlabs/structs.go
+++ b/toolkit/andlabs/structs.go
@@ -93,7 +93,7 @@ func forceDump(t *Toolkit) {
}
func (t *Toolkit) GetText() string {
- forceDump(t)
+ t.Dump()
if (DebugToolkit) {
log.Println("gui.Toolkit.Text() Enter")
scs := spew.ConfigState{MaxDepth: 1}
@@ -110,7 +110,9 @@ func (t *Toolkit) GetText() string {
log.Println("gui.Toolkit.Value() =", t.uiMultilineEntry.Text())
}
text := t.uiMultilineEntry.Text()
- log.Println("gui.Toolkit.Value() text =", text)
+ if (DebugToolkit) {
+ log.Println("gui.Toolkit.Value() text =", text)
+ }
t.text = text
return text
}
diff --git a/toolkit/andlabs/tab.go b/toolkit/andlabs/tab.go
index a0565c0..c641fc0 100644
--- a/toolkit/andlabs/tab.go
+++ b/toolkit/andlabs/tab.go
@@ -61,14 +61,18 @@ func (t *Toolkit) AddTab(name string) *Toolkit {
func tabSetMargined(tab *ui.Tab) {
c := tab.NumPages()
for i := 0; i < c; i++ {
- log.Println("SetMargined", i, margin)
+ if (DebugToolkit) {
+ log.Println("SetMargined", i, margin)
+ }
tab.SetMargined(i, margin)
}
}
func newTab(w *ui.Window, name string) *Toolkit {
- log.Println("gui.toolkit.NewTab() ADD", name)
var t Toolkit
+ if (DebugToolkit) {
+ log.Println("gui.toolkit.NewTab() ADD", name)
+ }
if (w == nil) {
log.Println("gui.toolkit.NewTab() node.UiWindow == nil. I can't add a tab without a window")
@@ -77,7 +81,9 @@ func newTab(w *ui.Window, name string) *Toolkit {
time.Sleep(1 * time.Second)
return nil
}
- log.Println("gui.toolkit.AddTab() START name =", name)
+ if (DebugToolkit) {
+ log.Println("gui.toolkit.AddTab() START name =", name)
+ }
tab := ui.NewTab()
w.SetMargined(margin)
@@ -94,14 +100,18 @@ func newTab(w *ui.Window, name string) *Toolkit {
}
func (t *Toolkit) appendTab(name string) *Toolkit {
- log.Println("gui.toolkit.NewTab() ADD", name)
var newT Toolkit
+ if (DebugToolkit) {
+ log.Println("gui.toolkit.NewTab() ADD", name)
+ }
if (t.uiTab == nil) {
log.Println("gui.Toolkit.UiWindow == nil. I can't add a widget without a place to put it")
panic("should never have happened. wit/gui/toolkit has ui.Tab == nil")
}
- log.Println("gui.toolkit.AddTab() START name =", name)
+ if (DebugToolkit) {
+ log.Println("gui.toolkit.AddTab() START name =", name)
+ }
var hbox *ui.Box
if (defaultBehavior) {
diff --git a/toolkit/andlabs/textbox.go b/toolkit/andlabs/textbox.go
index 95bfbaa..44946b8 100644
--- a/toolkit/andlabs/textbox.go
+++ b/toolkit/andlabs/textbox.go
@@ -6,7 +6,9 @@ import "github.com/andlabs/ui"
import _ "github.com/andlabs/ui/winmanifest"
func (t Toolkit) NewTextbox(name string) *Toolkit {
- log.Println("gui.Toolkit.NewTextbox()", name)
+ if (DebugToolkit) {
+ log.Println("gui.Toolkit.NewTextbox()", name)
+ }
var newt Toolkit
if t.broken() {
diff --git a/toolkit/andlabs/window.go b/toolkit/andlabs/window.go
index 2aef431..3e5f16a 100644
--- a/toolkit/andlabs/window.go
+++ b/toolkit/andlabs/window.go
@@ -22,17 +22,25 @@ func NewWindow(title string, x int, y int) *Toolkit {
w.SetBorderless(canvas)
w.SetMargined(margin)
w.OnClosing(func(*ui.Window) bool {
- log.Println("ui.Window().OnExit() SHOULD ATTEMPT CALLBACK here")
- t.Dump()
+ if (DebugToolkit) {
+ log.Println("ui.Window().OnExit() SHOULD ATTEMPT CALLBACK here")
+ t.Dump()
+ }
if (t.OnExit != nil) {
- log.Println("ui.Window().OnExit() ATTEMPTING toolkit.OnExit CALLBACK")
+ if (DebugToolkit) {
+ log.Println("ui.Window().OnExit() ATTEMPTING toolkit.OnExit CALLBACK")
+ }
t.OnExit(&t)
}
if (t.Custom != nil) {
- log.Println("ui.Window().Custom() ATTEMPTING toolkit.Custom CALLBACK")
+ if (DebugToolkit) {
+ log.Println("ui.Window().Custom() ATTEMPTING toolkit.Custom CALLBACK")
+ }
t.Custom()
}
- log.Println("ui.Window().OnExit() Toolkit.OnExit is nil")
+ if (DebugToolkit) {
+ log.Println("ui.Window().OnExit() Toolkit.OnExit is nil")
+ }
return true
})
w.Show()
diff --git a/window-debug.go b/window-debug.go
index 462588e..00ccfec 100644
--- a/window-debug.go
+++ b/window-debug.go
@@ -33,51 +33,58 @@ func DebugTab() {
var checkd, checkdn, checkdt, checkdtk *Node
-func (n *Node) DebugTab(title string) *Node {
- var newN, gog, g1, g2, g3, dd, gf *Node
-
- // time.Sleep(1 * time.Second)
- newN = n.NewTab(title)
- newN.Dump()
+//////////////////////// debug flags //////////////////////////////////
+func debugFlags(n *Node) {
+ var df, checkd, checkdn, checkdd, changeCheckbox *Node
+ df = n.NewGroup("Debug Flags")
+ df.NewLabel("flags to control debugging output")
- gog = newN.NewGroup("GOLANG")
- gog.NewLabel("go language")
- gog.NewButton("GO Language Debug", func () {
- GolangDebugWindow()
- })
-
- gf = newN.NewGroup("Debug Flags")
- gf.NewLabel("flags to control debugging output")
-
- checkd = gf.NewCheckbox("Debug")
+ checkd = df.NewCheckbox("Debug")
checkd.OnChanged = func(*Node) {
checkd.checked = checkd.toolkit.Checked()
- Config.Debug = checkd.checked
- if (Config.Debug) {
+ Config.Options.Debug = checkd.checked
+ if (Config.Options.Debug) {
+ log.Println("Debug turned on")
} else {
+ log.Println("Debug turned off")
}
}
- checkdn = gf.NewCheckbox("Debug Node")
+ checkdn = df.NewCheckbox("Debug Node")
checkdn.OnChanged = func(*Node) {
checkdn.checked = checkdn.toolkit.Checked()
- Config.DebugNode = checkdn.checked
+ Config.Options.DebugNode = checkdn.checked
}
- checkdd := gf.NewCheckbox("Debug node.Dump()")
+ checkdd = df.NewCheckbox("Debug node.Dump()")
checkdd.OnChanged = func(*Node) {
- Config.DebugDump = checkdd.toolkit.Checked()
+ Config.Options.DebugDump = checkdd.toolkit.Checked()
}
- checkdt = gf.NewCheckbox("Debug Tabs")
- checkdtk = gf.NewCheckbox("Debug Toolkit")
+ changeCheckbox = df.NewCheckbox("Debug Change")
+ changeCheckbox.OnChanged = func(*Node) {
+ Config.Options.DebugChange = changeCheckbox.toolkit.Checked()
+ }
-// Debug bool
-// DebugNode bool
-// DebugTabs bool
-// DebugTable bool
-// DebugWindow bool
-// DebugToolkit bool
+ df.NewButton("Dump Debug Flags", func () {
+ ShowDebugValues()
+ })
+
+}
+
+func (n *Node) DebugTab(title string) *Node {
+ var newN, gog, g1, g2, g3, dd *Node
+
+ // time.Sleep(1 * time.Second)
+ newN = n.NewTab(title)
+ newN.Dump()
+
+//////////////////////// main debug things //////////////////////////////////
+ gog = newN.NewGroup("GOLANG")
+ gog.NewLabel("go language")
+ gog.NewButton("GO Language Debug", func () {
+ GolangDebugWindow()
+ })
gog.NewLabel("wit/gui package")
gog.NewButton("WIT/GUI Package Debug", func () {
@@ -92,6 +99,9 @@ func (n *Node) DebugTab(title string) *Node {
DemoToolkitWindow()
})
+ debugFlags(newN)
+
+//////////////////////// window debugging things //////////////////////////////////
g1 = newN.NewGroup("Current Windows")
dd = g1.NewDropdown("Window Dropdown")
log.Println("dd =", dd)