andlabs: more code cleanup
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
e370d22932
commit
d282c353e6
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
func (p *node) newTextbox(n *node) {
|
||||
newt := new(andlabsT)
|
||||
|
||||
c := ui.NewNonWrappingMultilineEntry()
|
||||
newt.uiMultilineEntry = c
|
||||
newt.uiControl = c
|
||||
e := ui.NewNonWrappingMultilineEntry()
|
||||
newt.uiMultilineEntry = e
|
||||
newt.uiControl = e
|
||||
|
||||
newt.WidgetType = toolkit.Textbox
|
||||
|
||||
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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue