release as v0.6.5

good standard release
    really clean interaction to plugin
    really clean debug flags implementation
    common doAppend() idea, but it probably won't work
    re-implement combobox. this code base almost doesn't suck
    slider & spinner set values now
    tab set margin works
    convert dropdown to Send()
    lots of other changes to try to implement single line Entry()
    I guess use golang file names even though internalally the go developers
    use underscore chars in the actual go sources.
        Maybe there is a reason for that?
    go channel debug window does something
    make a debug window for channels. add sample icons

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2023-03-03 14:41:38 -06:00
parent 56cd14867d
commit 7d1836390a
40 changed files with 1072 additions and 472 deletions

View File

@ -145,41 +145,41 @@ var WARN bool
## Functions ## Functions
### func [DebugWidgetWindow](/debug_widget.go#L7) ### func [DebugWidgetWindow](/debugWidget.go#L107)
`func DebugWidgetWindow(w *Node)` `func DebugWidgetWindow(w *Node)`
### func [DebugWindow](/debug_window.go#L9) ### func [DebugWindow](/debugWindow.go#L9)
`func DebugWindow()` `func DebugWindow()`
Creates a window helpful for debugging this package Creates a window helpful for debugging this package
### func [Delete](/common.go#L66) ### func [Delete](/common.go#L90)
`func Delete(c *Node)` `func Delete(c *Node)`
### func [Indent](/debug.go#L123) ### func [Indent](/debug.go#L101)
`func Indent(a ...interface{})` `func Indent(a ...interface{})`
### func [InitPlugins](/main.go#L46) ### func [InitPlugins](/main.go#L50)
`func InitPlugins(names []string)` `func InitPlugins(names []string)`
### func [LoadToolkit](/plugin.go#L56) ### func [LoadToolkit](/plugin.go#L43)
`func LoadToolkit(name string) bool` `func LoadToolkit(name string) bool`
loads and initializes a toolkit (andlabs/ui, gocui, etc) loads and initializes a toolkit (andlabs/ui, gocui, etc)
### func [Main](/main.go#L87) ### func [Main](/main.go#L91)
`func Main(f func())` `func Main(f func())`
This should not pass a function This should not pass a function
### func [Queue](/main.go#L117) ### func [Queue](/main.go#L121)
`func Queue(f func())` `func Queue(f func())`
@ -190,27 +190,19 @@ other goroutines. This is due to the nature of how
Linux, MacOS and Windows work (they all work differently. suprise. surprise.) Linux, MacOS and Windows work (they all work differently. suprise. surprise.)
For example: gui.Queue(NewWindow()) For example: gui.Queue(NewWindow())
### func [SetDebug](/debug.go#L24) ### func [SetDebug](/debug.go#L27)
`func SetDebug(s bool)` `func SetDebug(s bool)`
### func [SetDebugChange](/debug.go#L58) ### func [SetFlag](/debug.go#L41)
`func SetDebugChange(s bool)` `func SetFlag(s string, b bool)`
This passes the debugChange flag to the toolkit plugin ### func [ShowDebugValues](/debug.go#L62)
### func [SetDebugToolkit](/debug.go#L43)
`func SetDebugToolkit(s bool)`
This passes the debugToolkit flag to the toolkit plugin
### func [ShowDebugValues](/debug.go#L72)
`func ShowDebugValues()` `func ShowDebugValues()`
### func [StandardExit](/main.go#L136) ### func [StandardExit](/main.go#L140)
`func StandardExit()` `func StandardExit()`
@ -243,7 +235,7 @@ This struct can be used with the go-arg package
var Config GuiConfig var Config GuiConfig
``` ```
### type [Node](/structs.go#L54) ### type [Node](/structs.go#L57)
`type Node struct { ... }` `type Node struct { ... }`

View File

@ -12,9 +12,3 @@ func (n *Node) NewCheckbox(name string) *Node {
send(n, newNode) send(n, newNode)
return newNode return newNode
} }
func (n *Node) NewThing(name string) *Node {
newNode := n.New(name, toolkit.Button, nil)
send(n, newNode)
return newNode
}

View File

@ -81,12 +81,6 @@ func buttonWindow() {
gui.DebugWindow() gui.DebugWindow()
}) })
g.NewButton("gui.GolangDebugWindow()", func () {
// make a seperate window out of this
// w.GolangDebugWindow(false)
w.GolangDebugWindow(true)
})
g.NewButton("LoadToolkit(andlabs)", func () { g.NewButton("LoadToolkit(andlabs)", func () {
gui.LoadToolkit("andlabs") gui.LoadToolkit("andlabs")
}) })

View File

@ -1,5 +1,5 @@
run: build run: build
./textbox --gui-debug GOTRACEBACK=all ./textbox --gui-debug
build-release: build-release:
go get -v -u -x . go get -v -u -x .
@ -7,7 +7,7 @@ build-release:
build: build:
GO111MODULE="off" go get -v -x . GO111MODULE="off" go get -v -x .
GO111MODULE="off" go build GO111MODULE="off" GOTRACEBACK=all go build
update: update:
GO111MODULE="off" go get -v -u -x . GO111MODULE="off" go get -v -u -x .

View File

