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)
|
p.newSlider(n)
|
||||||
return
|
return
|
||||||
case toolkit.Dropdown:
|
case toolkit.Dropdown:
|
||||||
newDropdown(&a)
|
p.newDropdown(n)
|
||||||
return
|
return
|
||||||
case toolkit.Combobox:
|
case toolkit.Combobox:
|
||||||
newCombobox(&a)
|
p.newCombobox(n)
|
||||||
return
|
return
|
||||||
case toolkit.Textbox:
|
case toolkit.Textbox:
|
||||||
newTextbox(&a)
|
p.newTextbox(n)
|
||||||
return
|
return
|
||||||
case toolkit.Group:
|
case toolkit.Group:
|
||||||
p.newGroup(n)
|
p.newGroup(n)
|
||||||
|
|
|
@ -3,29 +3,27 @@ package main
|
||||||
import (
|
import (
|
||||||
"github.com/andlabs/ui"
|
"github.com/andlabs/ui"
|
||||||
_ "github.com/andlabs/ui/winmanifest"
|
_ "github.com/andlabs/ui/winmanifest"
|
||||||
"git.wit.org/wit/gui/toolkit"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (t *andlabsT) newCombobox(a *toolkit.Action) *andlabsT {
|
func (p *node) newCombobox(n *node) {
|
||||||
var newt andlabsT
|
newt := new(andlabsT)
|
||||||
log(debugToolkit, "newCombobox() START", a.Name)
|
log(debugToolkit, "newCombobox() START", n.Name)
|
||||||
|
|
||||||
newt.wId = a.WidgetId
|
cb := ui.NewEditableCombobox()
|
||||||
newt.WidgetType = a.WidgetType
|
newt.uiEditableCombobox = cb
|
||||||
s := ui.NewEditableCombobox()
|
newt.uiControl = cb
|
||||||
newt.uiEditableCombobox = s
|
|
||||||
newt.uiControl = s
|
|
||||||
|
|
||||||
// initialize the index
|
// initialize the index
|
||||||
newt.c = 0
|
newt.c = 0
|
||||||
newt.val = make(map[int]string)
|
newt.val = make(map[int]string)
|
||||||
|
|
||||||
s.OnChanged(func(spin *ui.EditableCombobox) {
|
cb.OnChanged(func(spin *ui.EditableCombobox) {
|
||||||
newt.s = spin.Text()
|
newt.s = spin.Text()
|
||||||
newt.doUserEvent()
|
newt.doUserEvent()
|
||||||
})
|
})
|
||||||
|
|
||||||
return &newt
|
n.tk = newt
|
||||||
|
p.place(n)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *andlabsT) AddComboboxName(title string) {
|
func (t *andlabsT) AddComboboxName(title string) {
|
||||||
|
@ -41,16 +39,3 @@ func (t *andlabsT) AddComboboxName(title string) {
|
||||||
// }
|
// }
|
||||||
t.c = t.c + 1
|
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 (
|
import (
|
||||||
"github.com/andlabs/ui"
|
"github.com/andlabs/ui"
|
||||||
_ "github.com/andlabs/ui/winmanifest"
|
_ "github.com/andlabs/ui/winmanifest"
|
||||||
|
|
||||||
"git.wit.org/wit/gui/toolkit"
|
"git.wit.org/wit/gui/toolkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (t *andlabsT) newDropdown(a *toolkit.Action) *andlabsT {
|
func (p *node) newDropdown(n *node) {
|
||||||
var newt andlabsT
|
newt := new(andlabsT)
|
||||||
log(debugToolkit, "gui.Toolbox.newDropdown() START", a.Name)
|
log(debugToolkit, "gui.Toolbox.newDropdown() START", n.Name)
|
||||||
|
|
||||||
newt.WidgetType = a.WidgetType
|
cb := ui.NewCombobox()
|
||||||
newt.wId = a.WidgetId
|
newt.uiCombobox = cb
|
||||||
s := ui.NewCombobox()
|
newt.uiControl = cb
|
||||||
newt.uiCombobox = s
|
|
||||||
newt.uiControl = s
|
|
||||||
|
|
||||||
// initialize the index
|
// initialize the index
|
||||||
newt.c = 0
|
newt.c = 0
|
||||||
newt.val = make(map[int]string)
|
newt.val = make(map[int]string)
|
||||||
|
|
||||||
s.OnSelected(func(spin *ui.Combobox) {
|
cb.OnSelected(func(spin *ui.Combobox) {
|
||||||
i := spin.Selected()
|
i := spin.Selected()
|
||||||
if (newt.val == nil) {
|
if (newt.val == nil) {
|
||||||
log(debugChange, "make map didn't work")
|
log(debugChange, "make map didn't work")
|
||||||
|
@ -30,7 +29,8 @@ func (t *andlabsT) newDropdown(a *toolkit.Action) *andlabsT {
|
||||||
newt.doUserEvent()
|
newt.doUserEvent()
|
||||||
})
|
})
|
||||||
|
|
||||||
return &newt
|
n.tk = newt
|
||||||
|
p.place(n)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *andlabsT) addDropdownName(title string) {
|
func (t *andlabsT) addDropdownName(title string) {
|
||||||
|
@ -53,24 +53,24 @@ func (t *andlabsT) SetDropdown(i int) {
|
||||||
t.uiCombobox.SetSelected(i)
|
t.uiCombobox.SetSelected(i)
|
||||||
}
|
}
|
||||||
|
|
||||||
func AddDropdownName(a *toolkit.Action) {
|
func (n *node) AddDropdownName(a *toolkit.Action) {
|
||||||
log(debugToolkit, "gui.andlabs.AddDropdownName()", a.WidgetId, "add:", a.S)
|
log(debugToolkit, "gui.andlabs.AddDropdownName()", n.WidgetId, "add:", a.S)
|
||||||
|
|
||||||
t := andlabs[a.WidgetId]
|
t := n.tk
|
||||||
if (t == nil) {
|
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)
|
listMap(debugToolkit)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
t.addDropdownName(a.S)
|
t.addDropdownName(a.S)
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetDropdownName(a *toolkit.Action, s string) {
|
func (n *node) SetDropdownName(a *toolkit.Action, s string) {
|
||||||
log(debugChange, "gui.andlabs.SetDropdown()", a.WidgetId, ",", s)
|
log(debugChange, "gui.andlabs.SetDropdown()", n.WidgetId, ",", s)
|
||||||
|
|
||||||
t := andlabs[a.WidgetId]
|
t := n.tk
|
||||||
if (t == nil) {
|
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)
|
listMap(debugError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -78,17 +78,3 @@ func SetDropdownName(a *toolkit.Action, s string) {
|
||||||
// TODO: send back to wit/gui goroutine with the chan
|
// TODO: send back to wit/gui goroutine with the chan
|
||||||
t.s = s
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
n := rootNode.findWidgetId(a.WidgetId)
|
||||||
|
|
||||||
switch a.ActionType {
|
switch a.ActionType {
|
||||||
case toolkit.Add:
|
case toolkit.Add:
|
||||||
ui.QueueMain(func() {
|
ui.QueueMain(func() {
|
||||||
|
@ -45,7 +47,7 @@ func rawAction(a toolkit.Action) {
|
||||||
a.B = false
|
a.B = false
|
||||||
enable(&a)
|
enable(&a)
|
||||||
case toolkit.Get:
|
case toolkit.Get:
|
||||||
setText(&a)
|
n.setText(&a)
|
||||||
case toolkit.GetText:
|
case toolkit.GetText:
|
||||||
switch a.WidgetType {
|
switch a.WidgetType {
|
||||||
case toolkit.Textbox:
|
case toolkit.Textbox:
|
||||||
|
@ -53,11 +55,11 @@ func rawAction(a toolkit.Action) {
|
||||||
a.S = t.s
|
a.S = t.s
|
||||||
}
|
}
|
||||||
case toolkit.Set:
|
case toolkit.Set:
|
||||||
setText(&a)
|
n.setText(&a)
|
||||||
case toolkit.SetText:
|
case toolkit.SetText:
|
||||||
setText(&a)
|
n.setText(&a)
|
||||||
case toolkit.AddText:
|
case toolkit.AddText:
|
||||||
setText(&a)
|
n.setText(&a)
|
||||||
case toolkit.Margin:
|
case toolkit.Margin:
|
||||||
pad(&a)
|
pad(&a)
|
||||||
case toolkit.Unmargin:
|
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]
|
t := andlabs[a.WidgetId]
|
||||||
if (t == nil) {
|
if (t == nil) {
|
||||||
log(debugError, "setText error. andlabs[id] == nil", a.WidgetId)
|
log(debugError, "setText error. andlabs[id] == nil", a.WidgetId)
|
||||||
|
@ -167,7 +169,7 @@ func setText(a *toolkit.Action) {
|
||||||
case toolkit.Dropdown:
|
case toolkit.Dropdown:
|
||||||
switch a.ActionType {
|
switch a.ActionType {
|
||||||
case toolkit.AddText:
|
case toolkit.AddText:
|
||||||
AddDropdownName(a)
|
n.AddDropdownName(a)
|
||||||
case toolkit.Set:
|
case toolkit.Set:
|
||||||
var orig int
|
var orig int
|
||||||
var i int = -1
|
var i int = -1
|
||||||
|
|
|
@ -1,43 +1,21 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.wit.org/wit/gui/toolkit"
|
|
||||||
|
|
||||||
"github.com/andlabs/ui"
|
"github.com/andlabs/ui"
|
||||||
_ "github.com/andlabs/ui/winmanifest"
|
_ "github.com/andlabs/ui/winmanifest"
|
||||||
)
|
)
|
||||||
|
|
||||||
// func newTextbox(a *toolkit.Action) {
|
func (p *node) newTextbox(n *node) {
|
||||||
func (t *andlabsT) newTextbox() *andlabsT {
|
newt := new(andlabsT)
|
||||||
var newt andlabsT
|
|
||||||
|
|
||||||
c := ui.NewNonWrappingMultilineEntry()
|
e := ui.NewNonWrappingMultilineEntry()
|
||||||
newt.uiMultilineEntry = c
|
newt.uiMultilineEntry = e
|
||||||
newt.uiControl = c
|
newt.uiControl = e
|
||||||
|
|
||||||
newt.WidgetType = toolkit.Textbox
|
e.OnChanged(func(spin *ui.MultilineEntry) {
|
||||||
|
|
||||||
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")
|
|
||||||
newt.s = spin.Text()
|
newt.s = spin.Text()
|
||||||
newt.doUserEvent()
|
newt.doUserEvent()
|
||||||
})
|
})
|
||||||
return &newt
|
n.tk = newt
|
||||||
}
|
p.place(n)
|
||||||
|
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue