andlabs: use callback channel for window close
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
9041a6552e
commit
8045287501
|
@ -137,7 +137,7 @@ Creates a window helpful for debugging this package
|
||||||
|
|
||||||
loads and initializes a toolkit (andlabs/ui, gocui, etc)
|
loads and initializes a toolkit (andlabs/ui, gocui, etc)
|
||||||
|
|
||||||
### func [Main](/main.go#L170)
|
### func [Main](/main.go#L177)
|
||||||
|
|
||||||
`func Main(f func())`
|
`func Main(f func())`
|
||||||
|
|
||||||
|
@ -159,7 +159,7 @@ This should not pass a function
|
||||||
|
|
||||||
`func ShowDebugValues()`
|
`func ShowDebugValues()`
|
||||||
|
|
||||||
### func [StandardExit](/main.go#L231)
|
### func [StandardExit](/main.go#L238)
|
||||||
|
|
||||||
`func StandardExit()`
|
`func StandardExit()`
|
||||||
|
|
||||||
|
@ -252,7 +252,7 @@ You get a window
|
||||||
|
|
||||||
`func Start() *Node`
|
`func Start() *Node`
|
||||||
|
|
||||||
#### func [StartS](/main.go#L156)
|
#### func [StartS](/main.go#L163)
|
||||||
|
|
||||||
`func StartS(name string) *Node`
|
`func StartS(name string) *Node`
|
||||||
|
|
||||||
|
|
7
main.go
7
main.go
|
@ -142,6 +142,13 @@ func (n *Node) doUserEvent(a toolkit.Action) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
n.Custom()
|
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:
|
default:
|
||||||
log(logNow, "doUserEvent() type =", n.WidgetType)
|
log(logNow, "doUserEvent() type =", n.WidgetType)
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,10 +6,10 @@ import (
|
||||||
|
|
||||||
func (t *andlabsT) commonChange(tw *toolkit.Widget, wId int) {
|
func (t *andlabsT) commonChange(tw *toolkit.Widget, wId int) {
|
||||||
log(debugChange, "commonChange() START widget =", t.Name, t.WidgetType)
|
log(debugChange, "commonChange() START widget =", t.Name, t.WidgetType)
|
||||||
if (sendToChan(wId)) {
|
// if (sendToChan(wId)) {
|
||||||
log(debugChange, "commonChange() END attempted channel worked", t.Name, t.WidgetType)
|
// log(debugChange, "commonChange() END attempted channel worked", t.Name, t.WidgetType)
|
||||||
return
|
// return
|
||||||
}
|
// }
|
||||||
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")
|
||||||
return
|
return
|
||||||
|
@ -28,11 +28,20 @@ func (t *andlabsT) commonChange(tw *toolkit.Widget, wId int) {
|
||||||
log(debugChange, "commonChange() END Widget.Custom()", t.Name, t.WidgetType)
|
log(debugChange, "commonChange() END Widget.Custom()", t.Name, t.WidgetType)
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendToChan(i int) bool {
|
func (t *andlabsT) doUserEvent() {
|
||||||
if (callback == nil) {
|
if (callback == nil) {
|
||||||
log(debugError, "commonChange() SHOULD SEND int back here, but callback == nil", i)
|
log(debugError, "douserEvent() callback == nil", t.wId)
|
||||||
return false
|
return
|
||||||
}
|
}
|
||||||
log(debugError, "commonChange() Running callback() i =", i)
|
var a toolkit.Action
|
||||||
return callback(i)
|
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
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"embed"
|
"embed"
|
||||||
// "git.wit.org/wit/gui/toolkit"
|
"git.wit.org/wit/gui/toolkit"
|
||||||
|
|
||||||
"github.com/andlabs/ui"
|
"github.com/andlabs/ui"
|
||||||
// the _ means we only need this for the init()
|
// 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
|
// Other goroutines must use this to access the GUI
|
||||||
//
|
//
|
||||||
// You can not acess / process the GUI thread directly from
|
// You can not acess / process the GUI thread directly from
|
||||||
|
|
|
@ -31,12 +31,14 @@ func Action(a *toolkit.Action) {
|
||||||
rawAction(a)
|
rawAction(a)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
if (callback == nil) {
|
if (callback == nil) {
|
||||||
if (a.Callback != nil) {
|
if (a.Callback != nil) {
|
||||||
log(debugNow, "setting Callback", a.Callback)
|
log(debugNow, "setting Callback", a.Callback)
|
||||||
callback = a.Callback
|
callback = a.Callback
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// f()
|
// f()
|
||||||
Queue(f)
|
Queue(f)
|
||||||
|
|
|
@ -6,7 +6,8 @@ import "github.com/andlabs/ui"
|
||||||
import _ "github.com/andlabs/ui/winmanifest"
|
import _ "github.com/andlabs/ui/winmanifest"
|
||||||
|
|
||||||
var andlabs map[int]*andlabsT
|
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
|
// stores the raw toolkit internals
|
||||||
type andlabsT struct {
|
type andlabsT struct {
|
||||||
|
|
|
@ -27,7 +27,8 @@ func newWindow(a *toolkit.Action) {
|
||||||
win.SetBorderless(canvas)
|
win.SetBorderless(canvas)
|
||||||
win.SetMargined(margin)
|
win.SetMargined(margin)
|
||||||
win.OnClosing(func(*ui.Window) bool {
|
win.OnClosing(func(*ui.Window) bool {
|
||||||
newt.commonChange(newt.tw, a.WidgetId)
|
// newt.commonChange(newt.tw, a.WidgetId)
|
||||||
|
newt.doUserEvent()
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
win.Show()
|
win.Show()
|
||||||
|
|
Loading…
Reference in New Issue