andlabs: deprecate old code
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
d282c353e6
commit
d671c3c441
|
@ -1,65 +1,50 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/andlabs/ui"
|
||||
"git.wit.org/wit/gui/toolkit"
|
||||
)
|
||||
|
||||
func show(a *toolkit.Action) {
|
||||
if (a == nil) {
|
||||
log(debugError, "nil is probably already hidden")
|
||||
func (n *node) show(b bool) {
|
||||
if n.tk == nil {
|
||||
return
|
||||
}
|
||||
log(debugError, "show()", a.WidgetId)
|
||||
|
||||
t := andlabs[a.WidgetId]
|
||||
if (t == nil) {
|
||||
log(debugError, "show() toolkit struct == nil. for", a.WidgetId)
|
||||
if n.tk.uiControl == nil {
|
||||
return
|
||||
}
|
||||
|
||||
if (a.B) {
|
||||
t.uiControl.Show()
|
||||
if (b) {
|
||||
n.tk.uiControl.Show()
|
||||
} else {
|
||||
t.uiControl.Hide()
|
||||
n.tk.uiControl.Hide()
|
||||
}
|
||||
}
|
||||
|
||||
func enable(a *toolkit.Action) {
|
||||
if (a == nil) {
|
||||
log(debugError, "nil is probably already hidden")
|
||||
func (n *node) enable(b bool) {
|
||||
if n.tk == nil {
|
||||
return
|
||||
}
|
||||
log(debugError, "enable() name =", a.WidgetId)
|
||||
|
||||
t := andlabs[a.WidgetId]
|
||||
if (t == nil) {
|
||||
log(debugToolkit, "enable() toolkit struct == nil. for id =", a.WidgetId)
|
||||
if n.tk.uiControl == nil {
|
||||
return
|
||||
}
|
||||
|
||||
if (a.B) {
|
||||
t.uiControl.Enable()
|
||||
if (b) {
|
||||
n.tk.uiControl.Enable()
|
||||
} else {
|
||||
t.uiControl.Disable()
|
||||
n.tk.uiControl.Disable()
|
||||
}
|
||||
}
|
||||
|
||||
func pad(a *toolkit.Action) {
|
||||
if (a == nil) {
|
||||
log(debugError, "pad() ERROR: nil is probably already hidden")
|
||||
return
|
||||
}
|
||||
func (n *node) pad(at toolkit.ActionType) {
|
||||
log(debugError, "pad()")
|
||||
|
||||
t := andlabs[a.WidgetId]
|
||||
t := n.tk
|
||||
if (t == nil) {
|
||||
log(debugError, "pad() toolkit struct == nil. for", a.WidgetId)
|
||||
log(debugError, "pad() toolkit struct == nil. for", n.WidgetId)
|
||||
return
|
||||
}
|
||||
|
||||
switch t.WidgetType {
|
||||
switch n.WidgetType {
|
||||
case toolkit.Group:
|
||||
switch a.ActionType {
|
||||
switch at {
|
||||
case toolkit.Margin:
|
||||
t.uiGroup.SetMargined(true)
|
||||
case toolkit.Unmargin:
|
||||
|
@ -70,7 +55,7 @@ func pad(a *toolkit.Action) {
|
|||
t.uiGroup.SetMargined(false)
|
||||
}
|
||||
case toolkit.Tab:
|
||||
switch a.ActionType {
|
||||
switch at {
|
||||
case toolkit.Margin:
|
||||
tabSetMargined(t.uiTab, true)
|
||||
case toolkit.Unmargin:
|
||||
|
@ -81,7 +66,7 @@ func pad(a *toolkit.Action) {
|
|||
tabSetMargined(t.uiTab, false)
|
||||
}
|
||||
case toolkit.Window:
|
||||
switch a.ActionType {
|
||||
switch at {
|
||||
case toolkit.Margin:
|
||||
t.uiWindow.SetMargined(true)
|
||||
case toolkit.Unmargin:
|
||||
|
@ -92,7 +77,7 @@ func pad(a *toolkit.Action) {
|
|||
t.uiWindow.SetBorderless(true)
|
||||
}
|
||||
case toolkit.Grid:
|
||||
switch a.ActionType {
|
||||
switch at {
|
||||
case toolkit.Margin:
|
||||
t.uiGrid.SetPadded(true)
|
||||
case toolkit.Unmargin:
|
||||
|
@ -103,7 +88,7 @@ func pad(a *toolkit.Action) {
|
|||
t.uiGrid.SetPadded(false)
|
||||
}
|
||||
case toolkit.Box:
|
||||
switch a.ActionType {
|
||||
switch at {
|
||||
case toolkit.Margin:
|
||||
t.uiBox.SetPadded(true)
|
||||
case toolkit.Unmargin:
|
||||
|
@ -114,58 +99,31 @@ func pad(a *toolkit.Action) {
|
|||
t.uiBox.SetPadded(false)
|
||||
}
|
||||
case toolkit.Textbox:
|
||||
log(debugError, "TODO: implement expand for", a.ActionType)
|
||||
log(debugError, "TODO: implement expand for", a.ActionType)
|
||||
log(debugError, "TODO: implement expand for", a.ActionType)
|
||||
log(debugError, "TODO: implement expand for", a.ActionType)
|
||||
log(debugError, "TODO: implement ActionType =", at)
|
||||
default:
|
||||
log(debugError, "TODO: implement pad() for", a.ActionType)
|
||||
log(debugError, "TODO: implement pad() for", at)
|
||||
}
|
||||
}
|
||||
|
||||
func move(a *toolkit.Action) {
|
||||
log(debugNow, "move()", a.WidgetId, "to", a.ParentId)
|
||||
func (n *node) move(newParent *node) {
|
||||
p := n.parent
|
||||
|
||||
tWidget := andlabs[a.WidgetId]
|
||||
if (tWidget == nil) {
|
||||
log(debugError, "move() ERROR: toolkit struct == nil. for", a.WidgetId)
|
||||
return
|
||||
}
|
||||
|
||||
tParent := andlabs[a.ParentId]
|
||||
if (tParent == nil) {
|
||||
log(debugError, "move() ERROR: toolkit struct == nil. for", a.ParentId)
|
||||
return
|
||||
}
|
||||
|
||||
switch tParent.WidgetType {
|
||||
switch p.WidgetType {
|
||||
case toolkit.Group:
|
||||
switch a.ActionType {
|
||||
case toolkit.Margin:
|
||||
tParent.uiGroup.SetMargined(true)
|
||||
}
|
||||
case toolkit.Tab:
|
||||
switch a.ActionType {
|
||||
case toolkit.Margin:
|
||||
// tabSetMargined(tParent.uiTab, true)
|
||||
}
|
||||
case toolkit.Window:
|
||||
switch a.ActionType {
|
||||
case toolkit.Pad:
|
||||
// t.uiWindow.SetBorderless(false)
|
||||
}
|
||||
case toolkit.Grid:
|
||||
switch a.ActionType {
|
||||
case toolkit.Pad:
|
||||
// t.uiGrid.SetPadded(true)
|
||||
}
|
||||
case toolkit.Box:
|
||||
log(debugNow, "TODO: move() for a =", a.ActionType)
|
||||
log(debugNow, "TODO: move() where =", a.ParentId)
|
||||
log(debugNow, "TODO: move() for widget =", a.WidgetId)
|
||||
log(logInfo, "TODO: move() where =", p.ParentId)
|
||||
log(logInfo, "TODO: move() for widget =", n.WidgetId)
|
||||
|
||||
stretchy = true
|
||||
tParent.uiBox.Append(tWidget.uiControl, stretchy)
|
||||
if (p.tk.uiBox != nil) {
|
||||
p.tk.uiBox.Append(n.tk.uiControl, stretchy)
|
||||
}
|
||||
// log(debugNow, "is there a tParent parent? =", tParent.parent)
|
||||
// tParent.uiBox.Delete(0)
|
||||
|
||||
|
@ -173,73 +131,111 @@ func move(a *toolkit.Action) {
|
|||
// tWidget.uiControl.Disable()
|
||||
// sleep(.8)
|
||||
default:
|
||||
log(debugError, "TODO: need to implement move() for a =", a.ActionType)
|
||||
log(debugError, "TODO: need to implement move() for where =", a.ParentId)
|
||||
log(debugError, "TODO: need to implement move() for widget =", a.WidgetId)
|
||||
log(logError, "TODO: need to implement move() for type =", n.WidgetType)
|
||||
log(logError, "TODO: need to implement move() for where =", p.ParentId)
|
||||
log(logError, "TODO: need to implement move() for widget =", n.WidgetId)
|
||||
}
|
||||
}
|
||||
|
||||
func uiDelete(a *toolkit.Action) {
|
||||
if (andlabs[a.ParentId] == nil) {
|
||||
log(debugError, "uiDelete() ERROR: can not uiDelete to nil")
|
||||
return
|
||||
}
|
||||
if (andlabs[a.WidgetId] == nil) {
|
||||
log(debugError, "uiDelete() ERROR: can not uiDelete nil")
|
||||
return
|
||||
}
|
||||
log(debugNow, "uiDelete()", a.WidgetId, "to", a.ParentId)
|
||||
func (n *node) Delete() {
|
||||
p := n.parent
|
||||
log(debugNow, "uiDelete()", n.WidgetId, "to", p.WidgetId)
|
||||
|
||||
tWidget := andlabs[a.WidgetId]
|
||||
if (tWidget == nil) {
|
||||
log(debugError, "uiDelete() ERROR: toolkit struct == nil. for", a.WidgetId)
|
||||
return
|
||||
}
|
||||
|
||||
tParent := andlabs[a.ParentId]
|
||||
if (tParent == nil) {
|
||||
log(debugError, "uiDelete() ERROR: toolkit struct == nil. for", a.ParentId)
|
||||
return
|
||||
}
|
||||
|
||||
switch tParent.WidgetType {
|
||||
switch p.WidgetType {
|
||||
case toolkit.Group:
|
||||
switch a.ActionType {
|
||||
case toolkit.Margin:
|
||||
tParent.uiGroup.SetMargined(true)
|
||||
}
|
||||
// tParent.uiGroup.SetMargined(true)
|
||||
case toolkit.Tab:
|
||||
switch a.ActionType {
|
||||
case toolkit.Margin:
|
||||
// tabSetMargined(tParent.uiTab, true)
|
||||
}
|
||||
case toolkit.Window:
|
||||
switch a.ActionType {
|
||||
case toolkit.Pad:
|
||||
// t.uiWindow.SetBorderless(false)
|
||||
}
|
||||
case toolkit.Grid:
|
||||
switch a.ActionType {
|
||||
case toolkit.Pad:
|
||||
// t.uiGrid.SetPadded(true)
|
||||
}
|
||||
case toolkit.Box:
|
||||
log(debugNow, "tWidget.boxC =", tParent.Name)
|
||||
log(debugNow, "is there a tParent parent? =", tParent.parent)
|
||||
if (tWidget.boxC < 1) {
|
||||
log(debugNow, "Can not delete from Box. already empty. tWidget.boxC =", tParent.boxC)
|
||||
log(debugNow, "tWidget.boxC =", p.Name)
|
||||
log(debugNow, "is there a tParent parent? =", p.parent)
|
||||
if (p.tk.boxC < 1) {
|
||||
log(debugNow, "Can not delete from Box. already empty. tWidget.boxC =", p.tk.boxC)
|
||||
return
|
||||
}
|
||||
tWidget.uiBox.Delete(0)
|
||||
tWidget.boxC -= 1
|
||||
p.tk.uiBox.Delete(0)
|
||||
p.tk.boxC -= 1
|
||||
|
||||
// this didn't work:
|
||||
// tWidget.uiControl.Disable()
|
||||
// sleep(.8)
|
||||
// tParent.uiBox.Append(tWidget.uiControl, stretchy)
|
||||
default:
|
||||
log(debugError, "TODO: need to implement uiDelete() for a =", a.ActionType)
|
||||
log(debugError, "TODO: need to implement uiDelete() for where =", a.ParentId)
|
||||
log(debugError, "TODO: need to implement uiDelete() for widget =", a.WidgetId)
|
||||
log(debugError, "TODO: need to implement uiDelete() for widget =", n.WidgetId, n.WidgetType)
|
||||
log(debugError, "TODO: need to implement uiDelete() for parent =", p.WidgetId, p.WidgetType)
|
||||
}
|
||||
}
|
||||
|
||||
func rawAction(a toolkit.Action) {
|
||||
log(logNow, "rawAction() START a.ActionType =", a.ActionType)
|
||||
log(logNow, "rawAction() START a.S =", a.S)
|
||||
|
||||
if (a.ActionType == toolkit.InitToolkit) {
|
||||
// TODO: make sure to only do this once
|
||||
// go uiMain.Do(func() {
|
||||
// ui.Main(demoUI)
|
||||
// go catchActionChannel()
|
||||
// })
|
||||
// try doing this on toolkit load in init()
|
||||
return
|
||||
}
|
||||
|
||||
log(logNow, "rawAction() START a.WidgetId =", a.WidgetId, "a.ParentId =", a.ParentId)
|
||||
switch a.WidgetType {
|
||||
case toolkit.Flag:
|
||||
flag(&a)
|
||||
return
|
||||
}
|
||||
|
||||
n := rootNode.findWidgetId(a.WidgetId)
|
||||
|
||||
switch a.ActionType {
|
||||
case toolkit.Add:
|
||||
ui.QueueMain(func() {
|
||||
add(a)
|
||||
})
|
||||
sleep(.1)
|
||||
case toolkit.Show:
|
||||
n.show(true)
|
||||
case toolkit.Hide:
|
||||
n.show(false)
|
||||
case toolkit.Enable:
|
||||
n.enable(true)
|
||||
case toolkit.Disable:
|
||||
n.enable(false)
|
||||
case toolkit.Get:
|
||||
n.setText(&a)
|
||||
case toolkit.GetText:
|
||||
switch a.WidgetType {
|
||||
case toolkit.Textbox:
|
||||
a.S = n.S
|
||||
}
|
||||
case toolkit.Set:
|
||||
n.setText(&a)
|
||||
case toolkit.SetText:
|
||||
n.setText(&a)
|
||||
case toolkit.AddText:
|
||||
n.setText(&a)
|
||||
case toolkit.Margin:
|
||||
n.pad(toolkit.Unmargin)
|
||||
case toolkit.Unmargin:
|
||||
n.pad(toolkit.Margin)
|
||||
case toolkit.Pad:
|
||||
n.pad(toolkit.Pad)
|
||||
case toolkit.Unpad:
|
||||
n.pad(toolkit.Unpad)
|
||||
case toolkit.Delete:
|
||||
n.Delete()
|
||||
case toolkit.Move:
|
||||
log(debugNow, "rawAction() attempt to move() =", a.ActionType, a.WidgetType)
|
||||
newParent := rootNode.findWidgetId(a.ParentId)
|
||||
n.move(newParent)
|
||||
default:
|
||||
log(debugError, "rawAction() Unknown =", a.ActionType, a.WidgetType)
|
||||
}
|
||||
log(debugAction, "rawAction() END =", a.ActionType, a.WidgetType)
|
||||
}
|
||||
|
|
|
@ -16,11 +16,6 @@ func actionDump(b bool, a *toolkit.Action) {
|
|||
}
|
||||
|
||||
func add(a toolkit.Action) {
|
||||
if (andlabs[a.WidgetId] != nil) {
|
||||
log(debugError, "add() error. can't make a widget that already exists. id =", a.WidgetId)
|
||||
actionDump(debugError, &a)
|
||||
return
|
||||
}
|
||||
if (a.WidgetType == toolkit.Root) {
|
||||
rootNode = addWidget(&a, nil)
|
||||
return
|
||||
|
@ -100,70 +95,6 @@ func add(a toolkit.Action) {
|
|||
// -- (0,0) -- (1,0) -- (1,0) --
|
||||
// -- (0,1) -- (1,1) -- (1,1) --
|
||||
// -----------------------------
|
||||
func place(a *toolkit.Action, t *andlabsT, newt *andlabsT) bool {
|
||||
log(debugAction, "place() START", a.WidgetType, a.Name)
|
||||
|
||||
// add the structure to the array
|
||||
if (andlabs[a.WidgetId] == nil) {
|
||||
log(logInfo, "place() MAPPED", a.WidgetId, a.ParentId)
|
||||
andlabs[a.WidgetId] = newt
|
||||
newt.WidgetType = a.WidgetType
|
||||
} else {
|
||||
log(debugError, "place() DO WHAT?", a.WidgetId, a.ParentId)
|
||||
log(debugError, "place() THIS IS BAD")
|
||||
}
|
||||
log(logInfo, "place() DONE MAPPED", a.WidgetId, a.ParentId)
|
||||
|
||||
if (newt.uiControl == nil) {
|
||||
log(debugError, "place() ERROR uiControl == nil", a.ParentId)
|
||||
return false
|
||||
}
|
||||
|
||||
where := andlabs[a.ParentId]
|
||||
if (where == nil) {
|
||||
log(debugError, "place() ERROR where == nil", a.ParentId)
|
||||
return false
|
||||
}
|
||||
|
||||
log(logInfo, "place() switch", where.WidgetType)
|
||||
switch where.WidgetType {
|
||||
case toolkit.Grid:
|
||||
log(debugGrid, "place() Grid try at Parent X,Y =", a.X, a.Y)
|
||||
newt.gridX = a.X
|
||||
newt.gridY = a.Y
|
||||
log(debugGrid, "place() Grid try at gridX,gridY", newt.gridX, newt.gridY)
|
||||
// at the very end, subtract 1 from X & Y since andlabs/ui starts counting at zero
|
||||
t.uiGrid.Append(newt.uiControl,
|
||||
newt.gridY - 1, newt.gridX - 1, 1, 1,
|
||||
false, ui.AlignFill, false, ui.AlignFill)
|
||||
return true
|
||||
case toolkit.Group:
|
||||
if (t.uiBox == nil) {
|
||||
t.uiGroup.SetChild(newt.uiControl)
|
||||
log(debugGrid, "place() hack Group to use this as the box?", a.Name, a.WidgetType)
|
||||
t.uiBox = newt.uiBox
|
||||
} else {
|
||||
t.uiBox.Append(newt.uiControl, stretchy)
|
||||
}
|
||||
return true
|
||||
case toolkit.Tab:
|
||||
t.uiTab.Append(a.Text, newt.uiControl)
|
||||
t.boxC += 1
|
||||
return true
|
||||
case toolkit.Box:
|
||||
log(logInfo, "place() uiBox =", t.uiBox)
|
||||
log(logInfo, "place() uiControl =", newt.uiControl)
|
||||
t.uiBox.Append(newt.uiControl, stretchy)
|
||||
t.boxC += 1
|
||||
return true
|
||||
case toolkit.Window:
|
||||
t.uiWindow.SetChild(newt.uiControl)
|
||||
return true
|
||||
default:
|
||||
log(debugError, "place() how?", a.ParentId)
|
||||
}
|
||||
return false
|
||||
}
|
||||
func (p *node) place(n *node) bool {
|
||||
log(logInfo, "place() START", n.WidgetType, n.Name)
|
||||
|
||||
|
|
|
@ -9,26 +9,12 @@ import (
|
|||
func (p *node) newBox(n *node) {
|
||||
log(debugToolkit, "newBox()", n.Name)
|
||||
|
||||
t := p.tk
|
||||
if (t == nil) {
|
||||
log(debugToolkit, "newBox() toolkit struct == nil. name=", n.Name)
|
||||
listMap(debugToolkit)
|
||||
}
|
||||
newt := t.rawBox(n.Text, n.B)
|
||||
newt.boxC = 0
|
||||
n.tk = newt
|
||||
p.place(n)
|
||||
}
|
||||
|
||||
// make new Box using andlabs/ui
|
||||
func (t *andlabsT) rawBox(title string, b bool) *andlabsT {
|
||||
var newt andlabsT
|
||||
newt := new(andlabsT)
|
||||
var box *ui.Box
|
||||
newt.Name = title
|
||||
|
||||
log(debugToolkit, "rawBox() create", newt.Name)
|
||||
|
||||
if (b) {
|
||||
if (n.B) {
|
||||
box = ui.NewHorizontalBox()
|
||||
} else {
|
||||
box = ui.NewVerticalBox()
|
||||
|
@ -37,6 +23,7 @@ func (t *andlabsT) rawBox(title string, b bool) *andlabsT {
|
|||
|
||||
newt.uiBox = box
|
||||
newt.uiControl = box
|
||||
|
||||
return &newt
|
||||
newt.boxC = 0
|
||||
n.tk = newt
|
||||
p.place(n)
|
||||
}
|
||||
|
|
|
@ -19,12 +19,10 @@ func (p *node) newButton(n *node) {
|
|||
b := ui.NewButton(n.Text)
|
||||
newt.uiButton = b
|
||||
newt.uiControl = b
|
||||
newt.wId = n.WidgetId
|
||||
newt.WidgetType = n.WidgetType
|
||||
newt.parent = t
|
||||
|
||||
b.OnClicked(func(*ui.Button) {
|
||||
newt.doUserEvent()
|
||||
n.doUserEvent()
|
||||
})
|
||||
|
||||
n.tk = newt
|
||||
|
|
|
@ -8,10 +8,6 @@ import (
|
|||
func (p *node) newCheckbox(n *node) {
|
||||
newt := new(andlabsT)
|
||||
log(debugToolkit, "newCheckbox()", n.Name, n.WidgetType)
|
||||
newt.WidgetType = n.WidgetType
|
||||
newt.wId = n.WidgetId
|
||||
newt.Name = n.Name
|
||||
newt.Text = n.Text
|
||||
|
||||
newt.uiCheckbox = ui.NewCheckbox(n.Text)
|
||||
newt.uiControl = newt.uiCheckbox
|
||||
|
@ -19,7 +15,7 @@ func (p *node) newCheckbox(n *node) {
|
|||
newt.uiCheckbox.OnToggled(func(spin *ui.Checkbox) {
|
||||
newt.b = newt.checked()
|
||||
log(debugChange, "val =", newt.b)
|
||||
newt.doUserEvent()
|
||||
n.doUserEvent()
|
||||
})
|
||||
|
||||
n.tk = newt
|
||||
|
@ -29,16 +25,3 @@ func (p *node) newCheckbox(n *node) {
|
|||
func (t *andlabsT) checked() bool {
|
||||
return t.uiCheckbox.Checked()
|
||||
}
|
||||
|
||||
/*
|
||||
func newCheckbox(a *toolkit.Action) {
|
||||
log(debugToolkit, "newCheckbox()", a.Name)
|
||||
|
||||
t := andlabs[a.ParentId]
|
||||
if (t == nil) {
|
||||
listMap(debugError)
|
||||
return
|
||||
}
|
||||
newt := t.newCheckbox(a)
|
||||
}
|
||||
*/
|
||||
|
|
|
@ -18,8 +18,8 @@ func (p *node) newCombobox(n *node) {
|
|||
newt.val = make(map[int]string)
|
||||
|
||||
cb.OnChanged(func(spin *ui.EditableCombobox) {
|
||||
newt.s = spin.Text()
|
||||
newt.doUserEvent()
|
||||
n.S = spin.Text()
|
||||
n.doUserEvent()
|
||||
})
|
||||
|
||||
n.tk = newt
|
||||
|
|
|
@ -56,26 +56,21 @@ func addWidget(a *toolkit.Action, tk *andlabsT) *node {
|
|||
if n.parent != nil {
|
||||
n.parent.children = append(n.parent.children, n)
|
||||
}
|
||||
|
||||
// deprecate this when this toolkit uses the binary tree instead
|
||||
if (andlabs[a.WidgetId] == nil) {
|
||||
andlabs[a.WidgetId] = tk
|
||||
}
|
||||
|
||||
return n
|
||||
}
|
||||
|
||||
func (t *andlabsT) doUserEvent() {
|
||||
func (n *node) doUserEvent() {
|
||||
if (callback == nil) {
|
||||
log(debugError, "doUserEvent() callback == nil", t.wId)
|
||||
log(debugError, "doUserEvent() callback == nil", n.WidgetId)
|
||||
return
|
||||
}
|
||||
var a toolkit.Action
|
||||
a.WidgetId = t.wId
|
||||
a.Name = t.Name
|
||||
a.S = t.s
|
||||
a.I = t.i
|
||||
a.B = t.b
|
||||
a.WidgetId = n.WidgetId
|
||||
a.Name = n.Name
|
||||
a.Text = n.Text
|
||||
a.S = n.S
|
||||
a.I = n.I
|
||||
a.B = n.B
|
||||
a.ActionType = toolkit.User
|
||||
log(logInfo, "doUserEvent() START: send a user event to the callback channel")
|
||||
callback <- a
|
||||
|
|
|
@ -6,11 +6,13 @@ import "git.wit.org/wit/gui/toolkit"
|
|||
|
||||
// delete the child widget from the parent
|
||||
// p = parent, c = child
|
||||
func destroy(pId int, cId int) {
|
||||
log(true, "delete()", pId, cId)
|
||||
func (n *node) destroy() {
|
||||
pId := n.parent.WidgetId
|
||||
cId := n.WidgetId
|
||||
log(logNow, "delete()", pId, cId)
|
||||
|
||||
pt := andlabs[pId]
|
||||
ct := andlabs[cId]
|
||||
pt := n.parent.tk
|
||||
ct := n.tk
|
||||
if (ct == nil) {
|
||||
log(true, "delete FAILED (ct = mapToolkit[c] == nil) for c", pId, cId)
|
||||
// this pukes out a whole universe of shit
|
||||
|
@ -18,7 +20,7 @@ func destroy(pId int, cId int) {
|
|||
return
|
||||
}
|
||||
|
||||
switch ct.WidgetType {
|
||||
switch n.WidgetType {
|
||||
case toolkit.Button:
|
||||
log(true, "Should delete Button here:", ct.Name)
|
||||
log(true, "Parent:")
|
||||
|
@ -40,12 +42,6 @@ func destroy(pId int, cId int) {
|
|||
case toolkit.Window:
|
||||
log(true, "Should delete Window here:", ct.Name)
|
||||
default:
|
||||
log(true, "Don't know how to delete pt =", pt.WidgetType, pt.Name, pt.uiButton)
|
||||
log(true, "Don't know how to delete ct =", ct.WidgetType, ct.Name, ct.uiButton)
|
||||
log(true, "Parent:")
|
||||
pt.Dump(true)
|
||||
log(true, "Child:")
|
||||
ct.Dump(true)
|
||||
log(true, "Fuckit, let's destroy a button")
|
||||
if (ct.uiButton != nil) {
|
||||
pt.uiBox.Delete(4)
|
||||
|
|
|
@ -25,8 +25,8 @@ func (p *node) newDropdown(n *node) {
|
|||
log(debugChange, "make map didn't work")
|
||||
newt.text = "error"
|
||||
}
|
||||
newt.s = newt.val[i]
|
||||
newt.doUserEvent()
|
||||
n.S = newt.val[i]
|
||||
n.doUserEvent()
|
||||
})
|
||||
|
||||
n.tk = newt
|
||||
|
@ -53,28 +53,26 @@ func (t *andlabsT) SetDropdown(i int) {
|
|||
t.uiCombobox.SetSelected(i)
|
||||
}
|
||||
|
||||
func (n *node) AddDropdownName(a *toolkit.Action) {
|
||||
log(debugToolkit, "gui.andlabs.AddDropdownName()", n.WidgetId, "add:", a.S)
|
||||
func (n *node) AddDropdownName(s string) {
|
||||
log(logInfo, "AddDropdownName()", n.WidgetId, "add:", s)
|
||||
|
||||
t := n.tk
|
||||
if (t == nil) {
|
||||
log(debugToolkit, "go.andlabs.AddDropdownName() toolkit struct == nil. name=", n.Name, a.S)
|
||||
listMap(debugToolkit)
|
||||
log(logInfo, "AddDropdownName() toolkit struct == nil. name=", n.Name, s)
|
||||
return
|
||||
}
|
||||
t.addDropdownName(a.S)
|
||||
t.addDropdownName(s)
|
||||
}
|
||||
|
||||
func (n *node) SetDropdownName(a *toolkit.Action, s string) {
|
||||
log(debugChange, "gui.andlabs.SetDropdown()", n.WidgetId, ",", s)
|
||||
log(logInfo, "SetDropdown()", n.WidgetId, ",", s)
|
||||
|
||||
t := n.tk
|
||||
if (t == nil) {
|
||||
log(debugError, "ERROR: SetDropdown() FAILED mapToolkits[w] == nil. name=", n.WidgetId, s)
|
||||
listMap(debugError)
|
||||
log(debugError, "SetDropdown() FAILED mapToolkits[w] == nil. name=", n.WidgetId, s)
|
||||
return
|
||||
}
|
||||
t.SetDropdown(1)
|
||||
// TODO: send back to wit/gui goroutine with the chan
|
||||
t.s = s
|
||||
n.S = s
|
||||
}
|
||||
|
|
|
@ -8,27 +8,15 @@ import (
|
|||
func (p *node) newGroup(n *node) {
|
||||
log(debugToolkit, "NewGroup()", n.Name)
|
||||
|
||||
t := p.tk
|
||||
if (t == nil) {
|
||||
log(debugToolkit, "NewGroup() toolkit struct == nil. name=", n.Name)
|
||||
listMap(debugToolkit)
|
||||
}
|
||||
newt := t.rawGroup(n.Name)
|
||||
n.tk = newt
|
||||
p.place(n)
|
||||
}
|
||||
newt := new(andlabsT)
|
||||
|
||||
// make new Group here
|
||||
func (t *andlabsT) rawGroup(title string) *andlabsT {
|
||||
var newt andlabsT
|
||||
newt.Name = title
|
||||
log(debugToolkit, "NewGroup() create", n.Name)
|
||||
|
||||
log(debugToolkit, "NewGroup() create", newt.Name)
|
||||
|
||||
g := ui.NewGroup(newt.Name)
|
||||
g := ui.NewGroup(n.Name)
|
||||
g.SetMargined(margin)
|
||||
newt.uiGroup = g
|
||||
newt.uiControl = g
|
||||
|
||||
return &newt
|
||||
n.tk = newt
|
||||
p.place(n)
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ func init() {
|
|||
// log(debugToolkit, "gui/toolkit init() Setting defaultBehavior = true")
|
||||
setDefaultBehavior(true)
|
||||
|
||||
andlabs = make(map[int]*andlabsT)
|
||||
// andlabs = make(map[int]*andlabsT)
|
||||
pluginChan = make(chan toolkit.Action, 1)
|
||||
|
||||
log(logNow, "Init() start channel reciever")
|
||||
|
|
|
@ -1,84 +1,9 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/andlabs/ui"
|
||||
"git.wit.org/wit/gui/toolkit"
|
||||
)
|
||||
|
||||
func rawAction(a toolkit.Action) {
|
||||
log(debugAction, "rawAction() START a.ActionType =", a.ActionType)
|
||||
log(debugAction, "rawAction() START a.S =", a.S)
|
||||
|
||||
if (a.ActionType == toolkit.InitToolkit) {
|
||||
// TODO: make sure to only do this once
|
||||
// go uiMain.Do(func() {
|
||||
// ui.Main(demoUI)
|
||||
// go catchActionChannel()
|
||||
// })
|
||||
// try doing this on toolkit load in init()
|
||||
return
|
||||
}
|
||||
|
||||
log(logNow, "rawAction() START a.WidgetId =", a.WidgetId, "a.ParentId =", a.ParentId)
|
||||
switch a.WidgetType {
|
||||
case toolkit.Flag:
|
||||
flag(&a)
|
||||
return
|
||||
}
|
||||
|
||||
n := rootNode.findWidgetId(a.WidgetId)
|
||||
|
||||
switch a.ActionType {
|
||||
case toolkit.Add:
|
||||
ui.QueueMain(func() {
|
||||
add(a)
|
||||
})
|
||||
sleep(.1)
|
||||
case toolkit.Show:
|
||||
a.B = true
|
||||
show(&a)
|
||||
case toolkit.Hide:
|
||||
a.B = false
|
||||
show(&a)
|
||||
case toolkit.Enable:
|
||||
a.B = true
|
||||
enable(&a)
|
||||
case toolkit.Disable:
|
||||
a.B = false
|
||||
enable(&a)
|
||||
case toolkit.Get:
|
||||
n.setText(&a)
|
||||
case toolkit.GetText:
|
||||
switch a.WidgetType {
|
||||
case toolkit.Textbox:
|
||||
t := andlabs[a.WidgetId]
|
||||
a.S = t.s
|
||||
}
|
||||
case toolkit.Set:
|
||||
n.setText(&a)
|
||||
case toolkit.SetText:
|
||||
n.setText(&a)
|
||||
case toolkit.AddText:
|
||||
n.setText(&a)
|
||||
case toolkit.Margin:
|
||||
pad(&a)
|
||||
case toolkit.Unmargin:
|
||||
pad(&a)
|
||||
case toolkit.Pad:
|
||||
pad(&a)
|
||||
case toolkit.Unpad:
|
||||
pad(&a)
|
||||
case toolkit.Delete:
|
||||
uiDelete(&a)
|
||||
case toolkit.Move:
|
||||
log(debugNow, "rawAction() attempt to move() =", a.ActionType, a.WidgetType)
|
||||
move(&a)
|
||||
default:
|
||||
log(debugError, "rawAction() Unknown =", a.ActionType, a.WidgetType)
|
||||
}
|
||||
log(debugAction, "rawAction() END =", a.ActionType, a.WidgetType)
|
||||
}
|
||||
|
||||
func flag(a *toolkit.Action) {
|
||||
// log(debugFlags, "plugin Send() flag parent =", p.Name, p.Type)
|
||||
// log(debugFlags, "plugin Send() flag child =", c.Name, c.Type)
|
||||
|
@ -108,15 +33,15 @@ func flag(a *toolkit.Action) {
|
|||
}
|
||||
|
||||
func (n *node) setText(a *toolkit.Action) {
|
||||
t := andlabs[a.WidgetId]
|
||||
t := n.tk
|
||||
if (t == nil) {
|
||||
log(debugError, "setText error. andlabs[id] == nil", a.WidgetId)
|
||||
log(debugError, "setText error. tk == nil", n.Name, n.WidgetId)
|
||||
actionDump(debugError, a)
|
||||
return
|
||||
}
|
||||
log(debugChange, "setText() Attempt on", t.WidgetType, "with", a.S)
|
||||
log(debugChange, "setText() Attempt on", n.WidgetType, "with", a.S)
|
||||
|
||||
switch t.WidgetType {
|
||||
switch n.WidgetType {
|
||||
case toolkit.Window:
|
||||
t.uiWindow.SetTitle(a.S)
|
||||
case toolkit.Tab:
|
||||
|
@ -169,7 +94,7 @@ func (n *node) setText(a *toolkit.Action) {
|
|||
case toolkit.Dropdown:
|
||||
switch a.ActionType {
|
||||
case toolkit.AddText:
|
||||
n.AddDropdownName(a)
|
||||
n.AddDropdownName(a.S)
|
||||
case toolkit.Set:
|
||||
var orig int
|
||||
var i int = -1
|
||||
|
@ -215,6 +140,6 @@ func (n *node) setText(a *toolkit.Action) {
|
|||
log(debugError, "setText() unknown", a.ActionType, "on checkbox", t.Name)
|
||||
}
|
||||
default:
|
||||
log(debugError, "plugin Send() Don't know how to setText on", t.WidgetType, "yet", a.ActionType)
|
||||
log(debugError, "plugin Send() Don't know how to setText on", n.WidgetType, "yet", a.ActionType)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,8 +13,8 @@ func (p *node) newSlider(n *node) {
|
|||
newt.uiControl = s
|
||||
|
||||
s.OnChanged(func(spin *ui.Slider) {
|
||||
newt.i = newt.uiSlider.Value()
|
||||
newt.doUserEvent()
|
||||
n.I = newt.uiSlider.Value()
|
||||
n.doUserEvent()
|
||||
})
|
||||
|
||||
n.tk = newt
|
||||
|
|
|
@ -13,8 +13,8 @@ func (p *node) newSpinner(n *node) {
|
|||
newt.uiControl = s
|
||||
|
||||
s.OnChanged(func(s *ui.Spinbox) {
|
||||
newt.i = newt.uiSpinbox.Value()
|
||||
newt.doUserEvent()
|
||||
n.I = newt.uiSpinbox.Value()
|
||||
n.doUserEvent()
|
||||
})
|
||||
|
||||
n.tk = newt
|
||||
|
|
|
@ -5,7 +5,7 @@ import "git.wit.org/wit/gui/toolkit"
|
|||
import "github.com/andlabs/ui"
|
||||
import _ "github.com/andlabs/ui/winmanifest"
|
||||
|
||||
var andlabs map[int]*andlabsT
|
||||
// var andlabs map[int]*andlabsT
|
||||
// var callback func(int) bool
|
||||
var callback chan toolkit.Action
|
||||
|
||||
|
@ -38,8 +38,8 @@ type node struct {
|
|||
|
||||
// stores the raw toolkit internals
|
||||
type andlabsT struct {
|
||||
wId int // widget ID
|
||||
WidgetType toolkit.WidgetType
|
||||
// wId int // widget ID
|
||||
// WidgetType toolkit.WidgetType
|
||||
|
||||
Name string
|
||||
Text string
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
// "git.wit.org/wit/gui/toolkit"
|
||||
"git.wit.org/wit/gui/toolkit"
|
||||
|
||||
"github.com/andlabs/ui"
|
||||
_ "github.com/andlabs/ui/winmanifest"
|
||||
|
@ -22,15 +22,15 @@ import (
|
|||
func (p *node) newTab(n *node) {
|
||||
var newt *andlabsT
|
||||
|
||||
if (p.WidgetType != toolkit.Window) {
|
||||
log(debugToolkit, "newTab() uiWindow == nil. I can't add a toolbar without window", n.WidgetId, n.ParentId)
|
||||
return
|
||||
}
|
||||
t := p.tk
|
||||
|
||||
log(debugToolkit, "newTab() START", n.WidgetId, n.ParentId)
|
||||
|
||||
if (t.uiTab == nil) {
|
||||
if (t.uiWindow == nil) {
|
||||
log(debugToolkit, "newTab() uiWindow == nil. I can't add a toolbar without window", n.WidgetId, n.ParentId)
|
||||
return
|
||||
}
|
||||
// this means you have to make a new tab
|
||||
log(debugToolkit, "newTab() GOOD. This should be the first tab:", n.WidgetId, n.ParentId)
|
||||
newt = rawTab(t.uiWindow, n.Text)
|
||||
|
@ -41,22 +41,6 @@ func (p *node) newTab(n *node) {
|
|||
newt = t.appendTab(n.Text)
|
||||
}
|
||||
|
||||
// add the structure to the array
|
||||
if (andlabs[n.WidgetId] == nil) {
|
||||
log(logInfo, "newTab() MAPPED", n.WidgetId, n.ParentId)
|
||||
andlabs[n.WidgetId] = newt
|
||||
newt.WidgetType = n.WidgetType
|
||||
} else {
|
||||
log(debugError, "newTab() DO WHAT?", n.WidgetId, n.ParentId)
|
||||
log(debugError, "THIS IS BAD")
|
||||
}
|
||||
|
||||
newt.Name = n.Name
|
||||
|
||||
log(debugToolkit, "t:")
|
||||
t.Dump(debugToolkit)
|
||||
log(debugToolkit, "newt:")
|
||||
newt.Dump(debugToolkit)
|
||||
n.tk = newt
|
||||
}
|
||||
|
||||
|
|
|
@ -13,8 +13,8 @@ func (p *node) newTextbox(n *node) {
|
|||
newt.uiControl = e
|
||||
|
||||
e.OnChanged(func(spin *ui.MultilineEntry) {
|
||||
newt.s = spin.Text()
|
||||
newt.doUserEvent()
|
||||
n.S = spin.Text()
|
||||
n.doUserEvent()
|
||||
})
|
||||
n.tk = newt
|
||||
p.place(n)
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
// "git.wit.org/wit/gui/toolkit"
|
||||
)
|
||||
|
||||
// This is a map between the widgets in wit/gui and the internal structures of gocui
|
||||
|
||||
// var mapWidgets map[*andlabsT]*toolkit.Widget
|
||||
// var mapToolkits map[*toolkit.Widget]*andlabsT
|
||||
|
||||
// This lists out the known mappings
|
||||
// deprecate and use instead the GUI interface
|
||||
func listMap(b bool) {
|
||||
log(b, "listMap() disabled HERE. output too big")
|
||||
return
|
||||
log(b, "listMap() HERE mapToolkits()")
|
||||
for i, t := range andlabs {
|
||||
log(b, "andlabs =", t, "widgetId =", i)
|
||||
t.Dump(b)
|
||||
}
|
||||
log(b, "listMap() HERE mapWidgets()")
|
||||
log(b, "listMap() HERE FIXME. output too big")
|
||||
}
|
|
@ -3,8 +3,6 @@ package main
|
|||
import (
|
||||
"github.com/andlabs/ui"
|
||||
_ "github.com/andlabs/ui/winmanifest"
|
||||
|
||||
"git.wit.org/wit/gui/toolkit"
|
||||
)
|
||||
|
||||
func (t *andlabsT) MessageWindow(msg1 string, msg2 string) {
|
||||
|
@ -19,31 +17,28 @@ func newWindow(n *node) {
|
|||
var newt *andlabsT
|
||||
|
||||
newt = new(andlabsT)
|
||||
newt.WidgetType = toolkit.Window
|
||||
newt.wId = n.WidgetId
|
||||
|
||||
// menubar bool is if the OS defined border on the window should be used
|
||||
win := ui.NewWindow(n.Name, n.X, n.Y, menubar)
|
||||
win.SetBorderless(canvas)
|
||||
win.SetMargined(margin)
|
||||
win.OnClosing(func(*ui.Window) bool {
|
||||
newt.doUserEvent()
|
||||
n.doUserEvent()
|
||||
return true
|
||||
})
|
||||
newt.uiWindow = win
|
||||
newt.uiControl = win
|
||||
newt.Name = n.Name
|
||||
|
||||
n.tk = newt
|
||||
win.Show()
|
||||
return
|
||||
}
|
||||
|
||||
func (t *andlabsT) SetWindowTitle(title string) {
|
||||
log(debugToolkit, "toolkit NewWindow", t.Name, "title", title)
|
||||
win := t.uiWindow
|
||||
func (n *node) SetWindowTitle(title string) {
|
||||
log(debugToolkit, "toolkit NewWindow", n.Text, "title", title)
|
||||
win := n.tk.uiWindow
|
||||
if (win == nil) {
|
||||
log(debugError, "Error: no window", t.wId)
|
||||
log(debugError, "Error: no window", n.WidgetId)
|
||||
} else {
|
||||
win.SetTitle(title)
|
||||
log(debugToolkit, "Setting the window title", title)
|
||||
|
|
Loading…
Reference in New Issue