andlabs: callback is now safe through a go channel

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2023-04-06 20:25:14 -05:00
parent 8045287501
commit 45d43c3616
12 changed files with 58 additions and 68 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#L177)
### func [Main](/main.go#L194)
`func Main(f func())`
@ -159,7 +159,7 @@ This should not pass a function
`func ShowDebugValues()`
### func [StandardExit](/main.go#L238)
### func [StandardExit](/main.go#L255)
`func StandardExit()`
@ -252,7 +252,7 @@ You get a window
`func Start() *Node`
#### func [StartS](/main.go#L163)
#### func [StartS](/main.go#L180)
`func StartS(name string) *Node`

View File

@ -110,10 +110,10 @@ func dropdownWindow(p *Node) {
dd := p.NewDropdown("Window Dropdown")
dd.Custom = func() {
name := dd.widget.S
name := dd.S
activeWidget = mapWindows[name]
setActiveWidget(activeWidget)
log("The Window was set to", name)
log(true, "The Window was set to", name)
}
log(debugGui, "dd =", dd)
if (activeWidget == nil) {

53
main.go
View File

@ -124,31 +124,48 @@ func watchCallback() {
}
}
func (n *Node) doCustom() {
log(logNow, "doUserEvent() widget =", n.id, n.Name, n.WidgetType, n.B)
if (n.Custom == nil) {
log(debugError, "Custom() = nil. SKIPPING")
return
}
n.Custom()
}
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()
log(logNow, "doUserEvent() node =", n.id, n.Name, "set to:", n.B)
n.doCustom()
case toolkit.Button:
log(logNow, "doUserEvent() button =", n.id, n.Name)
if (n.Custom == nil) {
log(debugError, "Custom() = nil. SKIPPING")
return
}
n.Custom()
log(logNow, "doUserEvent() node =", n.id, n.Name, "button clicked")
n.doCustom()
case toolkit.Combobox:
n.S = a.S
log(logNow, "doUserEvent() node =", n.id, n.Name, "set to:", n.S)
n.doCustom()
case toolkit.Dropdown:
n.S = a.S
log(logNow, "doUserEvent() node =", n.id, n.Name, "set to:", n.S)
n.doCustom()
case toolkit.Textbox:
n.S = a.S
log(logNow, "doUserEvent() node =", n.id, n.Name, "set to:", n.S)
n.doCustom()
case toolkit.Spinner:
n.I = a.I
log(logNow, "doUserEvent() node =", n.id, n.Name, "set to:", n.I)
n.doCustom()
case toolkit.Slider:
n.I = a.I
log(logNow, "doUserEvent() node =", n.id, n.Name, "set to:", n.I)
n.doCustom()
case toolkit.Window:
log(logNow, "doUserEvent() window =", n.id, n.Name)
if (n.Custom == nil) {
log(debugError, "Custom() = nil. SKIPPING")
return
}
n.Custom()
log(logNow, "doUserEvent() node =", n.id, n.Name, "window closed")
n.doCustom()
default:
log(logNow, "doUserEvent() type =", n.WidgetType)
}

View File

@ -23,14 +23,15 @@ func newButton(a *toolkit.Action) {
b = ui.NewButton(a.Text)
newt.uiButton = b
newt.uiControl = b
newt.tw = a.Widget
newt.wId = a.WidgetId
// newt.tw = a.Widget
newt.WidgetType = a.WidgetType
newt.parent = t
place(a, t, newt)
b.OnClicked(func(*ui.Button) {
newt.commonChange(newt.tw, a.WidgetId)
newt.doUserEvent()
})
place(a, t, newt)
// mapWidgetsToolkits(a, newt)
}

View File

