summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2023-04-06 20:25:14 -0500
committerJeff Carr <[email protected]>2023-04-06 20:25:14 -0500
commit933a7e4df0e6a28ad06dfd60ab2928d5cdf916f9 (patch)
tree268ad3d290b392f877963a6fdc82197168f51fc4
parent8649f37a56bc31928d69077545f1e323a794c61a (diff)
andlabs: callback is now safe through a go channel
Signed-off-by: Jeff Carr <[email protected]>
-rw-r--r--README-goreadme.md6
-rw-r--r--debugWindow.go4
-rw-r--r--main.go53
-rw-r--r--toolkit/andlabs/button.go9
-rw-r--r--toolkit/andlabs/checkbox.go4
-rw-r--r--toolkit/andlabs/combobox.go6
-rw-r--r--toolkit/andlabs/common.go30
-rw-r--r--toolkit/andlabs/dropdown.go4
-rw-r--r--toolkit/andlabs/slider.go4
-rw-r--r--toolkit/andlabs/spinner.go4
-rw-r--r--toolkit/andlabs/textbox.go1
-rw-r--r--toolkit/andlabs/window.go1
12 files changed, 58 insertions, 68 deletions
diff --git a/README-goreadme.md b/README-goreadme.md
index a2f91b8..96323d8 100644
--- a/README-goreadme.md
+++ b/README-goreadme.md
@@ -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`
diff --git a/debugWindow.go b/debugWindow.go
index bed630a..0677b92 100644
--- a/debugWindow.go
+++ b/debugWindow.go
@@ -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) {
diff --git a/main.go b/main.go
index 85d25aa..07cd420 100644
--- a/main.go
+++ b/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) {
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)
}
diff --git a/toolkit/andlabs/button.go b/toolkit/andlabs/button.go
index 94e2966..bc58da2 100644
--- a/toolkit/andlabs/button.go
+++ b/toolkit/andlabs/button.go
@@ -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)
}
diff --git a/toolkit/andlabs/checkbox.go b/toolkit/andlabs/checkbox.go
index 69ba060..e4987e1 100644
--- a/toolkit/andlabs/checkbox.go
+++ b/toolkit/andlabs/checkbox.go
@@ -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
diff --git a/toolkit/andlabs/combobox.go b/toolkit/andlabs/combobox.go
index 100434e..293cc42 100644
--- a/toolkit/andlabs/combobox.go
+++ b/toolkit/andlabs/combobox.go
@@ -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
diff --git a/toolkit/andlabs/common.go b/toolkit/andlabs/common.go
index d905e5c..cd8e9c8 100644
--- a/toolkit/andlabs/common.go
+++ b/toolkit/andlabs/common.go
@@ -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
}
diff --git a/toolkit/andlabs/dropdown.go b/toolkit/andlabs/dropdown.go
index 036ed3e..d49ef1c 100644
--- a/toolkit/andlabs/dropdown.go
+++ b/toolkit/andlabs/dropdown.go
@@ -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
diff --git a/toolkit/andlabs/slider.go b/toolkit/andlabs/slider.go
index ed96f98..3f92067 100644
--- a/toolkit/andlabs/slider.go
+++ b/toolkit/andlabs/slider.go
@@ -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
diff --git a/toolkit/andlabs/spinner.go b/toolkit/andlabs/spinner.go
index 46be999..cfc1e67 100644
--- a/toolkit/andlabs/spinner.go
+++ b/toolkit/andlabs/spinner.go
@@ -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
diff --git a/toolkit/andlabs/textbox.go b/toolkit/andlabs/textbox.go
index 6ea01e1..36a9777 100644
--- a/toolkit/andlabs/textbox.go
+++ b/toolkit/andlabs/textbox.go
@@ -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
diff --git a/toolkit/andlabs/window.go b/toolkit/andlabs/window.go
index 4b64b12..cfa419f 100644
--- a/toolkit/andlabs/window.go
+++ b/toolkit/andlabs/window.go
@@ -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
})