gocui: debug flag buttons work

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2023-04-06 18:26:30 -05:00
parent bddce3d5a3
commit 7cf0d45909
3 changed files with 37 additions and 8 deletions

View File

@ -137,7 +137,7 @@ Creates a window helpful for debugging this package
loads and initializes a toolkit (andlabs/ui, gocui, etc)
### func [Main](/main.go#L143)
### func [Main](/main.go#L170)
`func Main(f func())`
@ -159,7 +159,7 @@ This should not pass a function
`func ShowDebugValues()`
### func [StandardExit](/main.go#L204)
### func [StandardExit](/main.go#L231)
`func StandardExit()`
@ -252,7 +252,7 @@ You get a window
`func Start() *Node`
#### func [StartS](/main.go#L129)
#### func [StartS](/main.go#L156)
`func StartS(name string) *Node`

View File

@ -9,12 +9,14 @@ func (n *Node) NewButton(name string, custom func()) *Node {
a.Name = name
a.Text = name
a.ActionType = toolkit.Add
// deprecate this once andlabs is refactored
a.Callback = callback
newaction(&a, newNode, n)
return newNode
}
// deprecate this once andlabs is refactored
func callback(i int) bool {
log(debugError, "callback() for widget id =", i)
n := Config.rootNode.FindId(i)

37
main.go
View File

@ -104,10 +104,6 @@ func Start() *Node {
return Config.rootNode
}
func doSomething() {
log(logNow, "doSomething()")
}
func watchCallback() {
log(logNow, "makeCallback() START")
for {
@ -115,11 +111,42 @@ func watchCallback() {
select {
case a := <-Config.guiChan:
log(logNow, "makeCallback() SELECT widget id =", a.WidgetId, a.Name)
sleep(.5) // TODO: remove this. added while under development
n := Config.rootNode.FindId(a.WidgetId)
if (n == nil) {
log(logError, "makeCallback() SELECT widget id =", a.WidgetId, a.Name)
} else {
go n.doUserEvent(a)
}
// this maybe a good idea?
// TODO: Throttle user events somehow
sleep(.1)
}
}
}
func (n *Node) doUserEvent(a toolkit.Action) {
log(logNow, "doUserEvent() node =", n.id, n.Name)
switch n.WidgetType {
case toolkit.Checkbox:
n.B = a.B
log(logNow, "doUserEvent() Check =", n.id, n.Name, n.B)
if (n.Custom == nil) {
log(debugError, "Custom() = nil. SKIPPING")
return
}
n.Custom()
case toolkit.Button:
log(logNow, "doUserEvent() button =", n.id, n.Name)
if (n.Custom == nil) {
log(debugError, "Custom() = nil. SKIPPING")
return
}
n.Custom()
default:
log(logNow, "doUserEvent() type =", n.WidgetType)
}
}
func (n *Node) LoadPlugin(name string) bool {
StartS(name)
Redraw(name)