@ -20,9 +20,9 @@ func (t *andlabsT) newCheckbox(a *toolkit.Action) *andlabsT {
newt.uiControl = newt.uiCheckbox
newt.uiCheckbox.OnToggled(func(spin *ui.Checkbox) {
newt.tw.B = newt.checked()
newt.b = newt.checked()
log(debugChange, "val =", newt.tw.B)
newt.commonChange(newt.tw, a.WidgetId)
newt.doUserEvent()
})
return &newt

View File

@ -8,10 +8,8 @@ import (
func (t *andlabsT) newCombobox(a *toolkit.Action) *andlabsT {
var newt andlabsT
w := a.Widget
log(debugToolkit, "newCombobox() START", a.Name)
newt.tw = w
newt.wId = a.WidgetId
newt.WidgetType = a.WidgetType
s := ui.NewEditableCombobox()
@ -23,8 +21,8 @@ func (t *andlabsT) newCombobox(a *toolkit.Action) *andlabsT {
newt.val = make(map[int]string)
s.OnChanged(func(spin *ui.EditableCombobox) {
newt.tw.S = spin.Text()
newt.commonChange(newt.tw, a.WidgetId)
newt.s = spin.Text()
newt.doUserEvent()
})
return &newt

View File

@ -4,33 +4,9 @@ import (
"git.wit.org/wit/gui/toolkit"
)
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 (tw == nil) {
log(true, "commonChange() What the fuck. there is no widget t.tw == nil")
return
}
if (tw.Custom == nil) {
log(debugChange, "commonChange() END Widget.Custom() = nil", t.Name, t.WidgetType)
return
}
tw.Custom()
if (andlabs[wId] == nil) {
log(debugError, "commonChange() ERROR: wId map == nil", wId)
return
}
log(debugChange, "commonChange() END Widget.Custom()", t.Name, t.WidgetType)
}
func (t *andlabsT) doUserEvent() {
if (callback == nil) {
log(debugError, "douserEvent() callback == nil", t.wId)
log(debugError, "doUserEvent() callback == nil", t.wId)
return
}
var a toolkit.Action
@ -40,8 +16,8 @@ func (t *andlabsT) doUserEvent() {
a.I = t.i
a.B = t.b
a.ActionType = toolkit.User
log(logNow, "START: send a user event to the callback channel")
log(logInfo, "doUserEvent() START: send a user event to the callback channel")
callback <- a
log(logNow, "END: sent a user event to the callback channel")
log(logInfo, "doUserEvent() END: sent a user event to the callback channel")
return
}

View File

@ -28,8 +28,8 @@ func (t *andlabsT) newDropdown(a *toolkit.Action) *andlabsT {
log(debugChange, "make map didn't work")
newt.text = "error"
}
newt.tw.S = newt.val[i]
newt.commonChange(newt.tw, a.WidgetId)
newt.s = newt.val[i]
newt.doUserEvent()
})
return &newt

View File

@ -19,8 +19,8 @@ func (t *andlabsT) newSlider(a *toolkit.Action) *andlabsT {
newt.wId = a.WidgetId
s.OnChanged(func(spin *ui.Slider) {
newt.tw.I = newt.uiSlider.Value()
newt.commonChange(newt.tw, a.WidgetId)
newt.i = newt.uiSlider.Value()
newt.doUserEvent()
})
return &newt

View File

@ -20,8 +20,8 @@ func (t *andlabsT) newSpinner(a *toolkit.Action) *andlabsT {
newt.WidgetType = toolkit.Spinner
s.OnChanged(func(s *ui.Spinbox) {
newt.tw.I = newt.uiSpinbox.Value()
newt.commonChange(newt.tw, a.WidgetId)
newt.i = newt.uiSpinbox.Value()
newt.doUserEvent()
})
return &newt

View File

@ -21,7 +21,6 @@ func (t *andlabsT) newTextbox(w *toolkit.Widget) *andlabsT {
c.OnChanged(func(spin *ui.MultilineEntry) {
t.s = spin.Text()
// this is still dangerous
// newt.commonChange(newt.tw)
log(debugChange, "Not yet safe to trigger on change for ui.MultilineEntry")
})
return &newt

View File

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