@ -8,6 +8,13 @@ import (
// functions for handling text related GUI elements // functions for handling text related GUI elements
func (n *Node) Add(str string) {
log(debugGui, "gui.Add() value =", str)
n.widget.Action = "Add"
n.widget.S = str
send(n.parent, n)
}
func (n *Node) SetText(str string) bool { func (n *Node) SetText(str string) bool {
log(debugChange, "gui.SetText() value =", str) log(debugChange, "gui.SetText() value =", str)
n.widget.Action = "Set" n.widget.Action = "Set"
@ -16,6 +23,23 @@ func (n *Node) SetText(str string) bool {
return true return true
} }
func (n *Node) Set(a any) bool {
log(debugChange, "gui.Set() value =", a)
n.widget.Action = "Set"
switch v := a.(type) {
case bool:
n.widget.B = a.(bool)
case string:
n.widget.S = a.(string)
case int:
n.widget.I = a.(int)
default:
log(debugError, "gui.Set() unknown type =", v, "a =", a)
}
send(n.parent, n)
return true
}
func (n *Node) AppendText(str string) bool { func (n *Node) AppendText(str string) bool {
n.widget.Action = "Set" n.widget.Action = "Set"
tmp := n.widget.S + str tmp := n.widget.S + str

View File

@ -10,69 +10,60 @@ import (
// various debugging flags // various debugging flags
var debugGui bool = false var debugGui bool = false
var debugError bool = false
var debugDump bool = false var debugDump bool = false
var debugNode bool = false var debugNode bool = false
var debugTabs bool = false var debugTabs bool = false
var debugFlags bool = false
var debugChange bool = false // shows user events like mouse and keyboard var debugChange bool = false // shows user events like mouse and keyboard
var debugPlugin bool = false var debugPlugin bool = false
var debugToolkit bool = false var debugToolkit bool = false
// func GetDebug () bool { // for printing out the binary tree
// return debugGui var listChildrenParent *Node
// } var listChildrenDepth int = 0
var defaultPadding = " "
func SetDebug (s bool) { func SetDebug (s bool) {
debugGui = s debugGui = s
debugChange = s
debugDump = s debugDump = s
debugTabs = s debugTabs = s
debugPlugin = s debugPlugin = s
debugNode = s debugNode = s
debugToolkit = s debugToolkit = s
SetDebugChange(s)
SetDebugToolkit(s) SetFlag("Flags", s)
SetFlag("Toolkit", s)
SetFlag("Change", s)
SetFlag("Error", s)
} }
/* func SetFlag (s string, b bool) {
func GetDebugToolkit () bool { switch s {
return debugToolkit case "Error":
} debugError = b
*/ case "Change":
debugChange = b
// This passes the debugToolkit flag to the toolkit plugin case "Show":
func SetDebugToolkit (s bool) { // print them here? For now, just used to print settings in the plugins
debugToolkit = s default:
for _, aplug := range allPlugins { log(debugError, "Can't set unknown flag", s)
log(debugPlugin, "gui.SetDebugToolkit() aplug =", aplug.name)
if (aplug.SetDebugToolkit == nil) {
log(debugPlugin, "\tgui.SetDebugToolkit() = nil", aplug.name)
continue
}
aplug.SetDebugToolkit(s)
return
} }
log(debugPlugin, "\tgui.SetDebugToolkit() = nil in all plugins")
}
// This passes the debugChange flag to the toolkit plugin // send the flag to the toolkit
func SetDebugChange (s bool) { n := Config.flag
// debugToolkit = s log(debugChange, "Set() toolkit flag", s, "to", b)
for _, aplug := range allPlugins { n.widget.Action = "Set"
log(debugPlugin, "gui.SetDebugChange() aplug =", aplug.name) n.widget.S = s
if (aplug.SetDebugChange == nil) { n.widget.B = b
log(debugPlugin, "\tgui.SetDebugChange() = nil", aplug.name) send(nil, n)
continue
}
aplug.SetDebugChange(s)
return
}
log(debugPlugin, "\tgui.SetDebugChange() = nil in all plugins")
} }
func ShowDebugValues() { func ShowDebugValues() {
// The order here should match the order in the GUI // The order here should match the order in the GUI
// TODO: get the order from the node binary tree // TODO: get the order from the node binary tree
log(true, "Debug =", debugGui) log(true, "Debug =", debugGui)
log(true, "DebugError =", debugError)
log(true, "DebugChange =", debugChange) log(true, "DebugChange =", debugChange)
log(true, "DebugDump =", debugDump) log(true, "DebugDump =", debugDump)
log(true, "DebugTabs =", debugTabs) log(true, "DebugTabs =", debugTabs)
@ -80,16 +71,7 @@ func ShowDebugValues() {
log(true, "DebugNode =", debugNode) log(true, "DebugNode =", debugNode)
log(true, "DebugToolkit =", debugToolkit) log(true, "DebugToolkit =", debugToolkit)
// dump out the debugging flags for the plugins SetFlag("Show", true)
for _, aplug := range allPlugins {
log(debugPlugin, "gui.ShowDebug() aplug =", aplug.name)
if (aplug.ShowDebug == nil) {
log(debugPlugin, "\tgui.ShowDebug() = nil", aplug.name)
continue
}
aplug.ShowDebug()
return
}
} }
func (n *Node) Dump() { func (n *Node) Dump() {
@ -116,10 +98,6 @@ func (n *Node) Dump() {
Indent("NODE DUMP END") Indent("NODE DUMP END")
} }
var listChildrenParent *Node
var listChildrenDepth int = 0
var defaultPadding = " "
func Indent(a ...interface{}) { func Indent(a ...interface{}) {
logindent(listChildrenDepth, defaultPadding, a...) logindent(listChildrenDepth, defaultPadding, a...)
} }

View File

@ -15,7 +15,7 @@ func (n *Node) debugFlags(makeWindow bool) {
w = NewWindow() w = NewWindow()
w.Custom = w.StandardClose w.Custom = w.StandardClose
} else { } else {
w = n.NewTab("Debug Flags") w = n.NewTab("Flags")
} }
w.Dump() w.Dump()
@ -36,12 +36,19 @@ func (n *Node) debugFlags(makeWindow bool) {
log(debugGui, "Custom() n.widget =", cb1.widget.Name, cb1.widget.B) log(debugGui, "Custom() n.widget =", cb1.widget.Name, cb1.widget.B)
} }
// errors. by default these always output somewhere
cbE := g.NewCheckbox("debugError")
cbE.Custom = func() {
debugError = cbE.widget.B
SetFlag("Error", debugError)
}
// debugging that will show you things like mouse clicks, user inputing text, etc // debugging that will show you things like mouse clicks, user inputing text, etc
// also set toolkit.DebugChange // also set toolkit.DebugChange
cb2 := g.NewCheckbox("debugChange") cb2 := g.NewCheckbox("debugChange")
cb2.Custom = func() { cb2.Custom = func() {
debugChange = cb2.widget.B debugChange = cb2.widget.B
SetDebugChange(cb2.widget.B) SetFlag("Change", debugChange)
log(debugGui, "Custom() n.widget =", cb2.widget.Name, cb2.widget.B) log(debugGui, "Custom() n.widget =", cb2.widget.Name, cb2.widget.B)
} }
@ -74,8 +81,9 @@ func (n *Node) debugFlags(makeWindow bool) {
// turns on debugging inside the plugin toolkit // turns on debugging inside the plugin toolkit
cb7 := g.NewCheckbox("debugToolkit") cb7 := g.NewCheckbox("debugToolkit")
cb7.Custom = func() { cb7.Custom = func() {
SetDebugToolkit(cb7.widget.B) // SetDebugToolkit(cb7.widget.B)
log(debugGui, "Custom() n.widget =", cb7.widget.Name, cb7.widget.B) SetFlag("Toolkit", cb7.widget.B)
log(debugFlags, "Custom() n.widget =", cb7.widget.Name, cb7.widget.B)
} }
g.NewButton("Dump Debug Flags", func () { g.NewButton("Dump Debug Flags", func () {

107
debugGochan.go Normal file
View File

@ -0,0 +1,107 @@
// https://www.digitalocean.com/community/tutorials/how-to-run-multiple-functions-concurrently-in-go
// who came up with the idea of making community tutorials. that was a good idea!
package gui
import (
"fmt"
"sync"
)
var debugWG *sync.WaitGroup
var debugNumberChan chan int
func (n *Node) debugGoChannels(makeWindow bool) {
var w, g *Node
// Either:
// make a new window
// make a new tab in the existing window
if (makeWindow) {
Config.Title = "Debug GO Channels"
Config.Width = 300
Config.Height = 400
w = NewWindow()
w.Custom = w.StandardClose
} else {
w = n.NewTab("Chan")
}
w.Dump()
g = w.NewGroup("Channel stuff")
// var debugWG sync.WaitGroup
g.NewButton("init()", func () {
if (debugNumberChan == nil) {
log("making debugNumberChan channel")
debugNumberChan = make(chan int)
} else {
log("debugNumberChan already made")
}
debugWG = new(sync.WaitGroup)
})
g.NewButton("go printInt(x) (read x values off the channel)", func () {
debugWG.Add(1)
go printInt(2, "routine1")
debugWG.Add(1)
go printInt(2, "routine2")
})
g.NewButton("sendNumber(2) (chan <- 2, 4)", func () {
debugWG.Add(1)
debugWG.Add(1)
go sendNumber(2)
go sendNumber(4)
})
g.NewButton("sendNumber(1) (chan <- 7)", func () {
debugWG.Add(1)
go sendNumber(7)
})
g.NewButton("send 4 numbers (chan <- int)", func () {
log("generateNumbers(4)")
go generateNumbers(4)
})
g.NewButton("debugWG.Done()", func () {
log("ran debugWG.Done()")
debugWG.Done()
})
g.NewButton("close chan", func () {
close(debugNumberChan)
})
g.NewButton("print", func () {
log("waitgroup counter is ?")
})
}
func sendNumber(i int) {
log("START debugNumberChan <-", i, " (sending", i, "to channel)")
debugNumberChan <- i
debugWG.Wait()
log("END debugNumberChan sendNumber() done", i)
}
func generateNumbers(total int) {
fmt.Printf("START generateNumbers()\n")
for idx := 1; idx <= total; idx++ {
log("ran debugNumberChan <= idx where idx =", idx)
fmt.Printf("S generateNumbers() sending %d to channel\n", idx)
debugNumberChan <- idx
// res, err := (<-r)()
fmt.Printf("E generateNumbers() sending %d to channel\n", idx)
}
debugWG.Wait()
fmt.Printf("END generateNumbers()\n")
}
// i equals the number of times to read values from the channel
func printInt(i int, name string) {
tmp := 1
log("START printInt", name, "read debugNumberChan()")
for num := range debugNumberChan {
log("printInt()",name, "read", num, "from channel")
debugWG.Done()
if (tmp == i) {
return
}
tmp += 1
}
fmt.Printf("END printInt()", name, "read debugNumberChan\n")
}

View File

@ -9,7 +9,7 @@ import (
"runtime/pprof" "runtime/pprof"
) )
func (n *Node) GolangDebugWindow(makeWindow bool) { func (n *Node) debugGolangWindow(makeWindow bool) {
var w, g, og, outputTextbox *Node var w, g, og, outputTextbox *Node
// Either: // Either:
@ -22,7 +22,7 @@ func (n *Node) GolangDebugWindow(makeWindow bool) {
w = NewWindow() w = NewWindow()
w.Custom = w.StandardClose w.Custom = w.StandardClose
} else { } else {
w = n.NewTab("GO") w = n.NewTab("GOLANG")
} }
w.Dump() w.Dump()
@ -93,6 +93,11 @@ func (n *Node) GolangDebugWindow(makeWindow bool) {
g.NewLabel("TODO:") g.NewLabel("TODO:")
g.NewButton("runtime.Stack(true)", func () {
// TODO: https://stackoverflow.com/questions/61127053/how-to-list-all-the-running-goroutines-in-a-go-program
// func Stack(buf []byte, all bool) int
})
g.NewButton("debug.SetMemoryLimit(int)", func () { g.NewButton("debug.SetMemoryLimit(int)", func () {
// TODO: // TODO:
//debug.SetMemoryLimit(1024 * 1024 * 100) //debug.SetMemoryLimit(1024 * 1024 * 100)
@ -109,6 +114,13 @@ func (n *Node) GolangDebugWindow(makeWindow bool) {
g.NewButton("debug.SetTraceback('all')", func () { g.NewButton("debug.SetTraceback('all')", func () {
debug.SetTraceback("all") debug.SetTraceback("all")
}) })
g.NewButton("runtime.NumGoroutine()", func () {
buf := new(bytes.Buffer)
pprof.Lookup("goroutine").WriteTo(buf, 1)
outputTextbox.SetText(buf.String())
outputTextbox.AppendText(fmt.Sprintln("runtime.NumGoroutine() = ", runtime.NumGoroutine()))
})
// deprecated (probably) by String() implementation within golang // deprecated (probably) by String() implementation within golang
g.NewButton("dumpModuleInfo() (deprecate)", func () { g.NewButton("dumpModuleInfo() (deprecate)", func () {

View File

@ -4,6 +4,106 @@ import (
"strconv" "strconv"
) )
var debugGrid *Node
func (n *Node) debugWidgets(makeWindow bool) {
var w, gList, gShow *Node
// Either:
// make a new window
// make a new tab in the existing window
if (makeWindow) {
Config.Title = "Debug Widgets"
Config.Width = 300
Config.Height = 400
w = NewWindow()
w.Custom = w.StandardClose
} else {
w = n.NewTab("Widgets")
}
w.Dump()
gList = w.NewGroup("Pick a widget to debug")
gShow = w.NewGroup("Added Widgets go here")
gList.NewButton("Button", func () {
SetDebug(true)
a := gShow.NewButton("myButton", func () {
log("this code is more better")
})
SetDebug(false)
DebugWidgetWindow(a)
})
gList.NewButton("Checkbox", func () {
a := gShow.NewCheckbox("myCheckbox")
a.Custom = func () {
log("custom checkox func a =", a.widget.B, a.id)
}
DebugWidgetWindow(a)
})
gList.NewButton("Label", func () {
a := gShow.NewLabel("mylabel")
DebugWidgetWindow(a)
})
gList.NewButton("Textbox", func () {
a := gShow.NewTextbox("mytext")
a.Custom = func () {
log("custom TextBox() a =", a.widget.S, a.id)
}
DebugWidgetWindow(a)
})
gList.NewButton("Slider", func () {
a := gShow.NewSlider("tmp slider", 10, 55)
a.Custom = func () {
log("custom slider() a =", a.widget.I, a.id)
}
DebugWidgetWindow(a)
})
gList.NewButton("Spinner", func () {
a := gShow.NewSpinner("tmp spinner", 6, 32)
a.Custom = func () {
log("custom spinner() a =", a.widget.I, a.id)
}
DebugWidgetWindow(a)
})
gList.NewButton("Dropdown", func () {
a := gShow.NewDropdown("tmp dropdown")
a.AddDropdownName("this is better than tcl/tk")
a.AddDropdownName("make something for tim")
a.AddDropdownName("for qflow")
a.Add("and for riscv")
a.Custom = func () {
log("custom dropdown() a =", a.widget.Name, a.widget.S)
}
DebugWidgetWindow(a)
})
gList.NewButton("Combobox", func () {
a := gShow.NewCombobox("tmp combobox")
a.Add("mirrors.wit.com")
a.Add("go.wit.org")
a.Custom = func () {
log("custom combobox() a =", a.widget.Name, a.widget.S)
}
DebugWidgetWindow(a)
})
gList.NewButton("Grid", func () {
// Grid numbering by (X,Y)
// -----------------------------
// -- (1,1) -- (2,1) -- (3,1) --
// -- (1,2) -- (2,1) -- (3,1) --
// -----------------------------
SetDebug(true)
debugGrid = gShow.NewGrid("tmp grid", 2, 3)
debugGrid.NewLabel("mirrors.wit.com")
SetDebug(false)
DebugWidgetWindow(debugGrid)
})
gList.NewButton("Image", func () {
a := gShow.NewTextbox("image")
DebugWidgetWindow(a)
})
}
func DebugWidgetWindow(w *Node) { func DebugWidgetWindow(w *Node) {
var win, g *Node var win, g *Node
@ -49,67 +149,32 @@ func DebugWidgetWindow(w *Node) {
w.widget.S = "Set Value(20)" w.widget.S = "Set Value(20)"
send(w.parent, w) send(w.parent, w)
}) })
g.NewButton("Add('foo')", func () {
w.widget.Action = "Add"
w.widget.S = "foo"
send(w.parent, w)
})
g.NewButton("Delete('foo')", func () {
w.widget.Action = "Delete"
w.widget.S = "foo"
send(w.parent, w)
})
g.NewButton("SetMargin(true)", func () {
w.widget.Action = "SetMargin"
w.widget.B = true
send(w.parent, w)
})
g.NewButton("SetMargin(false)", func () {
w.widget.Action = "SetMargin"
w.widget.B = false
send(w.parent, w)
})
g.NewButton("Add button to (1,1)", func () {
w.widget.Action = "AddGrid"
w.widget.B = false
send(w.parent, w)
})
g.NewButton("Delete()", func () { g.NewButton("Delete()", func () {
Delete(w) Delete(w)
}) })
} }
func (n *Node) debugWidgets(makeWindow bool) {
var w, gList, gShow *Node
// Either:
// make a new window
// make a new tab in the existing window
if (makeWindow) {
Config.Title = "Widgets"
Config.Width = 300
Config.Height = 400
w = NewWindow()
w.Custom = w.StandardClose
} else {
w = n.NewTab("Widgets")
}
w.Dump()
gList = w.NewGroup("Pick a widget to debug")
gShow = w.NewGroup("Added Widgets go here")
gList.NewButton("Button", func () {
a := gShow.NewButton("myButton", func () {
log("this code is more better")
})
DebugWidgetWindow(a)
})
gList.NewButton("Checkbox", func () {
a := gShow.NewCheckbox("myCheckbox")
a.Custom = func () {
log("custom checkox func a =", a.widget.B, a.id)
}
DebugWidgetWindow(a)
})
gList.NewButton("Label", func () {
a := gShow.NewLabel("mylabel")
DebugWidgetWindow(a)
})
gList.NewButton("Textbox", func () {
a := gShow.NewTextbox("mytext")
a.Custom = func () {
log("custom TextBox() a =", a.widget.S, a.id)
}
DebugWidgetWindow(a)
})
gList.NewButton("Slider", func () {
a := gShow.NewSlider("tmp slider", 10, 55)
a.Custom = func () {
log("custom slider() a =", a.widget.S, a.id)
}
DebugWidgetWindow(a)
})
gList.NewButton("Spinner", func () {
a := gShow.NewSpinner("tmp spinner", 6, 32)
a.Custom = func () {
log("custom spinner() a =", a.widget.S, a.id)
}
DebugWidgetWindow(a)
})
}

View File

@ -19,37 +19,28 @@ var checkd, checkdn, checkdt, checkdtk, lb1, lb2 *Node
var myButton *Node var myButton *Node
func (n *Node) DebugTab(title string) *Node { func (n *Node) DebugTab(title string) *Node {
var newN, gog, g1, g2, g3, dd, junk, newThing *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 ////////////////////////////////// //////////////////////// main debug things //////////////////////////////////
gog = newN.NewGroup("GOLANG") gog = newN.NewGroup("Debugging")
gog.NewLabel("go language")
gog.NewButton("GO Language Debug", func () {
newN.GolangDebugWindow(false)
})
gog.NewButton("Debug Flags", func () { gog.NewButton("Debug Flags", func () {
newN.debugFlags(false) newN.debugFlags(false)
}) })
gog.NewButton("Debug Widgets", func () { gog.NewButton("Debug Widgets", func () {
newN.debugWidgets(false) newN.debugWidgets(false)
}) })
gog.NewButton("GO Language Internals", func () {
gog.NewLabel("wit/gui package") newN.debugGolangWindow(false)
gog.NewButton("Demo toolkit andlabs/ui", func () {
// DemoToolkitWindow()
}) })
gog.NewButton("GO Channels debug", func () {
junk = gog.NewButton("junk", func () { newN.debugGoChannels(false)
log("click junk, get junk")
}) })
gog.NewLabel("tmp label")
//////////////////////// window debugging things ////////////////////////////////// //////////////////////// window debugging things //////////////////////////////////
g1 = newN.NewGroup("Current Windows") g1 = newN.NewGroup("Current Windows")
dd = g1.NewDropdown("Window Dropdown") dd = g1.NewDropdown("Window Dropdown")
@ -83,33 +74,6 @@ func (n *Node) DebugTab(title string) *Node {
mapWindows[child.Name] = child mapWindows[child.Name] = child
} }
dd.SetDropdownName(last) dd.SetDropdownName(last)
dd.NewButton("Delete(junk)", func () {
Delete(junk)
})
dd.NewButton("myButton", func () {
gog.NewButton("myButton", func () {
log("this code is better")
})
})
dd.NewButton("add Hope", func () {
var i int = 1
log("add hope?", i)
gog.NewButton("hope", func () {
i += 1
log("write better code", i)
})
})
dd.NewButton("add newThing", func () {
var i, j int = 1, 1
newThing = gog.NewThing("NewThing")
newThing.Custom = func() {
f := i + j
log("newThing!!! n.widget =", newThing.widget.Name, newThing.widget.B, f)
j = i
i = f
}
log("newThing!!! n.widget")
})
g2 = newN.NewGroup("Debug Window") g2 = newN.NewGroup("Debug Window")
g2.NewButton("SetMargined(tab)", func () { g2.NewButton("SetMargined(tab)", func () {

View File

@ -6,41 +6,22 @@ import (
// add a new entry to the dropdown name // add a new entry to the dropdown name
func (n *Node) AddDropdownName(name string) { func (n *Node) AddDropdownName(name string) {
for _, aplug := range allPlugins { n.Add(name)
log(debugPlugin, "AddDropdownName() aplug =", aplug.name, "name =", name)
if (aplug.AddDropdownName == nil) {
log(debugPlugin, "\taplug.AddDropdownName() = nil")
continue
}
aplug.AddDropdownName(&n.widget, name)
}
} }
// Set the dropdown menu to 'name' // Set the dropdown menu to 'name'
func (n *Node) SetDropdownName(name string) { func (n *Node) SetDropdownName(name string) {
log(debugGui, "SetDropdownName() work. name =", name) n.SetText(name)
for _, aplug := range allPlugins {
log(debugPlugin, "SetDropdownName() aplug =", aplug.name, "name =", name)
if (aplug.SetDropdownName == nil) {
log(true, "\taplug.SetDropdownName() aplug = nil")
continue
}
aplug.SetDropdownName(&n.widget, name)
}
} }
func (n *Node) NewDropdown(name string) *Node { func (n *Node) NewDropdown(name string) *Node {
newNode := n.New(name, toolkit.Dropdown, nil) newNode := n.New(name, toolkit.Dropdown, nil)
send(n, newNode)
for _, aplug := range allPlugins { return newNode
log(debugGui, "gui.NewDropdown() aplug =", aplug.name, "name =", newNode.widget.Name) }
if (aplug.NewDropdown == nil) {
log(debugGui, "\tgui.NewDropdown() aplug.NewDropdown = nil", aplug.name) func (n *Node) NewCombobox(name string) *Node {
continue newNode := n.New(name, toolkit.Combobox, nil)
} send(n, newNode)
aplug.NewDropdown(&n.widget, &newNode.widget)
}
// TODO, this doesn't work for some reason (over-written by plugin?)
return newNode return newNode
} }

16
grid.go Normal file
View File

@ -0,0 +1,16 @@
package gui
import (
"git.wit.org/wit/gui/toolkit"
)
func (n *Node) NewGrid(name string, x int, y int) *Node {
newNode := n.New(name, toolkit.Grid, func() {
log(debugChange, "click() NewGrid not defined =", name)
})
newNode.widget.X = x
newNode.widget.Y = y
send(n, newNode)
return newNode
}

8
int.go
View File

@ -13,13 +13,7 @@ package gui
Is it "has to go" or "should go"? Probably it makes sense to strictly inforce it. No "callback" functions. IPC only (go channels) Is it "has to go" or "should go"? Probably it makes sense to strictly inforce it. No "callback" functions. IPC only (go channels)
*/ */
func (n *Node) Int() int { func (n *Node) Int() int {
log(debugToolkit, "gui.Node.Int() for node name =", n.Name) return n.widget.I
log(debugToolkit, SPEW, n)
// FIXME: this needs to be redone
// i := n.toolkit.Value()
i := 3333
return i
} }
// which name to use? // which name to use?

View File

@ -2,6 +2,7 @@ package gui
import ( import (
"embed" "embed"
"git.wit.org/wit/gui/toolkit"
) )
// Windows doesn't support plugins. How can I keep andlabs and only compile it on windows? // Windows doesn't support plugins. How can I keep andlabs and only compile it on windows?
@ -26,7 +27,8 @@ func init() {
// Populates the top of the binary tree // Populates the top of the binary tree
Config.master = addNode("guiBinaryTree") Config.master = addNode("guiBinaryTree")
go doGuiChan() // used to pass debugging flags to the toolkit plugins
Config.flag = Config.master.New("flag", toolkit.Flag, nil)
} }
func doGuiChan() { func doGuiChan() {
@ -39,7 +41,9 @@ func doGuiChan() {
log(true, "CHANNEL ACTION 2 !!!!!") log(true, "CHANNEL ACTION 2 !!!!!")
return return
default: default:
log(true, "doGuiChan() nothing")
} }
log(true, "doGuiChan() for()")
} }
} }

View File

@ -35,19 +35,6 @@ type aplug struct {
// simplifies passing to the plugin // simplifies passing to the plugin
Send func(*toolkit.Widget, *toolkit.Widget) Send func(*toolkit.Widget, *toolkit.Widget)
NewButton func(*toolkit.Widget, *toolkit.Widget)
NewGroup func(*toolkit.Widget, *toolkit.Widget)
NewCheckbox func(*toolkit.Widget, *toolkit.Widget)
NewTab func(*toolkit.Widget, *toolkit.Widget)
NewDropdown func(*toolkit.Widget, *toolkit.Widget)
AddDropdownName func(*toolkit.Widget, string)
SetDropdownName func(*toolkit.Widget, string)
SetDebugToolkit func(bool)
SetDebugChange func(bool)
ShowDebug func()
} }
var allPlugins []*aplug var allPlugins []*aplug
@ -71,6 +58,7 @@ func LoadToolkit(name string) bool {
filename := name + ".so" filename := name + ".so"
loadPlugin(&newPlug, filename) loadPlugin(&newPlug, filename)
if (newPlug.plug == nil) { if (newPlug.plug == nil) {
log(true, "attempt to find plugin", filename, "failed")
return false return false
} }
// newPlug.Ok = true // newPlug.Ok = true
@ -92,19 +80,9 @@ func LoadToolkit(name string) bool {
// This includes instructions like "Add", "Delete", "Disable", etc // This includes instructions like "Add", "Delete", "Disable", etc
newPlug.Send = loadFunc2(&newPlug, "Send") newPlug.Send = loadFunc2(&newPlug, "Send")
// newPlug.NewGroup = loadFunc2(&newPlug, "NewGroup")
newPlug.NewDropdown = loadFunc2(&newPlug, "NewDropdown")
newPlug.AddDropdownName = loadFuncS(&newPlug, "AddDropdownName")
newPlug.SetDropdownName = loadFuncS(&newPlug, "SetDropdownName")
newPlug.SetDebugToolkit = loadFuncB(&newPlug, "SetDebugToolkit")
newPlug.SetDebugChange = loadFuncB(&newPlug, "SetDebugChange")
newPlug.ShowDebug = loadFuncE(&newPlug, "ShowDebug")
allPlugins = append(allPlugins, &newPlug) allPlugins = append(allPlugins, &newPlug)
log(debugGui, "gui.LoadToolkit() END", newPlug.name, filename) log(debugPlugin, "gui.LoadToolkit() END", newPlug.name, filename)
newPlug.Init() newPlug.Init()
newPlug.LoadOk = true newPlug.LoadOk = true
return true return true
@ -131,63 +109,6 @@ func loadFuncE(p *aplug, funcName string) func() {
return newfunc return newfunc
} }
func loadFunc1(p *aplug, funcName string) func(*toolkit.Widget) {
var newfunc func(*toolkit.Widget)
var ok bool
var test plugin.Symbol
test, err = p.plug.Lookup(funcName)
if err != nil {
log(debugGui, "DID NOT FIND: name =", test, "err =", err)
return nil
}
newfunc, ok = test.(func(*toolkit.Widget))
if !ok {
log(debugGui, "function name =", funcName, "names didn't map correctly. Fix the plugin name =", p.name)
return nil
}
return newfunc
}
func loadFuncS(p *aplug, funcName string) func(*toolkit.Widget, string) {
var newfunc func(*toolkit.Widget, string)
var ok bool
var test plugin.Symbol
test, err = p.plug.Lookup(funcName)
if err != nil {
log(debugGui, "DID NOT FIND: name =", test, "err =", err)
return nil
}
newfunc, ok = test.(func(*toolkit.Widget, string))
if !ok {
log(debugGui, "function name =", funcName, "names didn't map correctly. Fix the plugin name =", p.name)
return nil
}
return newfunc
}
func loadFuncB(p *aplug, funcName string) func(bool) {
var newfunc func(bool)
var ok bool
var test plugin.Symbol
test, err = p.plug.Lookup(funcName)
if err != nil {
log(debugGui, "DID NOT FIND: name =", test, "err =", err)
return nil
}
newfunc, ok = test.(func(bool))
if !ok {
log(debugGui, "function name =", funcName, "names didn't map correctly. Fix the plugin name =", p.name)
return nil
}
return newfunc
}
func loadFunc2(p *aplug, funcName string) func(*toolkit.Widget, *toolkit.Widget) { func loadFunc2(p *aplug, funcName string) func(*toolkit.Widget, *toolkit.Widget) {
var newfunc func(*toolkit.Widget, *toolkit.Widget) var newfunc func(*toolkit.Widget, *toolkit.Widget)
var ok bool var ok bool
@ -276,6 +197,7 @@ func loadfile(filename string) *plugin.Plugin {
return nil return nil
} }
log(debugGui, "plugin WORKED =", filename) log(debugGui, "plugin WORKED =", filename)
log(true, "loading plugin", filename, "worked")
return plug return plug
} }

View File

@ -34,6 +34,9 @@ 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
// A node off of master for passing debugging flags
flag *Node
// These are shortcuts to pass default values to make a new window // These are shortcuts to pass default values to make a new window
Title string Title string
Width int Width int

103
toolkit/andlabs/append.go Normal file
View File

@ -0,0 +1,103 @@
package main
import (
"git.wit.org/wit/gui/toolkit"
"github.com/andlabs/ui"
_ "github.com/andlabs/ui/winmanifest"
)
// make new Group here
func (t *andlabsT) doAppend(newt *andlabsT, c *ui.Control) {
if (newt.tw != nil) {
if (newt.tw.Type == toolkit.Grid) {
log(true, "doAppend() going to attempt uiGrid")
// hack to add shit to a grid
button1 := ui.NewButton("a(0,2)")
newt.uiGrid.Append(button1,
0, 2, 1, 1,
false, ui.AlignFill, false, ui.AlignFill)
button2 := ui.NewButton("a(1,2)")
newt.uiGrid.Append(button2,
1, 2, 1, 1,
false, ui.AlignFill, false, ui.AlignFill)
if (t.uiBox != nil) {
log(true, "doAppend() on uiGrid to a uiBox")
if (newt.Name == "output") {
t.uiBox.Append(newt.uiGrid, true)
} else {
t.uiBox.Append(newt.uiGrid, stretchy)
}
return
}
log(true, "doAppend() on uiGrid failed")
return
}
} else {
log(true, "doAppend() newt.tw == nil ERROR on newt.Name =", newt.Name)
}
// hack to pass a group
if (c == nil) {
log(true, "attempting to doAppend() on a uiGroup")
if (t.uiBox != nil) {
if (newt.Name == "output") {
t.uiBox.Append(newt.uiGroup, true)
} else {
t.uiBox.Append(newt.uiGroup, stretchy)
}
return
}
if (t.uiWindow != nil) {
log(true, "This is a raw window without a box. probably make a box here and add the group to that")
t.Dump(true)
newt.Dump(true)
t.uiBox = ui.NewHorizontalBox()
t.uiWindow.SetChild(t.uiBox)
log(true, "tried to make a box", t.uiBox)
if (newt.Name == "output") {
log(true, "tried to t.uiBox.Append(*c, true)")
if (t.uiBox == nil) {
log(true, "tried to t.uiBox.Append(*c, true)")
}
t.uiBox.Append(newt.uiGroup, true)
} else {
log(true, "tried to t.uiBox.Append(*c, stretchy)")
t.uiBox.Append(newt.uiGroup, stretchy)
}
return
}
log(debugError, "NewGroup() node.UiBox == nil. I can't add a range UI element without a place to put it")
log(debugError, "probably could just make a box here?")
exit("internal wit/gui error")
}
if (t.uiBox != nil) {
// TODO: temporary hack to make the output textbox 'fullscreen'
if (newt.Name == "output") {
t.uiBox.Append(*c, true)
} else {
t.uiBox.Append(*c, stretchy)
}
return
}
if (t.uiWindow != nil) {
log(true, "This is a raw window without a box. probably make a box here and add the group to that")
t.uiBox = ui.NewHorizontalBox()
t.uiWindow.SetChild(t.uiBox)
log(true, "tried to make a box")
if (newt.Name == "output") {
t.uiBox.Append(*c, true)
} else {
t.uiBox.Append(*c, stretchy)
}
return
}
log(debugError, "NewGroup() node.UiBox == nil. I can't add a range UI element without a place to put it")
log(debugError, "probably could just make a box here?")
exit("internal wit/gui error")
}

View File

@ -4,16 +4,16 @@ import "github.com/andlabs/ui"
import _ "github.com/andlabs/ui/winmanifest" import _ "github.com/andlabs/ui/winmanifest"
// create a new box // create a new box
func (t *andlabsT) GetBox() *ui.Box { func (t *andlabsT) getBox() *ui.Box {
return t.uiBox return t.uiBox
} }
// create a new box // create a new box
func (t *andlabsT) NewBox() *andlabsT { func (t *andlabsT) newBox() *andlabsT {
log(debugToolkit, "gui.Toolbox.NewBox() START create default") log(debugToolkit, "newBox() START create default")
t.Dump(debugToolkit) t.Dump(debugToolkit)
if (t.uiGroup != nil) { if (t.uiGroup != nil) {
log(debugToolkit, "\tgui.Toolbox.NewBox() is a Group") log(debugToolkit, "\tnewBox() is a Group")
var newTK andlabsT var newTK andlabsT
vbox := ui.NewVerticalBox() vbox := ui.NewVerticalBox()
@ -24,7 +24,7 @@ func (t *andlabsT) NewBox() *andlabsT {
return &newTK return &newTK
} }
if (t.uiBox != nil) { if (t.uiBox != nil) {
log(debugToolkit, "\tgui.Toolbox.NewBox() is a Box") log(debugToolkit, "\tnewBox() is a Box")
var newTK andlabsT var newTK andlabsT
vbox := ui.NewVerticalBox() vbox := ui.NewVerticalBox()
@ -36,7 +36,7 @@ func (t *andlabsT) NewBox() *andlabsT {
return &newTK return &newTK
} }
if (t.uiWindow != nil) { if (t.uiWindow != nil) {
log(debugToolkit, "\tgui.Toolbox.NewBox() is a Window") log(debugToolkit, "\tnewBox() is a Window")
var newT andlabsT var newT andlabsT
vbox := ui.NewVerticalBox() vbox := ui.NewVerticalBox()
@ -48,7 +48,7 @@ func (t *andlabsT) NewBox() *andlabsT {
// panic("WTF") // panic("WTF")
return &newT return &newT
} }
log(debugToolkit, "\tgui.Toolbox.NewBox() FAILED. Couldn't figure out where to make a box") log(debugToolkit, "\tnewBox() FAILED. Couldn't figure out where to make a box")
t.Dump(debugToolkit) t.Dump(debugToolkit)
return nil return nil
} }

View File

@ -6,8 +6,8 @@ import (
_ "github.com/andlabs/ui/winmanifest" _ "github.com/andlabs/ui/winmanifest"
) )
func (t andlabsT) NewCheckbox(w *toolkit.Widget) *andlabsT { func (t *andlabsT) newCheckbox(w *toolkit.Widget) *andlabsT {
log(debugToolkit, "NewCheckbox()", w.Name, w.Type) log(debugToolkit, "newCheckbox()", w.Name, w.Type)
var newt andlabsT var newt andlabsT
newt.tw = w newt.tw = w
@ -15,13 +15,13 @@ func (t andlabsT) NewCheckbox(w *toolkit.Widget) *andlabsT {
return nil return nil
} }
c := ui.NewCheckbox(w.Name) newt.uiCheckbox = ui.NewCheckbox(w.Name)
newt.uiCheckbox = c
newt.uiBox = t.uiBox newt.uiBox = t.uiBox
t.uiBox.Append(c, stretchy) // t.doAppend(&newt, *newt.uiCheckbox)
t.uiBox.Append(newt.uiCheckbox, stretchy)
c.OnToggled(func(spin *ui.Checkbox) { newt.uiCheckbox.OnToggled(func(spin *ui.Checkbox) {
newt.tw.B = newt.Checked() newt.tw.B = newt.checked()
log(debugChange, "val =", newt.tw.B) log(debugChange, "val =", newt.tw.B)
newt.commonChange(newt.tw) newt.commonChange(newt.tw)
}) })
@ -29,7 +29,7 @@ func (t andlabsT) NewCheckbox(w *toolkit.Widget) *andlabsT {
return &newt return &newt
} }
func (t andlabsT) Checked() bool { func (t *andlabsT) checked() bool {
if t.broken() { if t.broken() {
return false return false
} }
@ -37,15 +37,15 @@ func (t andlabsT) Checked() bool {
return t.uiCheckbox.Checked() return t.uiCheckbox.Checked()
} }
func NewCheckbox(parentW *toolkit.Widget, w *toolkit.Widget) { func newCheckbox(parentW *toolkit.Widget, w *toolkit.Widget) {
log(debugToolkit, "NewCheckbox()", w.Name) log(debugToolkit, "newCheckbox()", w.Name)
t := mapToolkits[parentW] t := mapToolkits[parentW]
if (t == nil) { if (t == nil) {
listMap(debugError) listMap(debugError)
return return
} }
newt := t.NewCheckbox(w) newt := t.newCheckbox(w)
mapWidgetsToolkits(w, newt) mapWidgetsToolkits(w, newt)
} }
@ -54,7 +54,7 @@ func doCheckbox(p *toolkit.Widget, c *toolkit.Widget) {
return return
} }
if (c.Action == "New") { if (c.Action == "New") {
NewCheckbox(p, c) newCheckbox(p, c)
return return
} }
ct := mapToolkits[c] ct := mapToolkits[c]

100
toolkit/andlabs/combobox.go Normal file
View File

@ -0,0 +1,100 @@
package main
import (
"github.com/andlabs/ui"
_ "github.com/andlabs/ui/winmanifest"
"git.wit.org/wit/gui/toolkit"
)
func (t *andlabsT) newCombobox(w *toolkit.Widget) *andlabsT {
var newt andlabsT
log(debugToolkit, "newCombobox() START", w.Name)
if t.broken() {
return nil
}
newt.tw = w
s := ui.NewEditableCombobox()
newt.uiEditableCombobox = s
newt.uiBox = t.uiBox
t.uiBox.Append(s, stretchy)
// initialize the index
newt.c = 0
newt.val = make(map[int]string)
s.OnChanged(func(spin *ui.EditableCombobox) {
newt.tw.S = spin.Text()
newt.commonChange(newt.tw)
})
return &newt
}
func (t *andlabsT) AddComboboxName(title string) {
t.uiEditableCombobox.Append(title)
if (t.val == nil) {
log(debugToolkit, "make map didn't work")
return
}
t.val[t.c] = title
// If this is the first menu added, set the dropdown to it
// if (t.c == 0) {
// }
t.c = t.c + 1
}
func newCombobox(parentW *toolkit.Widget, w *toolkit.Widget) {
log(debugToolkit, "newCombobox()", w.Name)
t := mapToolkits[parentW]
if (t == nil) {
log(debugToolkit, "newCombobox() toolkit struct == nil. name=", parentW.Name, w.Name)
listMap(debugToolkit)
return
}
newt := t.newCombobox(w)
mapWidgetsToolkits(w, newt)
}
func doCombobox(p *toolkit.Widget, c *toolkit.Widget) {
if broken(c) {
return
}
if (c.Action == "New") {
newCombobox(p, c)
return
}
ct := mapToolkits[c]
if (ct == nil) {
log(true, "Trying to do something on a widget that doesn't work or doesn't exist or something", c)
return
}
if ct.broken() {
log(true, "Combobox() ct.broken", ct)
return
}
if (ct.uiEditableCombobox == nil) {
log(true, "Combobox() uiEditableCombobox == nil", ct)
return
}
log(true, "Going to attempt:", c.Action)
switch c.Action {
case "Add":
ct.AddComboboxName(c.S)
case "Enable":
ct.uiEditableCombobox.Enable()
case "Disable":
ct.uiEditableCombobox.Disable()
case "Show":
ct.uiEditableCombobox.Show()
case "Hide":
ct.uiEditableCombobox.Hide()
case "Set":
ct.uiEditableCombobox.SetText(c.S)
default:
log(true, "Can't do", c.Action, "to a Combobox")
}
}

View File

@ -2,6 +2,7 @@ package main
import ( import (
"git.wit.org/wit/gui/toolkit" "git.wit.org/wit/gui/toolkit"
"github.com/davecgh/go-spew/spew"
) )
// This is important. This sets the defaults for the gui. Without this, there isn't correct padding, etc // This is important. This sets the defaults for the gui. Without this, there isn't correct padding, etc
@ -11,7 +12,7 @@ func init() {
setDefaultBehavior(true) setDefaultBehavior(true)
} }
func (t andlabsT) commonChange(tw *toolkit.Widget) { func (t *andlabsT) commonChange(tw *toolkit.Widget) {
log(debugChange, "commonChange() START widget =", t.Name, t.Type) log(debugChange, "commonChange() START widget =", t.Name, t.Type)
if (tw == nil) { if (tw == nil) {
log(true, "commonChange() What the fuck. there is no widget t.tw == nil") log(true, "commonChange() What the fuck. there is no widget t.tw == nil")
@ -35,7 +36,7 @@ func (t *andlabsT) broken() bool {
if (t.uiBox == nil) { if (t.uiBox == nil) {
if (t.uiWindow != nil) { if (t.uiWindow != nil) {
log(debugToolkit, "UiBox == nil. This is an empty window. Try to add a box") log(debugToolkit, "UiBox == nil. This is an empty window. Try to add a box")
t.NewBox() t.newBox()
return false return false
} }
log(true, "UiBox == nil. I can't add a widget without a place to put it") log(true, "UiBox == nil. I can't add a widget without a place to put it")
@ -60,3 +61,141 @@ func broken(w *toolkit.Widget) bool {
} }
return false return false
} }
func dump(p *toolkit.Widget, c *toolkit.Widget, b bool) {
log(b, "Parent:")
pt := mapToolkits[p]
if (pt == nil) {
log(b, "Trying to do something on a widget that doesn't work or doesn't exist or something", c)
return
}
pt.Dump(b)
log(b, "Child:")
ct := mapToolkits[c]
if (ct == nil) {
log(b, "Trying to do something on a widget that doesn't work or doesn't exist or something", c)
return
}
ct.Dump(b)
}
func setMarginNew(w *toolkit.Widget, b bool) {
wt := mapToolkits[w]
log(true, "START setMarginNew", w.Name)
if (wt == nil) {
return
}
if (wt.uiGroup != nil) {
log(true, "uiGroup.SetMargined(true)")
wt.uiGroup.SetMargined(b)
}
if (wt.uiTab != nil) {
i := wt.uiTab.NumPages()
log(true, "tab.NumPages() =", i)
for i > 0 {
i -= 1
log(true, "uiTab.SetMargined(true) for i =", i)
wt.uiTab.SetMargined(i, b)
}
} else {
log(true, "no uitab")
}
if (wt.uiWindow != nil) {
log(true, "uiWindow.SetMargined(true)")
wt.uiWindow.SetMargined(b)
}
log(true, "END setMarginNew", w.Name)
}
func setMargin(p *toolkit.Widget, c *toolkit.Widget, b bool) {
log(true, "Starting to implement SetMargin here")
dump(p, c, true)
setMarginNew(c, b)
setMarginNew(p, b)
}
func (t *andlabsT) String() string {
return t.GetText()
}
func (t *andlabsT) GetText() string {
log(debugToolkit, "GetText() Enter debugToolkit=", debugToolkit)
if (t.uiEntry != nil) {
log(debugToolkit, "uiEntry.Text() =", t.uiEntry.Text())
return t.uiEntry.Text()
}
if (t.uiMultilineEntry != nil) {
log(debugToolkit, "uiMultilineEntry.Text() =", t.uiMultilineEntry.Text())
text := t.uiMultilineEntry.Text()
log(debugToolkit, "uiMultilineEntry.Text() =", text)
t.text = text
return text
}
if (t.uiCombobox != nil) {
log(debugToolkit, "uiCombobox() =", t.text)
return t.text
}
return ""
}
func (t *andlabsT) SetText(s string) bool {
log(debugToolkit, "Text() SetText() Enter")
if (t.uiEntry != nil) {
log(debugToolkit, "Value() =", t.uiEntry.Text)
t.uiEntry.SetText(s)
return true
}
if (t.uiMultilineEntry != nil) {
log(debugToolkit, "Value() =", t.uiMultilineEntry.Text)
t.uiMultilineEntry.SetText(s)
return true
}
return false
}
func sanity(t *andlabsT) bool {
if (debugToolkit) {
log(debugToolkit, "Value() Enter")
scs := spew.ConfigState{MaxDepth: 1}
scs.Dump(t)
}
if (t.uiEntry == nil) {
log(debugToolkit, "Value() =", t.uiEntry.Text)
return false
}
return true
}
func (t *andlabsT) SetValue(i int) bool {
log(debugToolkit, "SetValue() START")
if (sanity(t)) {
return false
}
t.Dump(debugToolkit)
// panic("got to toolkit.SetValue")
return true
}
func (t *andlabsT) Value() int {
if (debugToolkit) {
log(debugToolkit, "Value() Enter")
scs := spew.ConfigState{MaxDepth: 1}
scs.Dump(t)
}
if (t == nil) {
log(debugToolkit, "Value() can not get value t == nil")
return 0
}
if (t.uiSlider != nil) {
log(debugToolkit, "Value() =", t.uiSlider.Value)
return t.uiSlider.Value()
}
if (t.uiSpinbox != nil) {
log(debugToolkit, "Value() =", t.uiSpinbox.Value)
return t.uiSpinbox.Value()
}
log(debugToolkit, "Value() Could not find a ui element to get a value from")
return 0
}

View File

@ -2,7 +2,7 @@ package main
import "git.wit.org/wit/gui/toolkit" import "git.wit.org/wit/gui/toolkit"
import "github.com/davecgh/go-spew/spew" // import "github.com/davecgh/go-spew/spew"
var defaultBehavior bool = true var defaultBehavior bool = true
@ -16,6 +16,7 @@ var margin bool // add space around the frames of windows
var debugToolkit bool var debugToolkit bool
var debugChange bool var debugChange bool
var debugPlugin bool var debugPlugin bool
var debugFlag bool
var debugError bool = true var debugError bool = true
// var DebugToolkit bool // var DebugToolkit bool
@ -36,6 +37,7 @@ func setDefaultBehavior(s bool) {
} }
} }
/*
func SetDebugToolkit (s bool) { func SetDebugToolkit (s bool) {
debugToolkit = s debugToolkit = s
log(true, "debugToolkit =", debugToolkit) log(true, "debugToolkit =", debugToolkit)
@ -47,98 +49,12 @@ func SetDebugChange (s bool) {
log(true, "debugToolkit =", debugToolkit) log(true, "debugToolkit =", debugToolkit)
log(true, "debugChange =", debugChange) log(true, "debugChange =", debugChange)
} }
*/
func ShowDebug () { func ShowDebug () {
log(true, "debugToolkit =", debugToolkit) log(true, "debugToolkit =", debugToolkit)
log(true, "debugChange =", debugChange) log(true, "debugError =", debugError)
} log(true, "debugChange =", debugChange)
func GetDebugToolkit () bool {
return debugToolkit
}
func (t *andlabsT) String() string {
return t.GetText()
}
func (t *andlabsT) GetText() string {
log(debugToolkit, "GetText() Enter debugToolkit=", debugToolkit)
if (t.uiEntry != nil) {
log(debugToolkit, "uiEntry.Text() =", t.uiEntry.Text())
return t.uiEntry.Text()
}
if (t.uiMultilineEntry != nil) {
log(debugToolkit, "uiMultilineEntry.Text() =", t.uiMultilineEntry.Text())
text := t.uiMultilineEntry.Text()
log(debugToolkit, "uiMultilineEntry.Text() =", text)
t.text = text
return text
}
if (t.uiCombobox != nil) {
log(debugToolkit, "uiCombobox() =", t.text)
return t.text
}
return ""
}
func (t *andlabsT) SetText(s string) bool {
log(debugToolkit, "Text() SetText() Enter")
if (t.uiEntry != nil) {
log(debugToolkit, "Value() =", t.uiEntry.Text)
t.uiEntry.SetText(s)
return true
}
if (t.uiMultilineEntry != nil) {
log(debugToolkit, "Value() =", t.uiMultilineEntry.Text)
t.uiMultilineEntry.SetText(s)
return true
}
return false
}
func sanity(t *andlabsT) bool {
if (debugToolkit) {
log(debugToolkit, "Value() Enter")
scs := spew.ConfigState{MaxDepth: 1}
scs.Dump(t)
}
if (t.uiEntry == nil) {
log(debugToolkit, "Value() =", t.uiEntry.Text)
return false
}
return true
}
func (t *andlabsT) SetValue(i int) bool {
log(debugToolkit, "SetValue() START")
if (sanity(t)) {
return false
}
t.Dump(debugToolkit)
// panic("got to toolkit.SetValue")
return true
}
func (t *andlabsT) Value() int {
if (debugToolkit) {
log(debugToolkit, "Value() Enter")
scs := spew.ConfigState{MaxDepth: 1}
scs.Dump(t)
}
if (t == nil) {
log(debugToolkit, "Value() can not get value t == nil")
return 0
}
if (t.uiSlider != nil) {
log(debugToolkit, "Value() =", t.uiSlider.Value)
return t.uiSlider.Value()
}
if (t.uiSpinbox != nil) {
log(debugToolkit, "Value() =", t.uiSpinbox.Value)
return t.uiSpinbox.Value()
}
log(debugToolkit, "Value() Could not find a ui element to get a value from")
return 0
} }
func (t *andlabsT) Dump(b bool) { func (t *andlabsT) Dump(b bool) {
@ -196,3 +112,9 @@ func widgetDump(b bool, w *toolkit.Widget) {
log(b, "widget.X =", w.X) log(b, "widget.X =", w.X)
log(b, "widget.Y =", w.Y) log(b, "widget.Y =", w.Y)
} }
/*
func GetDebugToolkit () bool {
return debugToolkit
}
*/

View File

@ -6,9 +6,9 @@ import (
"git.wit.org/wit/gui/toolkit" "git.wit.org/wit/gui/toolkit"
) )
func (t *andlabsT) NewDropdown(w *toolkit.Widget) *andlabsT { func (t *andlabsT) newDropdown(w *toolkit.Widget) *andlabsT {
var newt andlabsT var newt andlabsT
log(debugToolkit, "gui.Toolbox.NewDropdown() START", w.Name) log(debugToolkit, "gui.Toolbox.newDropdown() START", w.Name)
if t.broken() { if t.broken() {
return nil return nil
@ -53,23 +53,10 @@ func (t *andlabsT) AddDropdownName(title string) {
t.c = t.c + 1 t.c = t.c + 1
} }
func (t andlabsT) SetDropdown(i int) { func (t *andlabsT) SetDropdown(i int) {
t.uiCombobox.SetSelected(i) t.uiCombobox.SetSelected(i)
} }
func NewDropdown(parentW *toolkit.Widget, w *toolkit.Widget) {
log(debugToolkit, "gui.andlabs.NewDropdown()", w.Name)
t := mapToolkits[parentW]
if (t == nil) {
log(debugToolkit, "go.andlabs.NewDropdown() toolkit struct == nil. name=", parentW.Name, w.Name)
listMap(debugToolkit)
return
}
newt := t.NewDropdown(w)
mapWidgetsToolkits(w, newt)
}
func AddDropdownName(w *toolkit.Widget, s string) { func AddDropdownName(w *toolkit.Widget, s string) {
log(debugToolkit, "gui.andlabs.AddDropdownName()", w.Name, "add:", s) log(debugToolkit, "gui.andlabs.AddDropdownName()", w.Name, "add:", s)
@ -94,3 +81,57 @@ func SetDropdownName(w *toolkit.Widget, s string) {
t.SetDropdown(1) t.SetDropdown(1)
t.tw.S = s t.tw.S = s
} }
func newDropdown(parentW *toolkit.Widget, w *toolkit.Widget) {
log(debugToolkit, "gui.andlabs.newDropdown()", w.Name)
t := mapToolkits[parentW]
if (t == nil) {
log(debugToolkit, "go.andlabs.newDropdown() toolkit struct == nil. name=", parentW.Name, w.Name)
listMap(debugToolkit)
return
}
newt := t.newDropdown(w)
mapWidgetsToolkits(w, newt)
}
func doDropdown(p *toolkit.Widget, c *toolkit.Widget) {
if broken(c) {
return
}
if (c.Action == "New") {
newDropdown(p, c)
return
}
ct := mapToolkits[c]
if (ct == nil) {
log(true, "Trying to do something on a widget that doesn't work or doesn't exist or something", c)
return
}
if ct.broken() {
log(true, "Dropdown() ct.broken", ct)
return
}
if (ct.uiCombobox == nil) {
log(true, "Dropdown() uiCombobox == nil", ct)
return
}
log(true, "Going to attempt:", c.Action)
switch c.Action {
case "Add":
ct.AddDropdownName(c.S)
// ct.uiCombobox.Enable()
case "Enable":
ct.uiCombobox.Enable()
case "Disable":
ct.uiCombobox.Disable()
case "Show":
ct.uiCombobox.Show()
case "Hide":
ct.uiCombobox.Hide()
case "Set":
ct.uiCombobox.SetSelected(1)
default:
log(true, "Can't do", c.Action, "to a Dropdown")
}
}

102
toolkit/andlabs/grid.go Normal file
View File

@ -0,0 +1,102 @@
package main
import (
"github.com/andlabs/ui"
_ "github.com/andlabs/ui/winmanifest"
"git.wit.org/wit/gui/toolkit"
)
// Grid numbering by (X,Y)
// -----------------------------
// -- (1,1) -- (2,1) -- (3,1) --
// -- (1,2) -- (2,1) -- (3,1) --
// -----------------------------
func newGrid(parentW *toolkit.Widget, w *toolkit.Widget) {
var newt *andlabsT
log(debugToolkit, "NewGrid()", w.Name)
t := mapToolkits[parentW]
if (t == nil) {
listMap(debugError)
log(debugError, "ERROR newGrid() listMap()")
log(debugError, "ERROR FFFFFFFFFFFF listMap()")
log(debugError, "ERROR FFFFFFFFFFFF listMap()")
return
}
log(debugToolkit, "NewGrid()", w.Name)
if t.broken() {
return
}
newt = new(andlabsT)
c := ui.NewGrid()
newt.uiGrid = c
newt.uiBox = t.uiBox
newt.tw = w
t.doAppend(newt, nil)
/*
if (defaultBehavior) {
t.uiBox.Append(c, stretchy)
}
button1 := ui.NewButton("a(0,0)")
c.Append(button1,
0, 0, 1, 1,
false, ui.AlignFill, false, ui.AlignFill)
button2 := ui.NewButton("a(1,0)")
c.Append(button2,
1, 0, 1, 1,
false, ui.AlignFill, false, ui.AlignFill)
*/
// Append(child Control,
// left, top int,
// xspan, yspan int,
// hexpand bool, halign Align,
// vexpand bool, valign Align) {
mapWidgetsToolkits(w, newt)
}
func doGrid(p *toolkit.Widget, c *toolkit.Widget) {
if broken(c) {
return
}
if (c.Action == "New") {
newGrid(p, c)
return
}
ct := mapToolkits[c]
if (ct == nil) {
log(true, "Trying to do something on a widget that doesn't work or doesn't exist or something", c)
return
}
if ct.broken() {
log(true, "Grid() ct.broken", ct)
return
}
if (ct.uiGrid == nil) {
log(true, "Grid() uiGrid == nil", ct)
return
}
log(true, "Going to attempt:", c.Action)
switch c.Action {
case "Enable":
ct.uiGrid.Enable()
case "Disable":
ct.uiGrid.Disable()
case "Show":
ct.uiGrid.Show()
case "Hide":
ct.uiGrid.Hide()
case "Set":
log(true, "Can I use 'Set' to place a *Node in a Grid?")
default:
log(true, "Can't do", c.Action, "to a Grid")
}
}

View File

@ -8,49 +8,62 @@ import (
) )
func newGroup(parentW *toolkit.Widget, w *toolkit.Widget) { func newGroup(parentW *toolkit.Widget, w *toolkit.Widget) {
log(debugToolkit, "gui.andlabs.NewGroup()", w.Name) // log(debugToolkit, "gui.andlabs.NewGroup()", w.Name)
log(true, "NewGroup()", w.Name)
t := mapToolkits[parentW] t := mapToolkits[parentW]
if (t == nil) { if (t == nil) {
log(debugToolkit, "go.andlabs.NewGroup() toolkit struct == nil. name=", parentW.Name, w.Name) log(debugToolkit, "NewGroup() toolkit struct == nil. name=", parentW.Name, w.Name)
listMap(debugToolkit) listMap(debugToolkit)
} }
newt := t.NewGroup(w.Name) newt := t.rawGroup(w.Name)
mapWidgetsToolkits(w, newt) mapWidgetsToolkits(w, newt)
} }
// make new Group here // make new Group here
func (t andlabsT) NewGroup(title string) *andlabsT { func (t *andlabsT) rawGroup(title string) *andlabsT {
var newt andlabsT var newt andlabsT
newt.Name = title
log(debugToolkit, "NewGroup() create", title) log(debugToolkit, "NewGroup() create", newt.Name)
g := ui.NewGroup(title) g := ui.NewGroup(newt.Name)
g.SetMargined(margin) g.SetMargined(margin)
newt.uiGroup = g
t.doAppend(&newt, nil)
/*
if (t.uiBox != nil) { if (t.uiBox != nil) {
// TODO: temporary hack to make the output textbox 'fullscreen' // TODO: temporary hack to make the output textbox 'fullscreen'
if (title == "output") { if (newt.Name == "output") {
t.uiBox.Append(g, true) t.uiBox.Append(g, true)
} else { } else {
t.uiBox.Append(g, stretchy) t.uiBox.Append(g, stretchy)
} }
} else if (t.uiWindow != nil) { } else if (t.uiWindow != nil) {
t.uiWindow.SetChild(g) log(true, "This is a raw window without a box. probably make a box here and add the group to that")
t.uiBox = ui.NewHorizontalBox()
t.uiWindow.SetChild(t.uiBox)
log(true, "tried to make a box")
if (newt.Name == "output") {
t.uiBox.Append(g, true)
} else {
t.uiBox.Append(g, stretchy)
}
} else { } else {
log(debugError, "NewGroup() node.UiBox == nil. I can't add a range UI element without a place to put it") log(debugError, "NewGroup() node.UiBox == nil. I can't add a range UI element without a place to put it")
log(debugError, "probably could just make a box here?") log(debugError, "probably could just make a box here?")
exit("internal wit/gui error") exit("internal wit/gui error")
} }
*/
hbox := ui.NewVerticalBox() hbox := ui.NewVerticalBox()
hbox.SetPadded(padded) hbox.SetPadded(padded)
g.SetChild(hbox) g.SetChild(hbox)
newt.uiGroup = g
newt.uiBox = hbox newt.uiBox = hbox
newt.uiWindow = t.uiWindow newt.uiWindow = t.uiWindow
newt.Name = title newt.uiTab = t.uiTab
return &newt return &newt
} }

27
toolkit/andlabs/icon.go Normal file
View File

@ -0,0 +1,27 @@
package main
var rawImage = []byte{
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d,
0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10,
0x08, 0x06, 0x00, 0x00, 0x00, 0x1f, 0xf3, 0xff, 0x61, 0x00, 0x00, 0x00,
0x01, 0x73, 0x52, 0x47, 0x42, 0x00, 0xae, 0xce, 0x1c, 0xe9, 0x00, 0x00,
0x00, 0xca, 0x49, 0x44, 0x41, 0x54, 0x38, 0x11, 0xa5, 0x93, 0xb1, 0x0d,
0xc2, 0x40, 0x0c, 0x45, 0x1d, 0xc4, 0x14, 0x0c, 0x12, 0x41, 0x0f, 0x62,
0x12, 0x46, 0x80, 0x8a, 0x2e, 0x15, 0x30, 0x02, 0x93, 0x20, 0x68, 0x11,
0x51, 0x06, 0x61, 0x0d, 0x88, 0x2d, 0x7f, 0xdb, 0x07, 0x87, 0x08, 0xdc,
0x49, 0x91, 0x7d, 0xf6, 0xf7, 0xf3, 0x4f, 0xa4, 0x54, 0xbb, 0xeb, 0xf6,
0x41, 0x05, 0x67, 0xcc, 0xb3, 0x9b, 0xfa, 0xf6, 0x17, 0x62, 0xdf, 0xcd,
0x48, 0x00, 0x32, 0xbd, 0xa8, 0x1d, 0x72, 0xee, 0x3c, 0x47, 0x16, 0xfb,
0x5c, 0x53, 0x8d, 0x03, 0x30, 0x14, 0x84, 0xf7, 0xd5, 0x89, 0x26, 0xc7,
0x25, 0x10, 0x36, 0xe4, 0x05, 0xa2, 0x51, 0xbc, 0xc4, 0x1c, 0xc3, 0x1c,
0xed, 0x30, 0x1c, 0x8f, 0x16, 0x3f, 0x02, 0x78, 0x33, 0x20, 0x06, 0x60,
0x97, 0x70, 0xaa, 0x45, 0x7f, 0x85, 0x60, 0x5d, 0xb6, 0xf4, 0xc2, 0xc4,
0x3e, 0x0f, 0x44, 0xcd, 0x1b, 0x20, 0x90, 0x0f, 0xed, 0x85, 0xa8, 0x55,
0x05, 0x42, 0x43, 0xb4, 0x9e, 0xce, 0x71, 0xb3, 0xe8, 0x0e, 0xb4, 0xc4,
0xc3, 0x39, 0x21, 0xb7, 0x73, 0xbd, 0xe4, 0x1b, 0xe4, 0x04, 0xb6, 0xaa,
0x4f, 0x18, 0x2c, 0xee, 0x42, 0x31, 0x01, 0x84, 0xfa, 0xe0, 0xd4, 0x00,
0xdf, 0xb6, 0x83, 0xf8, 0xea, 0xc2, 0x00, 0x10, 0xfc, 0x1a, 0x05, 0x30,
0x74, 0x3b, 0xe0, 0xd1, 0x45, 0xb1, 0x83, 0xaa, 0xf4, 0x77, 0x7e, 0x02,
0x87, 0x1f, 0x42, 0x7f, 0x9e, 0x2b, 0xe8, 0xdf, 0x00, 0x00, 0x00, 0x00,
0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82,
}

View File

@ -27,7 +27,7 @@ func newLabel(parentW *toolkit.Widget, w *toolkit.Widget) {
newt = new(andlabsT) newt = new(andlabsT)
c := ui.NewLabel(w.Name + " FIX") c := ui.NewLabel(w.Name)
newt.uiLabel = c newt.uiLabel = c
newt.uiBox = t.uiBox newt.uiBox = t.uiBox
@ -39,7 +39,6 @@ func newLabel(parentW *toolkit.Widget, w *toolkit.Widget) {
mapWidgetsToolkits(w, newt) mapWidgetsToolkits(w, newt)
} }
func doLabel(p *toolkit.Widget, c *toolkit.Widget) { func doLabel(p *toolkit.Widget, c *toolkit.Widget) {
if broken(c) { if broken(c) {
return return

View File

@ -1,6 +1,7 @@
package main package main
import ( import (
"embed"
"git.wit.org/wit/gui/toolkit" "git.wit.org/wit/gui/toolkit"
"github.com/andlabs/ui" "github.com/andlabs/ui"
@ -8,6 +9,9 @@ import (
_ "github.com/andlabs/ui/winmanifest" _ "github.com/andlabs/ui/winmanifest"
) )
//go:embed resources
var res embed.FS
func Main(f func()) { func Main(f func()) {
log(debugToolkit, "Starting gui.Main() (using gtk via andlabs/ui)") log(debugToolkit, "Starting gui.Main() (using gtk via andlabs/ui)")
ui.Main( func() { ui.Main( func() {
@ -33,9 +37,8 @@ func Main(f func()) {
// //
func Queue(f func()) { func Queue(f func()) {
log(debugToolkit, "Sending function to ui.QueueMain()") log(debugToolkit, "Sending function to ui.QueueMain()")
log(true, "THIS DOES BREAK. TODO: wrap this") log(true, "using gui.Queue() in this plugin DOES BREAK. TODO: wrap this")
ui.QueueMain(f) ui.QueueMain(f)
// f()
} }
func Init() { func Init() {

View File

@ -26,6 +26,12 @@ func Send(p *toolkit.Widget, c *toolkit.Widget) {
} }
log(debugPlugin, "Send() child =", c.Name, ",", c.Action, ",", c.Type) log(debugPlugin, "Send() child =", c.Name, ",", c.Action, ",", c.Type)
if (c.Action == "SetMargin") {
log(true, "need to implement SetMargin here")
setMargin(p, c, c.B)
return
}
switch c.Type { switch c.Type {
case toolkit.Window: case toolkit.Window:
newWindow(c) newWindow(c)
@ -45,10 +51,36 @@ func Send(p *toolkit.Widget, c *toolkit.Widget) {
newSlider(p, c) newSlider(p, c)
case toolkit.Spinner: case toolkit.Spinner:
newSpinner(p, c) newSpinner(p, c)
case toolkit.Dropdown:
doDropdown(p, c)
case toolkit.Combobox:
doCombobox(p, c)
case toolkit.Grid:
doGrid(p, c)
case toolkit.Flag:
log(debugFlag, "plugin Send() flag parent =", p.Name, p.Type)
log(debugFlag, "plugin Send() flag child =", c.Name, c.Type)
log(debugFlag, "plugin Send() flag child.Action =", c.Action)
log(debugFlag, "plugin Send() flag child.S =", c.S)
log(debugFlag, "plugin Send() flag child.B =", c.B)
log(debugFlag, "plugin Send() what to flag?")
// should set the checkbox to this value
switch c.S {
case "Error":
debugError = c.B
case "Toolkit":
debugToolkit = c.B
case "Change":
debugChange = c.B
case "Show":
ShowDebug()
default:
log(debugError, "Can't set unknown flag", c.S)
}
default: default:
log(true, "unknown parent =", p.Name, p.Type) log(true, "plugin Send() unknown parent =", p.Name, p.Type)
log(true, "unknown child =", c.Name, c.Type) log(true, "plugin Send() unknown child =", c.Name, c.Type)
log(true, "Don't know how to do", c.Type, "yet") log(true, "plugin Send() Don't know how to do", c.Type, "yet")
} }
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

View File

@ -7,7 +7,7 @@ import (
_ "github.com/andlabs/ui/winmanifest" _ "github.com/andlabs/ui/winmanifest"
) )
func (t andlabsT) newSlider(w *toolkit.Widget) *andlabsT { func (t *andlabsT) newSlider(w *toolkit.Widget) *andlabsT {
// make new node here // make new node here
log(debugToolkit, w.Name, w.Type, w.X, w.Y) log(debugToolkit, w.Name, w.Type, w.X, w.Y)
var newt andlabsT var newt andlabsT
@ -26,6 +26,7 @@ func (t andlabsT) newSlider(w *toolkit.Widget) *andlabsT {
t.uiBox.Append(s, stretchy) t.uiBox.Append(s, stretchy)
s.OnChanged(func(spin *ui.Slider) { s.OnChanged(func(spin *ui.Slider) {
newt.tw.I = newt.uiSlider.Value()
newt.commonChange(newt.tw) newt.commonChange(newt.tw)
}) })

View File

@ -7,7 +7,7 @@ import (
_ "github.com/andlabs/ui/winmanifest" _ "github.com/andlabs/ui/winmanifest"
) )
func (t andlabsT) newSpinner(w *toolkit.Widget) *andlabsT { func (t *andlabsT) newSpinner(w *toolkit.Widget) *andlabsT {
// make new node here // make new node here
log(debugToolkit, "newSpinner()", w.X, w.Y) log(debugToolkit, "newSpinner()", w.X, w.Y)
var newt andlabsT var newt andlabsT
@ -24,6 +24,7 @@ func (t andlabsT) newSpinner(w *toolkit.Widget) *andlabsT {
t.uiBox.Append(s, stretchy) t.uiBox.Append(s, stretchy)
s.OnChanged(func(s *ui.Spinbox) { s.OnChanged(func(s *ui.Spinbox) {
newt.tw.I = newt.uiSpinbox.Value()
newt.commonChange(newt.tw) newt.commonChange(newt.tw)
}) })

View File

@ -28,9 +28,9 @@ type andlabsT struct {
uiSpinbox *ui.Spinbox uiSpinbox *ui.Spinbox
uiTab *ui.Tab uiTab *ui.Tab
uiWindow *ui.Window uiWindow *ui.Window
// UiWindowBad *ui.Window // erase this
uiMultilineEntry *ui.MultilineEntry uiMultilineEntry *ui.MultilineEntry
uiEditableCombobox *ui.EditableCombobox uiEditableCombobox *ui.EditableCombobox
uiGrid *ui.Grid
// used as a counter to work around limitations of widgets like combobox // 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 // this is probably fucked up and in many ways wrong because of unsafe goroutine threading

View File

@ -63,7 +63,7 @@ func tabSetMargined(tab *ui.Tab) {
} }
func rawTab(w *ui.Window, name string) *andlabsT { func rawTab(w *ui.Window, name string) *andlabsT {
var t andlabsT var newt andlabsT
log(debugToolkit, "gui.toolkit.NewTab() ADD", name) log(debugToolkit, "gui.toolkit.NewTab() ADD", name)
if (w == nil) { if (w == nil) {
@ -83,10 +83,10 @@ func rawTab(w *ui.Window, name string) *andlabsT {
tabSetMargined(tab) // TODO: run this in the right place(?) tabSetMargined(tab) // TODO: run this in the right place(?)
w.SetChild(tab) w.SetChild(tab)
t.uiWindow = w newt.uiWindow = w
t.uiTab = tab newt.uiTab = tab
t.uiBox = hbox newt.uiBox = hbox
return &t return &newt
} }
func (t *andlabsT) appendTab(name string) *andlabsT { func (t *andlabsT) appendTab(name string) *andlabsT {

View File

@ -1,9 +1,11 @@
package main package main
import "git.wit.org/wit/gui/toolkit" import (
"git.wit.org/wit/gui/toolkit"
import "github.com/andlabs/ui" "github.com/andlabs/ui"
import _ "github.com/andlabs/ui/winmanifest" _ "github.com/andlabs/ui/winmanifest"
)
func newTextbox(parentW *toolkit.Widget, w *toolkit.Widget) { func newTextbox(parentW *toolkit.Widget, w *toolkit.Widget) {
log(debugToolkit, "NewTexbox()", w.Name) log(debugToolkit, "NewTexbox()", w.Name)
@ -15,8 +17,9 @@ func newTextbox(parentW *toolkit.Widget, w *toolkit.Widget) {
log(debugError, "FFFFFFFFFFFF listMap()") log(debugError, "FFFFFFFFFFFF listMap()")
log(debugError, "FFFFFFFFFFFF listMap()") log(debugError, "FFFFFFFFFFFF listMap()")
} }
// t.NewTextbox(w) // t.NewTextbox(w)
// func (t andlabsT) NewTextbox(w *toolkit.Widget) *andlabsT { // func (t *andlabsT) NewTextbox(w *toolkit.Widget) *andlabsT {
var newt *andlabsT var newt *andlabsT
newt = new(andlabsT) newt = new(andlabsT)
@ -37,6 +40,41 @@ func newTextbox(parentW *toolkit.Widget, w *toolkit.Widget) {
t.uiBox.Append(c, stretchy) t.uiBox.Append(c, stretchy)
} }
/*
// don't bother with "images" on andlabs/ui
"image"
"bytes"
_ "image/png"
"image/draw"
if (w.Name == "image") {
log(true, "NewTextbox() trying to add a new image")
i := ui.NewImage(16, 16)
img, _, err := image.Decode(bytes.NewReader(rawImage))
if err != nil {
panic(err)
}
nr, ok := img.(*image.RGBA)
if !ok {
i2 := image.NewRGBA(img.Bounds())
draw.Draw(i2, i2.Bounds(), img, img.Bounds().Min, draw.Src)
nr = i2
}
i.Append(nr)
t.uiBox.Append(i, true)
var img *ui.Image
var icon []byte
var imgA image.Image
icon, _ = res.ReadFile("resources/ping6.working.png")
// imgA, _, err := image.Decode(bytes.NewReader(b))
imgA, _, _ = image.Decode(icon)
img.Append(imgA)
img.Append(icon)
}
*/
c.OnChanged(func(spin *ui.MultilineEntry) { c.OnChanged(func(spin *ui.MultilineEntry) {
w.S = newt.uiMultilineEntry.Text() w.S = newt.uiMultilineEntry.Text()
// this is still dangerous // this is still dangerous
@ -81,9 +119,21 @@ func (t *andlabsT) doSimpleAction() {
log(debugChange, "Going to attempt:", t.tw.Action) log(debugChange, "Going to attempt:", t.tw.Action)
switch t.tw.Action { switch t.tw.Action {
case "Enable": case "Enable":
t.uiMultilineEntry.Enable() if (t.uiEntry != nil) {
t.uiEntry.Enable()
} else if (t.uiMultilineEntry != nil) {
t.uiMultilineEntry.Enable()
} else {
log(true, "don't know what to enable", t.Name)
}
case "Disable": case "Disable":
t.uiMultilineEntry.Disable() if (t.uiEntry != nil) {
t.uiEntry.Disable()
} else if (t.uiMultilineEntry != nil) {
t.uiMultilineEntry.Disable()
} else {
log(true, "don't know what to disable", t.Name)
}
case "Show": case "Show":
t.uiMultilineEntry.Show() t.uiMultilineEntry.Show()
case "Hide": case "Hide":

View File

@ -56,10 +56,13 @@ const (
Button Button
Checkbox Checkbox
Dropdown Dropdown
Combobox
Label Label
Textbox Textbox
Slider Slider
Spinner Spinner
Grid
Flag
) )
func (s WidgetType) String() string { func (s WidgetType) String() string {
@ -78,6 +81,8 @@ func (s WidgetType) String() string {
return "Checkbox" return "Checkbox"
case Dropdown: case Dropdown:
return "Dropdown" return "Dropdown"
case Combobox:
return "Combobox"
case Label: case Label:
return "Label" return "Label"
case Textbox: case Textbox:
@ -86,6 +91,10 @@ func (s WidgetType) String() string {
return "Slider" return "Slider"
case Spinner: case Spinner:
return "Spinner" return "Spinner"
case Grid:
return "Grid"
case Flag:
return "Flag"
case Unknown: case Unknown:
return "Unknown" return "Unknown"
} }