andlabs: use callback channel for window close

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2023-04-06 19:48:24 -05:00
parent 9041a6552e
commit 8045287501
7 changed files with 40 additions and 15 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#L170)
### func [Main](/main.go#L177)
`func Main(f func())`
@ -159,7 +159,7 @@ This should not pass a function
`func ShowDebugValues()`
### func [StandardExit](/main.go#L231)
### func [StandardExit](/main.go#L238)
`func StandardExit()`
@ -252,7 +252,7 @@ You get a window
`func Start() *Node`
#### func [StartS](/main.go#L156)
#### func [StartS](/main.go#L163)
`func StartS(name string) *Node`

View File

@ -142,6 +142,13 @@ func (n *Node) doUserEvent(a toolkit.Action) {
return
}
n.Custom()
case toolkit.Window:
log(logNow, "doUserEvent() window =", n.id, n.Name)
if (n.Custom == nil) {
log(debugError, "Custom() = nil. SKIPPING")
return
}
n.Custom()
default:
log(logNow, "doUserEvent() type =", n.WidgetType)
}

View File

@ -6,10 +6,10 @@ import (
func (t *andlabsT) commonChange(tw *toolkit.Widget, wId int) {
log(debugChange, "commonChange() START widget =", t.Name, t.WidgetType)
if (sendToChan(wId)) {
log(debugChange, "commonChange() END attempted channel worked", t.Name, t.WidgetType)
return
}
// if (sendToChan(wId)) {
// log(debugChange, "commonChange() END attempted channel worked", t.Name, t.WidgetType)
// return
// }
if (tw == nil) {
log(true, "commonChange() What the fuck. there is no widget t.tw == nil")
return
@ -28,11 +28,20 @@ func (t *andlabsT) commonChange(tw *toolkit.Widget, wId int) {
log(debugChange, "commonChange() END Widget.Custom()", t.Name, t.WidgetType)
}
func sendToChan(i int) bool {
func (t *andlabsT) doUserEvent() {
if (callback == nil) {
log(debugError, "commonChange() SHOULD SEND int back here, but callback == nil", i)
return false
log(debugError, "douserEvent() callback == nil", t.wId)
return
}
log(debugError, "commonChange() Running callback() i =", i)
return callback(i)
var a toolkit.Action
a.WidgetId = t.wId
a.Name = t.Name
a.S = t.s
a.I = t.i
a.B = t.b
a.ActionType = toolkit.User
log(logNow, "START: send a user event to the callback channel")
callback <- a
log(logNow, "END: sent a user event to the callback channel")
return
}

View File

@ -2,7 +2,7 @@ package main
import (
"embed"
// "git.wit.org/wit/gui/toolkit"
"git.wit.org/wit/gui/toolkit"
"github.com/andlabs/ui"
// the _ means we only need this for the init()
@ -22,6 +22,11 @@ func Main(f func()) {
})
}
// this sets the channel to send user events back from the plugin
func Callback(guiCallback chan toolkit.Action) {
callback = guiCallback
}
// Other goroutines must use this to access the GUI
//
// You can not acess / process the GUI thread directly from

View File

@ -31,12 +31,14 @@ func Action(a *toolkit.Action) {
rawAction(a)
}
/*
if (callback == nil) {
if (a.Callback != nil) {
log(debugNow, "setting Callback", a.Callback)
callback = a.Callback
}
}
*/
// f()
Queue(f)

View File

@ -6,7 +6,8 @@ import "github.com/andlabs/ui"
import _ "github.com/andlabs/ui/winmanifest"
var andlabs map[int]*andlabsT
var callback func(int) bool
// var callback func(int) bool
var callback chan toolkit.Action
// stores the raw toolkit internals
type andlabsT struct {

View File

@ -27,7 +27,8 @@ func newWindow(a *toolkit.Action) {
win.SetBorderless(canvas)
win.SetMargined(margin)
win.OnClosing(func(*ui.Window) bool {
newt.commonChange(newt.tw, a.WidgetId)
// newt.commonChange(newt.tw, a.WidgetId)
newt.doUserEvent()
return true
})
win.Show()