v0.4.2 more code cleanups and improvements

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
This commit is contained in:
Jeff Carr 2022-11-05 10:19:04 -05:00
parent f48d3fbcfe
commit 5417c8f477
22 changed files with 349 additions and 179 deletions

3
.gitignore vendored
View File

@ -1,4 +1,5 @@
*.swp *.swp
cmds/gui-demo/gui-demo
cmds/helloworld/helloworld cmds/helloworld/helloworld
cmds/textbox/textbox
cmds/gui-demo/gui-demo
cmds/consolemouse/consolemouse cmds/consolemouse/consolemouse

View File

@ -21,7 +21,7 @@ Principles:
* It's ok to guess. We will return something close. * It's ok to guess. We will return something close.
* Hide complexity internally here * Hide complexity internally here
* Isolate the GUI toolkit * Isolate the GUI toolkit
* Function names should follow [[Graphical widget]] * Function names should follow [Wikipedia Graphical widget]
``` ```
## Quick Start ## Quick Start
@ -107,12 +107,19 @@ information this uses spew.Dump()
-- manpage quote from the excellent minimalistic window manager 'evilwm' -- 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) [Wikipedia Graphical widget]: [https://en.wikipedia.org/wiki/Graphical_widget](https://en.wikipedia.org/wiki/Graphical_widget)
* [Github mirror](https://github.com/witorg/gui) [Github mirror]: [https://github.com/witorg/gui](https://github.com/witorg/gui)
```go
* [Wikipedia Graphical widget]
* [Github mirror]
```
## Functions ## Functions
@ -154,7 +161,7 @@ This creates a window that shows how this package works
`func GolangDebugWindow()` `func GolangDebugWindow()`
### func [IndentPrintln](/structs.go#L191) ### func [IndentPrintln](/structs.go#L190)
`func IndentPrintln(a ...interface{})` `func IndentPrintln(a ...interface{})`
@ -187,7 +194,7 @@ For example: gui.Queue(NewWindow())
## Types ## Types
### type [GuiConfig](/structs.go#L43) ### type [GuiConfig](/structs.go#L42)
`type GuiConfig struct { ... }` `type GuiConfig struct { ... }`
@ -197,7 +204,7 @@ For example: gui.Queue(NewWindow())
var Config GuiConfig var Config GuiConfig
``` ```
### type [Node](/structs.go#L98) ### type [Node](/structs.go#L97)
`type Node struct { ... }` `type Node struct { ... }`
@ -255,7 +262,7 @@ func main() {
You get a window You get a window
``` ```
### type [Widget](/structs.go#L68) ### type [Widget](/structs.go#L67)
`type Widget int` `type Widget int`

View File

@ -13,10 +13,14 @@ func (n *Node) NewButton(name string, custom func()) *Node {
// TODO: this is still confusing and probably wrong. This needs to communicate through a channel // TODO: this is still confusing and probably wrong. This needs to communicate through a channel
newNode.toolkit.Custom = func() { newNode.toolkit.Custom = func() {
if (Config.Options.Debug) {
log.Println("gui.AppendButton() Button Clicked. Running custom() from outside toolkit START") log.Println("gui.AppendButton() Button Clicked. Running custom() from outside toolkit START")
}
custom() custom()
if (Config.Options.Debug) {
log.Println("gui.AppendButton() Button Clicked. Running custom() from outside toolkit END") log.Println("gui.AppendButton() Button Clicked. Running custom() from outside toolkit END")
} }
}
newNode.custom = custom newNode.custom = custom
return newNode return newNode

View File

@ -8,57 +8,37 @@ import (
) )
func main() { func main() {
f, err := os.OpenFile("/tmp/guilogfile", os.O_RDWR | os.O_CREATE | os.O_APPEND, 0666) gui.Main(myGUI)
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 // This initializes the first window
func initGUI() { func myGUI() {
var w *gui.Node var w *gui.Node
gui.Config.Title = "Hello World golang wit/gui Window" gui.Config.Title = "Hello World golang wit/gui Window"
gui.Config.Width = 640 gui.Config.Width = 640
gui.Config.Height = 480 gui.Config.Height = 480
gui.Config.Exit = myDefaultExit gui.Config.Exit = myExit
w = gui.NewWindow() w = gui.NewWindow()
w.Dump() addHelloWorld(w, "A Simple Tab")
addDemoTab(w, "A Simple Tab Demo")
addDemoTab(w, "A Second Tab")
} }
func addDemoTab(window *gui.Node, title string) { func addHelloWorld(window *gui.Node, title string) {
var newNode, g *gui.Node var newNode, g, tb *gui.Node
newNode = window.NewTab(title) 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") g = newNode.NewGroup("hello")
log.Println("addDemoTab() g.Dump") tb = g.NewTextbox("hello world box") // when debugging, this string will be used
log.Println("addDemoTab() g.Dump") tb.OnChanged = func(*gui.Node) {
log.Println("addDemoTab() g.Dump") s := tb.GetText()
log.Println("addDemoTab() g.Dump") log.Println("text box =", s)
g.Dump() }
// os.Exit(0) tb.SetText("world")
dd := g.NewDropdown("demoCombo2")
dd.AddDropdown("more 1")
dd.AddDropdown("more 2")
dd.AddDropdown("more 3")
} }
func myDefaultExit(n *gui.Node) { func myExit(n *gui.Node) {
log.Println("You can Do exit() things here") log.Println("exit() here")
os.Exit(0) os.Exit(0)
} }

13
cmds/textbox/Makefile Normal file
View File

@ -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 .

104
cmds/textbox/main.go Normal file
View File

@ -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)
}

View File

@ -7,16 +7,24 @@ import toolkit "git.wit.org/wit/gui/toolkit/andlabs"
func commonCallback(n *Node) { func commonCallback(n *Node) {
// TODO: make all of this common code to all the widgets // TODO: make all of this common code to all the widgets
if (n.OnChanged == nil) { if (n.OnChanged == nil) {
if (Config.Options.DebugChange) {
log.Println("Not Running n.OnChanged(n) == nil") log.Println("Not Running n.OnChanged(n) == nil")
}
} else { } else {
if (Config.Options.DebugChange) {
log.Println("Running n.OnChanged(n)") log.Println("Running n.OnChanged(n)")
}
n.OnChanged(n) n.OnChanged(n)
} }
if (n.custom == nil) { if (n.custom == nil) {
if (Config.Options.DebugChange) {
log.Println("Not Running n.custom(n) == nil") log.Println("Not Running n.custom(n) == nil")
}
} else { } else {
if (Config.Options.DebugChange) {
log.Println("Running n.custom()") log.Println("Running n.custom()")
}
n.custom() n.custom()
} }
} }
@ -25,7 +33,9 @@ func (n *Node) NewDropdown(name string) *Node {
var newT *toolkit.Toolkit var newT *toolkit.Toolkit
var sNode *Node var sNode *Node
if (Config.Options.Debug) {
log.Println("toolkit.NewDropdown() START", name) log.Println("toolkit.NewDropdown() START", name)
}
n.verify() n.verify()

View File

@ -17,8 +17,8 @@ func init() {
Config.counter = 0 Config.counter = 0
Config.prefix = "wit" Config.prefix = "wit"
Config.DebugNode = false Config.Options.DebugNode = false
Config.DebugTabs = false Config.Options.DebugTabs = false
title := "master" title := "master"
w := 640 w := 640

View File

@ -30,16 +30,29 @@ func GetDebugToolkit () bool {
} }
func ShowDebugValues() { func ShowDebugValues() {
log.Println("\t wit/gui Debug =", Config.Debug) log.Println("\t wit/gui Debug =", Config.Options.Debug)
log.Println("\t wit/gui DebugDump =", Config.DebugDump) log.Println("\t wit/gui DebugDump =", Config.Options.DebugDump)
log.Println("\t wit/gui DebugNode =", Config.DebugNode) log.Println("\t wit/gui DebugNode =", Config.Options.DebugNode)
log.Println("\t wit/gui DebugTabs =", Config.DebugTabs) log.Println("\t wit/gui DebugTabs =", Config.Options.DebugTabs)
log.Println("\t wit/gui DebugTable =", Config.DebugTable) // log.Println("\t wit/gui DebugTable =", Config.Options.DebugTable)
log.Println("\t wit/gui DebugWindow =", Config.DebugWindow) // log.Println("\t wit/gui DebugWindow =", Config.Options.DebugWindow)
log.Println("\t wit/gui DebugWindow =", Config.DebugWindow) log.Println("\t wit/gui DebugChange =", Config.Options.DebugChange)
log.Println("\t wit/gui DebugToolkit =", toolkit.DebugToolkit) 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 { type GuiConfig struct {
// This is the master node. The Binary Tree starts here // This is the master node. The Binary Tree starts here
master *Node master *Node
@ -50,14 +63,7 @@ type GuiConfig struct {
Height int Height int
Exit func(*Node) Exit func(*Node)
// These are global debugging settings Options GuiOptions
// TODO: move to a standard logging system
Debug bool
DebugDump bool
DebugNode bool
DebugTabs bool
DebugTable bool
DebugWindow bool
// hacks // hacks
depth int depth int
@ -124,7 +130,7 @@ func (n *Node) Window() *Node {
} }
func (n *Node) Dump() { func (n *Node) Dump() {
if ! Config.DebugDump { if ! Config.Options.DebugDump {
return return
} }
IndentPrintln("NODE DUMP START") IndentPrintln("NODE DUMP START")
@ -162,14 +168,16 @@ func (n *Node) Dump() {
IndentPrintln("NODE DUMP END") IndentPrintln("NODE DUMP END")
} }
/*
func (n *Node) SetName(name string) { func (n *Node) SetName(name string) {
n.toolkit.SetWindowTitle(name) n.toolkit.SetWindowTitle(name)
return return
} }
*/
func (n *Node) Append(child *Node) { func (n *Node) Append(child *Node) {
n.children = append(n.children, child) n.children = append(n.children, child)
if (Config.Debug) { if (Config.Options.Debug) {
log.Println("child node:") log.Println("child node:")
child.Dump() child.Dump()
log.Println("parent node:") log.Println("parent node:")
@ -212,11 +220,11 @@ func (n *Node) ListChildren(dump bool) {
if len(n.children) == 0 { if len(n.children) == 0 {
if (n.parent == nil) { if (n.parent == nil) {
} else { } else {
if (Config.DebugNode) { if (Config.Options.DebugNode) {
log.Println("\t\t\tparent =",n.parent.id) log.Println("\t\t\tparent =",n.parent.id)
} }
if (listChildrenParent != nil) { if (listChildrenParent != nil) {
if (Config.DebugNode) { if (Config.Options.DebugNode) {
log.Println("\t\t\tlistChildrenParent =",listChildrenParent.id) log.Println("\t\t\tlistChildrenParent =",listChildrenParent.id)
} }
if (listChildrenParent.id != n.parent.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") log.Println("\t\t", n.id, "has no children")
} }
return return
@ -233,7 +241,7 @@ func (n *Node) ListChildren(dump bool) {
for _, child := range n.children { for _, child := range n.children {
// log.Println("\t\t", child.id, child.Width, child.Height, child.Name) // log.Println("\t\t", child.id, child.Width, child.Height, child.Name)
if (child.parent != nil) { if (child.parent != nil) {
if (Config.DebugNode) { if (Config.Options.DebugNode) {
log.Println("\t\t\tparent =",child.parent.id) log.Println("\t\t\tparent =",child.parent.id)
} }
} else { } else {
@ -243,7 +251,7 @@ func (n *Node) ListChildren(dump bool) {
if (dump == true) { if (dump == true) {
child.Dump() child.Dump()
} }
if (Config.DebugNode) { if (Config.Options.DebugNode) {
if (child.children == nil) { if (child.children == nil) {
log.Println("\t\t", child.id, "has no children") log.Println("\t\t", child.id, "has no children")
} else { } else {

View File

@ -18,7 +18,9 @@ func (n *Node) NewLabel(text string) *Node {
} }
func (n *Node) SetText(str string) bool { func (n *Node) SetText(str string) bool {
if (Config.Options.DebugChange) {
log.Println("gui.SetText() value =", str) log.Println("gui.SetText() value =", str)
}
if (n.toolkit == nil) { if (n.toolkit == nil) {
return false return false
} }

View File

@ -22,13 +22,26 @@ func (n *Node) NewTextbox(name string) *Node {
newt.Name = name newt.Name = name
// newt.Custom = func () { // newt.Custom = func () {
newt.OnChanged = func (*toolkit.Toolkit) { newt.OnChanged = func (*toolkit.Toolkit) {
println("AM IN CALLBACK. SETTING NODE.checked START") if (Config.Options.DebugChange) {
c.text = c.toolkit.GetText() log.Println("AM IN CALLBACK. SETTING NODE.checked START")
c.Dump() c.Dump()
c.toolkit.Dump() c.toolkit.Dump()
}
c.text = c.toolkit.GetText()
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) c.OnChanged(n)
println("n.toolkit.GetText() =", c.text) }
println("AM IN CALLBACK. SETTING NODE.checked END") if (Config.Options.DebugChange) {
log.Println("n.toolkit.GetText() =", c.text)
log.Println("AM IN CALLBACK. SETTING NODE.checked END")
}
} }
return c return c

View File

@ -18,7 +18,9 @@ func (t Toolkit) NewButton(name string) *Toolkit {
return nil return nil
} }
if (DebugToolkit) {
log.Println("gui.Toolbox.NewGroup() create", name) log.Println("gui.Toolbox.NewGroup() create", name)
}
b = ui.NewButton(name) b = ui.NewButton(name)
newt.uiButton = b newt.uiButton = b
@ -26,21 +28,35 @@ func (t Toolkit) NewButton(name string) *Toolkit {
log.Println("TODO: IN TOOLKIT GOROUTINE. SHOULD LEAVE HERE VIA channels. button name =", name) log.Println("TODO: IN TOOLKIT GOROUTINE. SHOULD LEAVE HERE VIA channels. button name =", name)
t.Dump() t.Dump()
newt.Dump() newt.Dump()
if (DebugToolkit) {
log.Println("wit/gui/toolkit NewButton() Should do something here") log.Println("wit/gui/toolkit NewButton() Should do something here")
}
if (newt.Custom == nil) { if (newt.Custom == nil) {
if (DebugToolkit) {
log.Println("wit/gui/toolkit NewButton() toolkit.Custom == nil") log.Println("wit/gui/toolkit NewButton() toolkit.Custom == nil")
}
} else { } else {
if (DebugToolkit) {
log.Println("wit/gui/toolkit NewButton() toolkit.Custom() START") log.Println("wit/gui/toolkit NewButton() toolkit.Custom() START")
}
newt.Custom() newt.Custom()
if (DebugToolkit) {
log.Println("wit/gui/toolkit NewButton() toolkit.Custom() END") log.Println("wit/gui/toolkit NewButton() toolkit.Custom() END")
} }
}
if (t.Custom == nil) { if (t.Custom == nil) {
if (DebugToolkit) {
log.Println("wit/gui/toolkit NewButton() parent toolkit.Custom == nil") log.Println("wit/gui/toolkit NewButton() parent toolkit.Custom == nil")
}
} else { } else {
if (DebugToolkit) {
log.Println("wit/gui/toolkit NewButton() running parent toolkit.Custom() START (IS THIS A BAD IDEA?)") log.Println("wit/gui/toolkit NewButton() running parent toolkit.Custom() START (IS THIS A BAD IDEA?)")
}
t.Custom() t.Custom()
if (DebugToolkit) {
log.Println("wit/gui/toolkit NewButton() running parent toolkit.Custom() END (IS THIS A BAD IDEA?)") 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) log.Println("TODO: LEFT TOOLKIT GOROUTINE button name =", name)
}) })

View File

@ -12,30 +12,38 @@ func init() {
func (t Toolkit) commonChange(widget string) { func (t Toolkit) commonChange(widget string) {
s := t.String() s := t.String()
log.Println("gui.Toolkit.ui.OnChanged() =", s)
if (DebugToolkit) { if (DebugToolkit) {
log.Println("gui.Toolkit.ui.OnChanged() =", s) log.Println("gui.Toolkit.ui.OnChanged() =", s)
} }
if (t.OnChanged != nil) { if (t.OnChanged != nil) {
if (DebugToolkit) {
log.Println("gui.Toolkit.OnChanged() trying to run toolkit.OnChanged() entered val =", s) log.Println("gui.Toolkit.OnChanged() trying to run toolkit.OnChanged() entered val =", s)
}
t.OnChanged(&t) t.OnChanged(&t)
return return
} }
if (t.Custom != nil) { if (t.Custom != nil) {
if (DebugToolkit) {
log.Println("gui.Toolkit.OnChanged() Running toolkit.Custom()") log.Println("gui.Toolkit.OnChanged() Running toolkit.Custom()")
t.Dump() t.Dump()
}
t.Custom() t.Custom()
return return
} }
if (DebugToolkit) {
log.Println("gui.Toolkit.OnChanged() ENDED without finding any callback") 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 { func (t Toolkit) broken() bool {
if (t.uiBox == nil) { if (t.uiBox == nil) {
log.Println("gui.Toolkit.UiBox == nil. I can't add a widget without a place to put it") 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?") // log.Println("probably could just make a box here?")
// corruption or something horrible? // corruption or something horrible?
panic("wit/gui toolkit/andlabs func broken() invalid goroutine access into this toolkit?") 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 return true
} }
if (t.uiWindow == nil) { if (t.uiWindow == nil) {

View File

@ -9,7 +9,9 @@ import _ "github.com/andlabs/ui/winmanifest"
func (t *Toolkit) NewDropdown(title string) *Toolkit { func (t *Toolkit) NewDropdown(title string) *Toolkit {
// make new node here // make new node here
log.Println("gui.Toolbox.NewDropdownCombobox()") if (DebugToolkit) {
log.Println("gui.Toolbox.NewDropdownCombobox()", title)
}
var newt Toolkit var newt Toolkit
if t.broken() { if t.broken() {

View File

@ -17,7 +17,9 @@ func (t Toolkit) NewGroup(title string) *Toolkit {
return nil return nil
} }
if (DebugToolkit) {
log.Println("gui.Toolbox.NewGroup() create", title) log.Println("gui.Toolbox.NewGroup() create", title)
}
g := ui.NewGroup(title) g := ui.NewGroup(title)
g.SetMargined(margin) g.SetMargined(margin)
t.uiBox.Append(g, stretchy) t.uiBox.Append(g, stretchy)

View File

@ -6,9 +6,6 @@ import "os"
import "github.com/andlabs/ui" import "github.com/andlabs/ui"
import _ "github.com/andlabs/ui/winmanifest" 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 { func (t Toolkit) NewSlider(title string, x int, y int) *Toolkit {
// make new node here // make new node here
log.Println("gui.Toolkit.NewSpinbox()", x, y) 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) t.uiBox.Append(s, stretchy)
s.OnChanged(func(spin *ui.Slider) { s.OnChanged(func(spin *ui.Slider) {
i := spin.Value() newt.commonChange("Slider")
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")
}) })
return &newt return &newt

View File

@ -6,9 +6,6 @@ import "os"
import "github.com/andlabs/ui" import "github.com/andlabs/ui"
import _ "github.com/andlabs/ui/winmanifest" 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 { func (t Toolkit) NewSpinner(title string, x int, y int) *Toolkit {
// make new node here // make new node here
log.Println("gui.Toolkit.NewSpinner()", x, y) 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) t.uiBox.Append(s, stretchy)
s.OnChanged(func(s *ui.Spinbox) { s.OnChanged(func(s *ui.Spinbox) {
i := s.Value() newt.commonChange("Spinner")
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)
}
}) })
return &newt return &newt

View File

@ -93,7 +93,7 @@ func forceDump(t *Toolkit) {
} }
func (t *Toolkit) GetText() string { func (t *Toolkit) GetText() string {
forceDump(t) t.Dump()
if (DebugToolkit) { if (DebugToolkit) {
log.Println("gui.Toolkit.Text() Enter") log.Println("gui.Toolkit.Text() Enter")
scs := spew.ConfigState{MaxDepth: 1} scs := spew.ConfigState{MaxDepth: 1}
@ -110,7 +110,9 @@ func (t *Toolkit) GetText() string {
log.Println("gui.Toolkit.Value() =", t.uiMultilineEntry.Text()) log.Println("gui.Toolkit.Value() =", t.uiMultilineEntry.Text())
} }
text := t.uiMultilineEntry.Text() text := t.uiMultilineEntry.Text()
if (DebugToolkit) {
log.Println("gui.Toolkit.Value() text =", text) log.Println("gui.Toolkit.Value() text =", text)
}
t.text = text t.text = text
return text return text
} }

View File

@ -61,14 +61,18 @@ func (t *Toolkit) AddTab(name string) *Toolkit {
func tabSetMargined(tab *ui.Tab) { func tabSetMargined(tab *ui.Tab) {
c := tab.NumPages() c := tab.NumPages()
for i := 0; i < c; i++ { for i := 0; i < c; i++ {
if (DebugToolkit) {
log.Println("SetMargined", i, margin) log.Println("SetMargined", i, margin)
}
tab.SetMargined(i, margin) tab.SetMargined(i, margin)
} }
} }
func newTab(w *ui.Window, name string) *Toolkit { func newTab(w *ui.Window, name string) *Toolkit {
log.Println("gui.toolkit.NewTab() ADD", name)
var t Toolkit var t Toolkit
if (DebugToolkit) {
log.Println("gui.toolkit.NewTab() ADD", name)
}
if (w == nil) { if (w == nil) {
log.Println("gui.toolkit.NewTab() node.UiWindow == nil. I can't add a tab without a window") 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) time.Sleep(1 * time.Second)
return nil return nil
} }
if (DebugToolkit) {
log.Println("gui.toolkit.AddTab() START name =", name) log.Println("gui.toolkit.AddTab() START name =", name)
}
tab := ui.NewTab() tab := ui.NewTab()
w.SetMargined(margin) w.SetMargined(margin)
@ -94,14 +100,18 @@ func newTab(w *ui.Window, name string) *Toolkit {
} }
func (t *Toolkit) appendTab(name string) *Toolkit { func (t *Toolkit) appendTab(name string) *Toolkit {
log.Println("gui.toolkit.NewTab() ADD", name)
var newT Toolkit var newT Toolkit
if (DebugToolkit) {
log.Println("gui.toolkit.NewTab() ADD", name)
}
if (t.uiTab == nil) { if (t.uiTab == nil) {
log.Println("gui.Toolkit.UiWindow == nil. I can't add a widget without a place to put it") 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") panic("should never have happened. wit/gui/toolkit has ui.Tab == nil")
} }
if (DebugToolkit) {
log.Println("gui.toolkit.AddTab() START name =", name) log.Println("gui.toolkit.AddTab() START name =", name)
}
var hbox *ui.Box var hbox *ui.Box
if (defaultBehavior) { if (defaultBehavior) {

View File

@ -6,7 +6,9 @@ import "github.com/andlabs/ui"
import _ "github.com/andlabs/ui/winmanifest" import _ "github.com/andlabs/ui/winmanifest"
func (t Toolkit) NewTextbox(name string) *Toolkit { func (t Toolkit) NewTextbox(name string) *Toolkit {
if (DebugToolkit) {
log.Println("gui.Toolkit.NewTextbox()", name) log.Println("gui.Toolkit.NewTextbox()", name)
}
var newt Toolkit var newt Toolkit
if t.broken() { if t.broken() {

View File

@ -22,17 +22,25 @@ func NewWindow(title string, x int, y int) *Toolkit {
w.SetBorderless(canvas) w.SetBorderless(canvas)
w.SetMargined(margin) w.SetMargined(margin)
w.OnClosing(func(*ui.Window) bool { w.OnClosing(func(*ui.Window) bool {
if (DebugToolkit) {
log.Println("ui.Window().OnExit() SHOULD ATTEMPT CALLBACK here") log.Println("ui.Window().OnExit() SHOULD ATTEMPT CALLBACK here")
t.Dump() t.Dump()
}
if (t.OnExit != nil) { if (t.OnExit != nil) {
if (DebugToolkit) {
log.Println("ui.Window().OnExit() ATTEMPTING toolkit.OnExit CALLBACK") log.Println("ui.Window().OnExit() ATTEMPTING toolkit.OnExit CALLBACK")
}
t.OnExit(&t) t.OnExit(&t)
} }
if (t.Custom != nil) { if (t.Custom != nil) {
if (DebugToolkit) {
log.Println("ui.Window().Custom() ATTEMPTING toolkit.Custom CALLBACK") log.Println("ui.Window().Custom() ATTEMPTING toolkit.Custom CALLBACK")
}
t.Custom() t.Custom()
} }
if (DebugToolkit) {
log.Println("ui.Window().OnExit() Toolkit.OnExit is nil") log.Println("ui.Window().OnExit() Toolkit.OnExit is nil")
}
return true return true
}) })
w.Show() w.Show()

View File

@ -33,52 +33,59 @@ func DebugTab() {
var checkd, checkdn, checkdt, checkdtk *Node var checkd, checkdn, checkdt, checkdtk *Node
//////////////////////// 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")
checkd = df.NewCheckbox("Debug")
checkd.OnChanged = func(*Node) {
checkd.checked = checkd.toolkit.Checked()
Config.Options.Debug = checkd.checked
if (Config.Options.Debug) {
log.Println("Debug turned on")
} else {
log.Println("Debug turned off")
}
}
checkdn = df.NewCheckbox("Debug Node")
checkdn.OnChanged = func(*Node) {
checkdn.checked = checkdn.toolkit.Checked()
Config.Options.DebugNode = checkdn.checked
}
checkdd = df.NewCheckbox("Debug node.Dump()")
checkdd.OnChanged = func(*Node) {
Config.Options.DebugDump = checkdd.toolkit.Checked()
}
changeCheckbox = df.NewCheckbox("Debug Change")
changeCheckbox.OnChanged = func(*Node) {
Config.Options.DebugChange = changeCheckbox.toolkit.Checked()
}
df.NewButton("Dump Debug Flags", func () {
ShowDebugValues()
})
}
func (n *Node) DebugTab(title string) *Node { func (n *Node) DebugTab(title string) *Node {
var newN, gog, g1, g2, g3, dd, gf *Node var newN, gog, g1, g2, g3, dd *Node
// time.Sleep(1 * time.Second) // time.Sleep(1 * time.Second)
newN = n.NewTab(title) newN = n.NewTab(title)
newN.Dump() newN.Dump()
//////////////////////// main debug things //////////////////////////////////
gog = newN.NewGroup("GOLANG") gog = newN.NewGroup("GOLANG")
gog.NewLabel("go language") gog.NewLabel("go language")
gog.NewButton("GO Language Debug", func () { gog.NewButton("GO Language Debug", func () {
GolangDebugWindow() GolangDebugWindow()
}) })
gf = newN.NewGroup("Debug Flags")
gf.NewLabel("flags to control debugging output")
checkd = gf.NewCheckbox("Debug")
checkd.OnChanged = func(*Node) {
checkd.checked = checkd.toolkit.Checked()
Config.Debug = checkd.checked
if (Config.Debug) {
} else {
}
}
checkdn = gf.NewCheckbox("Debug Node")
checkdn.OnChanged = func(*Node) {
checkdn.checked = checkdn.toolkit.Checked()
Config.DebugNode = checkdn.checked
}
checkdd := gf.NewCheckbox("Debug node.Dump()")
checkdd.OnChanged = func(*Node) {
Config.DebugDump = checkdd.toolkit.Checked()
}
checkdt = gf.NewCheckbox("Debug Tabs")
checkdtk = gf.NewCheckbox("Debug Toolkit")
// Debug bool
// DebugNode bool
// DebugTabs bool
// DebugTable bool
// DebugWindow bool
// DebugToolkit bool
gog.NewLabel("wit/gui package") gog.NewLabel("wit/gui package")
gog.NewButton("WIT/GUI Package Debug", func () { gog.NewButton("WIT/GUI Package Debug", func () {
Config.Width = 640 Config.Width = 640
@ -92,6 +99,9 @@ func (n *Node) DebugTab(title string) *Node {
DemoToolkitWindow() DemoToolkitWindow()
}) })
debugFlags(newN)
//////////////////////// window debugging things //////////////////////////////////
g1 = newN.NewGroup("Current Windows") g1 = newN.NewGroup("Current Windows")
dd = g1.NewDropdown("Window Dropdown") dd = g1.NewDropdown("Window Dropdown")
log.Println("dd =", dd) log.Println("dd =", dd)