summaryrefslogtreecommitdiff
path: root/toolkit/andlabs
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2023-04-27 10:46:54 -0500
committerJeff Carr <[email protected]>2023-04-27 10:46:54 -0500
commit8100e7a1abdc31afbf65af6d0b7cd7cb0fff69eb (patch)
tree7722df0af4968b6fac7d2ea544296c8b8f7db1f4 /toolkit/andlabs
parente3dbd4b2074c80cc089e54495ff2df3f94afabab (diff)
andlabs: more code cleanup
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'toolkit/andlabs')
-rw-r--r--toolkit/andlabs/add.go6
-rw-r--r--toolkit/andlabs/combobox.go33
-rw-r--r--toolkit/andlabs/dropdown.go50
-rw-r--r--toolkit/andlabs/plugin.go14
-rw-r--r--toolkit/andlabs/textbox.go38
5 files changed, 46 insertions, 95 deletions
diff --git a/toolkit/andlabs/add.go b/toolkit/andlabs/add.go
index bebcfde..1bcead7 100644
--- a/toolkit/andlabs/add.go
+++ b/toolkit/andlabs/add.go
@@ -54,13 +54,13 @@ func add(a toolkit.Action) {
p.newSlider(n)
return
case toolkit.Dropdown:
- newDropdown(&a)
+ p.newDropdown(n)
return
case toolkit.Combobox:
- newCombobox(&a)
+ p.newCombobox(n)
return
case toolkit.Textbox:
- newTextbox(&a)
+ p.newTextbox(n)
return
case toolkit.Group:
p.newGroup(n)
diff --git a/toolkit/andlabs/combobox.go b/toolkit/andlabs/combobox.go
index 293cc42..06a7f41 100644
--- a/toolkit/andlabs/combobox.go
+++ b/toolkit/andlabs/combobox.go
@@ -3,29 +3,27 @@ package main
import (
"github.com/andlabs/ui"
_ "github.com/andlabs/ui/winmanifest"
- "git.wit.org/wit/gui/toolkit"
)
-func (t *andlabsT) newCombobox(a *toolkit.Action) *andlabsT {
- var newt andlabsT
- log(debugToolkit, "newCombobox() START", a.Name)
+func (p *node) newCombobox(n *node) {
+ newt := new(andlabsT)
+ log(debugToolkit, "newCombobox() START", n.Name)
- newt.wId = a.WidgetId
- newt.WidgetType = a.WidgetType
- s := ui.NewEditableCombobox()
- newt.uiEditableCombobox = s
- newt.uiControl = s
+ cb := ui.NewEditableCombobox()
+ newt.uiEditableCombobox = cb
+ newt.uiControl = cb
// initialize the index
newt.c = 0
newt.val = make(map[int]string)
- s.OnChanged(func(spin *ui.EditableCombobox) {
+ cb.OnChanged(func(spin *ui.EditableCombobox) {
newt.s = spin.Text()
newt.doUserEvent()
})
- return &newt
+ n.tk = newt
+ p.place(n)
}
func (t *andlabsT) AddComboboxName(title string) {
@@ -41,16 +39,3 @@ func (t *andlabsT) AddComboboxName(title string) {
// }
t.c = t.c + 1
}
-
-func newCombobox(a *toolkit.Action) {
- log(debugToolkit, "newCombobox()", a.Name)
-
- t := andlabs[a.ParentId]
- if (t == nil) {
- log(debugToolkit, "newCombobox() toolkit struct == nil. name=", a.Name)
- listMap(debugToolkit)
- return
- }
- newt := t.newCombobox(a)
- place(a, t, newt)
-}
diff --git a/toolkit/andlabs/dropdown.go b/toolkit/andlabs/dropdown.go
index 34e6d5c..fd28965 100644
--- a/toolkit/andlabs/dropdown.go
+++ b/toolkit/andlabs/dropdown.go
@@ -3,24 +3,23 @@ package main
import (
"github.com/andlabs/ui"
_ "github.com/andlabs/ui/winmanifest"
+
"git.wit.org/wit/gui/toolkit"
)
-func (t *andlabsT) newDropdown(a *toolkit.Action) *andlabsT {
- var newt andlabsT
- log(debugToolkit, "gui.Toolbox.newDropdown() START", a.Name)
+func (p *node) newDropdown(n *node) {
+ newt := new(andlabsT)
+ log(debugToolkit, "gui.Toolbox.newDropdown() START", n.Name)
- newt.WidgetType = a.WidgetType
- newt.wId = a.WidgetId
- s := ui.NewCombobox()
- newt.uiCombobox = s
- newt.uiControl = s
+ cb := ui.NewCombobox()
+ newt.uiCombobox = cb
+ newt.uiControl = cb
// initialize the index
newt.c = 0
newt.val = make(map[int]string)
- s.OnSelected(func(spin *ui.Combobox) {
+ cb.OnSelected(func(spin *ui.Combobox) {
i := spin.Selected()
if (newt.val == nil) {
log(debugChange, "make map didn't work")
@@ -30,7 +29,8 @@ func (t *andlabsT) newDropdown(a *toolkit.Action) *andlabsT {
newt.doUserEvent()
})
- return &newt
+ n.tk = newt
+ p.place(n)
}
func (t *andlabsT) addDropdownName(title string) {
@@ -53,24 +53,24 @@ func (t *andlabsT) SetDropdown(i int) {
t.uiCombobox.SetSelected(i)
}
-func AddDropdownName(a *toolkit.Action) {
- log(debugToolkit, "gui.andlabs.AddDropdownName()", a.WidgetId, "add:", a.S)
+func (n *node) AddDropdownName(a *toolkit.Action) {
+ log(debugToolkit, "gui.andlabs.AddDropdownName()", n.WidgetId, "add:", a.S)
- t := andlabs[a.WidgetId]
+ t := n.tk
if (t == nil) {
- log(debugToolkit, "go.andlabs.AddDropdownName() toolkit struct == nil. name=", a.Name, a.S)
+ log(debugToolkit, "go.andlabs.AddDropdownName() toolkit struct == nil. name=", n.Name, a.S)
listMap(debugToolkit)
return
}
t.addDropdownName(a.S)
}
-func SetDropdownName(a *toolkit.Action, s string) {
- log(debugChange, "gui.andlabs.SetDropdown()", a.WidgetId, ",", s)
+func (n *node) SetDropdownName(a *toolkit.Action, s string) {
+ log(debugChange, "gui.andlabs.SetDropdown()", n.WidgetId, ",", s)
- t := andlabs[a.WidgetId]
+ t := n.tk
if (t == nil) {
- log(debugError, "ERROR: SetDropdown() FAILED mapToolkits[w] == nil. name=", a.WidgetId, s)
+ log(debugError, "ERROR: SetDropdown() FAILED mapToolkits[w] == nil. name=", n.WidgetId, s)
listMap(debugError)
return
}
@@ -78,17 +78,3 @@ func SetDropdownName(a *toolkit.Action, s string) {
// TODO: send back to wit/gui goroutine with the chan
t.s = s
}
-
-func newDropdown(a *toolkit.Action) {
- log(debugToolkit, "gui.andlabs.newDropdown()", a.Name)
-
- t := andlabs[a.ParentId]
- if (t == nil) {
- log(debugToolkit, "go.andlabs.newDropdown() toolkit struct == nil. name=", a.WidgetId)
- listMap(debugToolkit)
- return
- }
- newt := t.newDropdown(a)
- place(a, t, newt)
- // mapWidgetsToolkits(a, newt)
-}
diff --git a/toolkit/andlabs/plugin.go b/toolkit/andlabs/plugin.go
index 96a73ac..e4b3234 100644
--- a/toolkit/andlabs/plugin.go
+++ b/toolkit/andlabs/plugin.go
@@ -26,6 +26,8 @@ func rawAction(a toolkit.Action) {
return
}
+ n := rootNode.findWidgetId(a.WidgetId)
+
switch a.ActionType {
case toolkit.Add:
ui.QueueMain(func() {
@@ -45,7 +47,7 @@ func rawAction(a toolkit.Action) {
a.B = false
enable(&a)
case toolkit.Get:
- setText(&a)
+ n.setText(&a)
case toolkit.GetText:
switch a.WidgetType {
case toolkit.Textbox:
@@ -53,11 +55,11 @@ func rawAction(a toolkit.Action) {
a.S = t.s
}
case toolkit.Set:
- setText(&a)
+ n.setText(&a)
case toolkit.SetText:
- setText(&a)
+ n.setText(&a)
case toolkit.AddText:
- setText(&a)
+ n.setText(&a)
case toolkit.Margin:
pad(&a)
case toolkit.Unmargin:
@@ -105,7 +107,7 @@ func flag(a *toolkit.Action) {
}
}
-func setText(a *toolkit.Action) {
+func (n *node) setText(a *toolkit.Action) {
t := andlabs[a.WidgetId]
if (t == nil) {
log(debugError, "setText error. andlabs[id] == nil", a.WidgetId)
@@ -167,7 +169,7 @@ func setText(a *toolkit.Action) {
case toolkit.Dropdown:
switch a.ActionType {
case toolkit.AddText:
- AddDropdownName(a)
+ n.AddDropdownName(a)
case toolkit.Set:
var orig int
var i int = -1
diff --git a/toolkit/andlabs/textbox.go b/toolkit/andlabs/textbox.go
index 626eec4..5dca1bc 100644
--- a/toolkit/andlabs/textbox.go
+++ b/toolkit/andlabs/textbox.go
@@ -1,43 +1,21 @@
package main
import (
- "git.wit.org/wit/gui/toolkit"
-
"github.com/andlabs/ui"
_ "github.com/andlabs/ui/winmanifest"
)
-// func newTextbox(a *toolkit.Action) {
-func (t *andlabsT) newTextbox() *andlabsT {
- var newt andlabsT
-
- c := ui.NewNonWrappingMultilineEntry()
- newt.uiMultilineEntry = c
- newt.uiControl = c
+func (p *node) newTextbox(n *node) {
+ newt := new(andlabsT)
- newt.WidgetType = toolkit.Textbox
+ e := ui.NewNonWrappingMultilineEntry()
+ newt.uiMultilineEntry = e
+ newt.uiControl = e
- c.OnChanged(func(spin *ui.MultilineEntry) {
- newt.s = spin.Text()
- // this is still dangerous
- log(debugChange, "Not yet safe to trigger on change for ui.MultilineEntry")
+ e.OnChanged(func(spin *ui.MultilineEntry) {
newt.s = spin.Text()
newt.doUserEvent()
})
- return &newt
-}
-
-func newTextbox(a *toolkit.Action) {
- log(debugToolkit, "newCombobox()", a.Name)
-
- t := andlabs[a.ParentId]
- if (t == nil) {
- log(debugToolkit, "newCombobox() toolkit struct == nil. name=", a.Name)
- listMap(debugToolkit)
- return
- }
- newt := t.newTextbox()
- newt.Name = a.Name
- newt.wId = a.WidgetId
- place(a, t, newt)
+ n.tk = newt
+ p.place(n)
}