andlabs: callback is now safe through a go channel
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
8045287501
commit
45d43c3616
|
@ -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#L177)
|
### func [Main](/main.go#L194)
|
||||||
|
|
||||||
`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#L238)
|
### func [StandardExit](/main.go#L255)
|
||||||
|
|
||||||
`func StandardExit()`
|
`func StandardExit()`
|
||||||
|
|
||||||
|
@ -252,7 +252,7 @@ You get a window
|
||||||
|
|
||||||
`func Start() *Node`
|
`func Start() *Node`
|
||||||
|
|
||||||
#### func [StartS](/main.go#L163)
|
#### func [StartS](/main.go#L180)
|
||||||
|
|
||||||
`func StartS(name string) *Node`
|
`func StartS(name string) *Node`
|
||||||
|
|
||||||
|
|
|
@ -110,10 +110,10 @@ func dropdownWindow(p *Node) {
|
||||||
|
|
||||||
dd := p.NewDropdown("Window Dropdown")
|
dd := p.NewDropdown("Window Dropdown")
|
||||||
dd.Custom = func() {
|
dd.Custom = func() {
|
||||||
name := dd.widget.S
|
name := dd.S
|
||||||
activeWidget = mapWindows[name]
|
activeWidget = mapWindows[name]
|
||||||
setActiveWidget(activeWidget)
|
setActiveWidget(activeWidget)
|
||||||
log("The Window was set to", name)
|
log(true, "The Window was set to", name)
|
||||||
}
|
}
|
||||||
log(debugGui, "dd =", dd)
|
log(debugGui, "dd =", dd)
|
||||||
if (activeWidget == nil) {
|
if (activeWidget == nil) {
|
||||||
|
|
53
main.go
53
main.go
|
@ -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) {
|
func (n *Node) doUserEvent(a toolkit.Action) {
|
||||||
log(logNow, "doUserEvent() node =", n.id, n.Name)
|
log(logNow, "doUserEvent() node =", n.id, n.Name)
|
||||||
switch n.WidgetType {
|
switch n.WidgetType {
|
||||||
case toolkit.Checkbox:
|
case toolkit.Checkbox:
|
||||||
n.B = a.B
|
n.B = a.B
|
||||||
log(logNow, "doUserEvent() Check =", n.id, n.Name, n.B)
|
log(logNow, "doUserEvent() node =", n.id, n.Name, "set to:", n.B)
|
||||||
if (n.Custom == nil) {
|
n.doCustom()
|
||||||
log(debugError, "Custom() = nil. SKIPPING")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
n.Custom()
|
|
||||||
case toolkit.Button:
|
case toolkit.Button:
|
||||||
log(logNow, "doUserEvent() button =", n.id, n.Name)
|
log(logNow, "doUserEvent() node =", n.id, n.Name, "button clicked")
|
||||||
if (n.Custom == nil) {
|
n.doCustom()
|
||||||
log(debugError, "Custom() = nil. SKIPPING")
|
case toolkit.Combobox:
|
||||||
return
|
n.S = a.S
|
||||||
}
|
log(logNow, "doUserEvent() node =", n.id, n.Name, "set to:", n.S)
|
||||||
n.Custom()
|
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:
|
case toolkit.Window:
|
||||||
log(logNow, "doUserEvent() window =", n.id, n.Name)
|
log(logNow, "doUserEvent() node =", n.id, n.Name, "window closed")
|
||||||
if (n.Custom == nil) {
|
n.doCustom()
|
||||||
log(debugError, "Custom() = nil. SKIPPING")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
n.Custom()
|
|
||||||
default:
|
default:
|
||||||
log(logNow, "doUserEvent() type =", n.WidgetType)
|
log(logNow, "doUserEvent() type =", n.WidgetType)
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,14 +23,15 @@ func newButton(a *toolkit.Action) {
|
||||||
b = ui.NewButton(a.Text)
|
b = ui.NewButton(a.Text)
|
||||||
newt.uiButton = b
|
newt.uiButton = b
|
||||||
newt.uiControl = b
|
newt.uiControl = b
|
||||||
newt.tw = a.Widget
|
newt.wId = a.WidgetId
|
||||||
|
// newt.tw = a.Widget
|
||||||
newt.WidgetType = a.WidgetType
|
newt.WidgetType = a.WidgetType
|
||||||
newt.parent = t
|
newt.parent = t
|
||||||
|
|
||||||
|
place(a, t, newt)
|
||||||
|
|
||||||
b.OnClicked(func(*ui.Button) {
|
b.OnClicked(func(*ui.Button) {
|
||||||
newt.commonChange(newt.tw, a.WidgetId)
|
newt.doUserEvent()
|
||||||
})
|
})
|
||||||
|
|
||||||
place(a, t, newt)
|
|
||||||
// mapWidgetsToolkits(a, newt)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,9 +20,9 @@ func (t *andlabsT) newCheckbox(a *toolkit.Action) *andlabsT {
|
||||||
newt.uiControl = newt.uiCheckbox
|
newt.uiControl = newt.uiCheckbox
|
||||||
|
|
||||||
newt.uiCheckbox.OnToggled(func(spin *ui.Checkbox) {
|
newt.uiCheckbox.OnToggled(func(spin *ui.Checkbox) {
|
||||||
newt.tw.B = newt.checked()
|
newt.b = newt.checked()
|
||||||
log(debugChange, "val =", newt.tw.B)
|
log(debugChange, "val =", newt.tw.B)
|
||||||
newt.commonChange(newt.tw, a.WidgetId)
|
newt.doUserEvent()
|
||||||
})
|
})
|
||||||
|
|
||||||
return &newt
|
return &newt
|
||||||
|
|
|
@ -8,10 +8,8 @@ import (
|
||||||
|
|
||||||
func (t *andlabsT) newCombobox(a *toolkit.Action) *andlabsT {
|
func (t *andlabsT) newCombobox(a *toolkit.Action) *andlabsT {
|
||||||
var newt andlabsT
|
var newt andlabsT
|
||||||
w := a.Widget
|
|
||||||
log(debugToolkit, "newCombobox() START", a.Name)
|
log(debugToolkit, "newCombobox() START", a.Name)
|
||||||
|
|
||||||
newt.tw = w
|
|
||||||
newt.wId = a.WidgetId
|
newt.wId = a.WidgetId
|
||||||
newt.WidgetType = a.WidgetType
|
newt.WidgetType = a.WidgetType
|
||||||
s := ui.NewEditableCombobox()
|
s := ui.NewEditableCombobox()
|
||||||
|
@ -23,8 +21,8 @@ func (t *andlabsT) newCombobox(a *toolkit.Action) *andlabsT {
|
||||||
newt.val = make(map[int]string)
|
newt.val = make(map[int]string)
|
||||||
|
|
||||||
s.OnChanged(func(spin *ui.EditableCombobox) {
|
s.OnChanged(func(spin *ui.EditableCombobox) {
|
||||||
newt.tw.S = spin.Text()
|
newt.s = spin.Text()
|
||||||
newt.commonChange(newt.tw, a.WidgetId)
|
newt.doUserEvent()
|
||||||
})
|
})
|
||||||
|
|
||||||
return &newt
|
return &newt
|
||||||
|
|
|
@ -4,33 +4,9 @@ import (
|
||||||
"git.wit.org/wit/gui/toolkit"
|
"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() {
|
func (t *andlabsT) doUserEvent() {
|
||||||
if (callback == nil) {
|
if (callback == nil) {
|
||||||
log(debugError, "douserEvent() callback == nil", t.wId)
|
log(debugError, "doUserEvent() callback == nil", t.wId)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var a toolkit.Action
|
var a toolkit.Action
|
||||||
|
@ -40,8 +16,8 @@ func (t *andlabsT) doUserEvent() {
|
||||||
a.I = t.i
|
a.I = t.i
|
||||||
a.B = t.b
|
a.B = t.b
|
||||||
a.ActionType = toolkit.User
|
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
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,8 +28,8 @@ func (t *andlabsT) newDropdown(a *toolkit.Action) *andlabsT {
|
||||||
log(debugChange, "make map didn't work")
|
log(debugChange, "make map didn't work")
|
||||||
newt.text = "error"
|
newt.text = "error"
|
||||||
}
|
}
|
||||||
newt.tw.S = newt.val[i]
|
newt.s = newt.val[i]
|
||||||
newt.commonChange(newt.tw, a.WidgetId)
|
newt.doUserEvent()
|
||||||
})
|
})
|
||||||
|
|
||||||
return &newt
|
return &newt
|
||||||
|
|
|
@ -19,8 +19,8 @@ func (t *andlabsT) newSlider(a *toolkit.Action) *andlabsT {
|
||||||
newt.wId = a.WidgetId
|
newt.wId = a.WidgetId
|
||||||
|
|
||||||
s.OnChanged(func(spin *ui.Slider) {
|
s.OnChanged(func(spin *ui.Slider) {
|
||||||
newt.tw.I = newt.uiSlider.Value()
|
newt.i = newt.uiSlider.Value()
|
||||||
newt.commonChange(newt.tw, a.WidgetId)
|
newt.doUserEvent()
|
||||||
})
|
})
|
||||||
|
|
||||||
return &newt
|
return &newt
|
||||||
|
|
|
@ -20,8 +20,8 @@ func (t *andlabsT) newSpinner(a *toolkit.Action) *andlabsT {
|
||||||
newt.WidgetType = toolkit.Spinner
|
newt.WidgetType = toolkit.Spinner
|
||||||
|
|
||||||
s.OnChanged(func(s *ui.Spinbox) {
|
s.OnChanged(func(s *ui.Spinbox) {
|
||||||
newt.tw.I = newt.uiSpinbox.Value()
|
newt.i = newt.uiSpinbox.Value()
|
||||||
newt.commonChange(newt.tw, a.WidgetId)
|
newt.doUserEvent()
|
||||||
})
|
})
|
||||||
|
|
||||||
return &newt
|
return &newt
|
||||||
|
|
|
@ -21,7 +21,6 @@ func (t *andlabsT) newTextbox(w *toolkit.Widget) *andlabsT {
|
||||||
c.OnChanged(func(spin *ui.MultilineEntry) {
|
c.OnChanged(func(spin *ui.MultilineEntry) {
|
||||||
t.s = spin.Text()
|
t.s = spin.Text()
|
||||||
// this is still dangerous
|
// this is still dangerous
|
||||||
// newt.commonChange(newt.tw)
|
|
||||||
log(debugChange, "Not yet safe to trigger on change for ui.MultilineEntry")
|
log(debugChange, "Not yet safe to trigger on change for ui.MultilineEntry")
|
||||||
})
|
})
|
||||||
return &newt
|
return &newt
|
||||||
|
|
|
@ -27,7 +27,6 @@ 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.doUserEvent()
|
newt.doUserEvent()
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue