andlabs: deprecate old code

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2023-04-27 12:41:42 -05:00
parent d282c353e6
commit d671c3c441
19 changed files with 188 additions and 436 deletions

View File

@ -1,65 +1,50 @@
package main package main
import ( import (
"github.com/andlabs/ui"
"git.wit.org/wit/gui/toolkit" "git.wit.org/wit/gui/toolkit"
) )
func show(a *toolkit.Action) { func (n *node) show(b bool) {
if (a == nil) { if n.tk == nil {
log(debugError, "nil is probably already hidden")
return return
} }
log(debugError, "show()", a.WidgetId) if n.tk.uiControl == nil {
t := andlabs[a.WidgetId]
if (t == nil) {
log(debugError, "show() toolkit struct == nil. for", a.WidgetId)
return return
} }
if (b) {
if (a.B) { n.tk.uiControl.Show()
t.uiControl.Show()
} else { } else {
t.uiControl.Hide() n.tk.uiControl.Hide()
} }
} }
func enable(a *toolkit.Action) { func (n *node) enable(b bool) {
if (a == nil) { if n.tk == nil {
log(debugError, "nil is probably already hidden")
return return
} }
log(debugError, "enable() name =", a.WidgetId) if n.tk.uiControl == nil {
t := andlabs[a.WidgetId]
if (t == nil) {
log(debugToolkit, "enable() toolkit struct == nil. for id =", a.WidgetId)
return return
} }
if (b) {
if (a.B) { n.tk.uiControl.Enable()
t.uiControl.Enable()
} else { } else {
t.uiControl.Disable() n.tk.uiControl.Disable()
} }
} }
func pad(a *toolkit.Action) { func (n *node) pad(at toolkit.ActionType) {
if (a == nil) {
log(debugError, "pad() ERROR: nil is probably already hidden")
return
}
log(debugError, "pad()") log(debugError, "pad()")
t := andlabs[a.WidgetId] t := n.tk
if (t == nil) { if (t == nil) {
log(debugError, "pad() toolkit struct == nil. for", a.WidgetId) log(debugError, "pad() toolkit struct == nil. for", n.WidgetId)
return return
} }
switch t.WidgetType { switch n.WidgetType {
case toolkit.Group: case toolkit.Group:
switch a.ActionType { switch at {
case toolkit.Margin: case toolkit.Margin:
t.uiGroup.SetMargined(true) t.uiGroup.SetMargined(true)
case toolkit.Unmargin: case toolkit.Unmargin:
@ -70,7 +55,7 @@ func pad(a *toolkit.Action) {
t.uiGroup.SetMargined(false) t.uiGroup.SetMargined(false)
} }
case toolkit.Tab: case toolkit.Tab:
switch a.ActionType { switch at {
case toolkit.Margin: case toolkit.Margin:
tabSetMargined(t.uiTab, true) tabSetMargined(t.uiTab, true)
case toolkit.Unmargin: case toolkit.Unmargin:
@ -81,7 +66,7 @@ func pad(a *toolkit.Action) {
tabSetMargined(t.uiTab, false) tabSetMargined(t.uiTab, false)
} }
case toolkit.Window: case toolkit.Window:
switch a.ActionType { switch at {
case toolkit.Margin: case toolkit.Margin:
t.uiWindow.SetMargined(true) t.uiWindow.SetMargined(true)
case toolkit.Unmargin: case toolkit.Unmargin:
@ -92,7 +77,7 @@ func pad(a *toolkit.Action) {
t.uiWindow.SetBorderless(true) t.uiWindow.SetBorderless(true)
} }
case toolkit.Grid: case toolkit.Grid:
switch a.ActionType { switch at {
case toolkit.Margin: case toolkit.Margin:
t.uiGrid.SetPadded(true) t.uiGrid.SetPadded(true)
case toolkit.Unmargin: case toolkit.Unmargin:
@ -103,7 +88,7 @@ func pad(a *toolkit.Action) {
t.uiGrid.SetPadded(false) t.uiGrid.SetPadded(false)
} }
case toolkit.Box: case toolkit.Box:
switch a.ActionType { switch at {
case toolkit.Margin: case toolkit.Margin:
t.uiBox.SetPadded(true) t.uiBox.SetPadded(true)
case toolkit.Unmargin: case toolkit.Unmargin:
@ -114,58 +99,31 @@ func pad(a *toolkit.Action) {
t.uiBox.SetPadded(false) t.uiBox.SetPadded(false)
} }
case toolkit.Textbox: case toolkit.Textbox:
log(debugError, "TODO: implement expand for", a.ActionType) log(debugError, "TODO: implement ActionType =", at)
log(debugError, "TODO: implement expand for", a.ActionType)
log(debugError, "TODO: implement expand for", a.ActionType)
log(debugError, "TODO: implement expand for", a.ActionType)
default: default:
log(debugError, "TODO: implement pad() for", a.ActionType) log(debugError, "TODO: implement pad() for", at)
} }
} }
func move(a *toolkit.Action) { func (n *node) move(newParent *node) {
log(debugNow, "move()", a.WidgetId, "to", a.ParentId) p := n.parent
tWidget := andlabs[a.WidgetId] switch p.WidgetType {
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 {
case toolkit.Group: case toolkit.Group:
switch a.ActionType {
case toolkit.Margin:
tParent.uiGroup.SetMargined(true)
}
case toolkit.Tab: case toolkit.Tab:
switch a.ActionType { // tabSetMargined(tParent.uiTab, true)
case toolkit.Margin:
// tabSetMargined(tParent.uiTab, true)
}
case toolkit.Window: case toolkit.Window:
switch a.ActionType { // t.uiWindow.SetBorderless(false)
case toolkit.Pad:
// t.uiWindow.SetBorderless(false)
}
case toolkit.Grid: case toolkit.Grid:
switch a.ActionType { // t.uiGrid.SetPadded(true)
case toolkit.Pad:
// t.uiGrid.SetPadded(true)
}
case toolkit.Box: case toolkit.Box:
log(debugNow, "TODO: move() for a =", a.ActionType) log(logInfo, "TODO: move() where =", p.ParentId)
log(debugNow, "TODO: move() where =", a.ParentId) log(logInfo, "TODO: move() for widget =", n.WidgetId)
log(debugNow, "TODO: move() for widget =", a.WidgetId)
stretchy = true 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) // log(debugNow, "is there a tParent parent? =", tParent.parent)
// tParent.uiBox.Delete(0) // tParent.uiBox.Delete(0)
@ -173,73 +131,111 @@ func move(a *toolkit.Action) {
// tWidget.uiControl.Disable() // tWidget.uiControl.Disable()
// sleep(.8) // sleep(.8)
default: default:
log(debugError, "TODO: need to implement move() for a =", a.ActionType) log(logError, "TODO: need to implement move() for type =", n.WidgetType)
log(debugError, "TODO: need to implement move() for where =", a.ParentId) log(logError, "TODO: need to implement move() for where =", p.ParentId)
log(debugError, "TODO: need to implement move() for widget =", a.WidgetId) log(logError, "TODO: need to implement move() for widget =", n.WidgetId)
} }
} }
func uiDelete(a *toolkit.Action) { func (n *node) Delete() {
if (andlabs[a.ParentId] == nil) { p := n.parent
log(debugError, "uiDelete() ERROR: can not uiDelete to nil") log(debugNow, "uiDelete()", n.WidgetId, "to", p.WidgetId)
return
}
if (andlabs[a.WidgetId] == nil) {
log(debugError, "uiDelete() ERROR: can not uiDelete nil")
return
}
log(debugNow, "uiDelete()", a.WidgetId, "to", a.ParentId)
tWidget := andlabs[a.WidgetId] switch p.WidgetType {
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 {
case toolkit.Group: case toolkit.Group:
switch a.ActionType { // tParent.uiGroup.SetMargined(true)
case toolkit.Margin:
tParent.uiGroup.SetMargined(true)
}
case toolkit.Tab: case toolkit.Tab:
switch a.ActionType { // tabSetMargined(tParent.uiTab, true)
case toolkit.Margin:
// tabSetMargined(tParent.uiTab, true)
}
case toolkit.Window: case toolkit.Window:
switch a.ActionType { // t.uiWindow.SetBorderless(false)
case toolkit.Pad:
// t.uiWindow.SetBorderless(false)
}
case toolkit.Grid: case toolkit.Grid:
switch a.ActionType { // t.uiGrid.SetPadded(true)
case toolkit.Pad:
// t.uiGrid.SetPadded(true)
}
case toolkit.Box: case toolkit.Box:
log(debugNow, "tWidget.boxC =", tParent.Name) log(debugNow, "tWidget.boxC =", p.Name)
log(debugNow, "is there a tParent parent? =", tParent.parent) log(debugNow, "is there a tParent parent? =", p.parent)
if (tWidget.boxC < 1) { if (p.tk.boxC < 1) {
log(debugNow, "Can not delete from Box. already empty. tWidget.boxC =", tParent.boxC) log(debugNow, "Can not delete from Box. already empty. tWidget.boxC =", p.tk.boxC)
return return
} }
tWidget.uiBox.Delete(0) p.tk.uiBox.Delete(0)
tWidget.boxC -= 1 p.tk.boxC -= 1
// this didn't work: // this didn't work:
// tWidget.uiControl.Disable() // tWidget.uiControl.Disable()
// sleep(.8) // sleep(.8)
// tParent.uiBox.Append(tWidget.uiControl, stretchy) // tParent.uiBox.Append(tWidget.uiControl, stretchy)
default: default:
log(debugError, "TODO: need to implement uiDelete() for a =", a.ActionType) log(debugError, "TODO: need to implement uiDelete() for widget =", n.WidgetId, n.WidgetType)
log(debugError, "TODO: need to implement uiDelete() for where =", a.ParentId) log(debugError, "TODO: need to implement uiDelete() for parent =", p.WidgetId, p.WidgetType)
log(debugError, "TODO: need to implement uiDelete() for widget =", a.WidgetId)
} }
} }
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)
}

View File

@ -16,11 +16,6 @@ func actionDump(b bool, a *toolkit.Action) {
} }
func add(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) { if (a.WidgetType == toolkit.Root) {
rootNode = addWidget(&a, nil) rootNode = addWidget(&a, nil)
return return
@ -100,70 +95,6 @@ func add(a toolkit.Action) {
// -- (0,0) -- (1,0) -- (1,0) -- // -- (0,0) -- (1,0) -- (1,0) --
// -- (0,1) -- (1,1) -- (1,1) -- // -- (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 { func (p *node) place(n *node) bool {
log(logInfo, "place() START", n.WidgetType, n.Name) log(logInfo, "place() START", n.WidgetType, n.Name)

View File

@ -9,26 +9,12 @@ import (
func (p *node) newBox(n *node) { func (p *node) newBox(n *node) {
log(debugToolkit, "newBox()", n.Name) log(debugToolkit, "newBox()", n.Name)
t := p.tk newt := new(andlabsT)
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
var box *ui.Box var box *ui.Box
newt.Name = title
log(debugToolkit, "rawBox() create", newt.Name) log(debugToolkit, "rawBox() create", newt.Name)
if (b) { if (n.B) {
box = ui.NewHorizontalBox() box = ui.NewHorizontalBox()
} else { } else {
box = ui.NewVerticalBox() box = ui.NewVerticalBox()
@ -37,6 +23,7 @@ func (t *andlabsT) rawBox(title string, b bool) *andlabsT {
newt.uiBox = box newt.uiBox = box
newt.uiControl = box newt.uiControl = box
newt.boxC = 0
return &newt n.tk = newt
p.place(n)
} }

View File

@ -19,12 +19,10 @@ func (p *node) newButton(n *node) {
b := ui.NewButton(n.Text) b := ui.NewButton(n.Text)
newt.uiButton = b newt.uiButton = b
newt.uiControl = b newt.uiControl = b
newt.wId = n.WidgetId
newt.WidgetType = n.WidgetType
newt.parent = t newt.parent = t
b.OnClicked(func(*ui.Button) { b.OnClicked(func(*ui.Button) {
newt.doUserEvent() n.doUserEvent()
}) })
n.tk = newt n.tk = newt

View File

@ -8,10 +8,6 @@ import (
func (p *node) newCheckbox(n *node) { func (p *node) newCheckbox(n *node) {
newt := new(andlabsT) newt := new(andlabsT)
log(debugToolkit, "newCheckbox()", n.Name, n.WidgetType) 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.uiCheckbox = ui.NewCheckbox(n.Text)
newt.uiControl = newt.uiCheckbox newt.uiControl = newt.uiCheckbox
@ -19,7 +15,7 @@ func (p *node) newCheckbox(n *node) {
newt.uiCheckbox.OnToggled(func(spin *ui.Checkbox) { newt.uiCheckbox.OnToggled(func(spin *ui.Checkbox) {
newt.b = newt.checked() newt.b = newt.checked()
log(debugChange, "val =", newt.b) log(debugChange, "val =", newt.b)
newt.doUserEvent() n.doUserEvent()
}) })
n.tk = newt n.tk = newt
@ -29,16 +25,3 @@ func (p *node) newCheckbox(n *node) {
func (t *andlabsT) checked() bool { func (t *andlabsT) checked() bool {
return t.uiCheckbox.Checked() 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)
}
*/

View File

@ -18,8 +18,8 @@ func (p *node) newCombobox(n *node) {
newt.val = make(map[int]string) newt.val = make(map[int]string)
cb.OnChanged(func(spin *ui.EditableCombobox) { cb.OnChanged(func(spin *ui.EditableCombobox) {
newt.s = spin.Text() n.S = spin.Text()
newt.doUserEvent() n.doUserEvent()
}) })
n.tk = newt n.tk = newt

View File

@ -56,26 +56,21 @@ func addWidget(a *toolkit.Action, tk *andlabsT) *node {
if n.parent != nil { if n.parent != nil {
n.parent.children = append(n.parent.children, n) 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 return n
} }
func (t *andlabsT) doUserEvent() { func (n *node) doUserEvent() {
if (callback == nil) { if (callback == nil) {
log(debugError, "doUserEvent() callback == nil", t.wId) log(debugError, "doUserEvent() callback == nil", n.WidgetId)
return return
} }
var a toolkit.Action var a toolkit.Action
a.WidgetId = t.wId a.WidgetId = n.WidgetId
a.Name = t.Name a.Name = n.Name
a.S = t.s a.Text = n.Text
a.I = t.i a.S = n.S
a.B = t.b a.I = n.I
a.B = n.B
a.ActionType = toolkit.User a.ActionType = toolkit.User
log(logInfo, "doUserEvent() START: send a user event to the callback channel") log(logInfo, "doUserEvent() START: send a user event to the callback channel")
callback <- a callback <- a

View File

@ -6,11 +6,13 @@ import "git.wit.org/wit/gui/toolkit"
// delete the child widget from the parent // delete the child widget from the parent
// p = parent, c = child // p = parent, c = child
func destroy(pId int, cId int) { func (n *node) destroy() {
log(true, "delete()", pId, cId) pId := n.parent.WidgetId
cId := n.WidgetId
log(logNow, "delete()", pId, cId)
pt := andlabs[pId] pt := n.parent.tk
ct := andlabs[cId] ct := n.tk
if (ct == nil) { if (ct == nil) {
log(true, "delete FAILED (ct = mapToolkit[c] == nil) for c", pId, cId) log(true, "delete FAILED (ct = mapToolkit[c] == nil) for c", pId, cId)
// this pukes out a whole universe of shit // this pukes out a whole universe of shit
@ -18,7 +20,7 @@ func destroy(pId int, cId int) {
return return
} }
switch ct.WidgetType { switch n.WidgetType {
case toolkit.Button: case toolkit.Button:
log(true, "Should delete Button here:", ct.Name) log(true, "Should delete Button here:", ct.Name)
log(true, "Parent:") log(true, "Parent:")
@ -40,12 +42,6 @@ func destroy(pId int, cId int) {
case toolkit.Window: case toolkit.Window:
log(true, "Should delete Window here:", ct.Name) log(true, "Should delete Window here:", ct.Name)
default: 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") log(true, "Fuckit, let's destroy a button")
if (ct.uiButton != nil) { if (ct.uiButton != nil) {
pt.uiBox.Delete(4) pt.uiBox.Delete(4)

View File

@ -25,8 +25,8 @@ func (p *node) newDropdown(n *node) {
log(debugChange, "make map didn't work") log(debugChange, "make map didn't work")
newt.text = "error" newt.text = "error"
} }
newt.s = newt.val[i] n.S = newt.val[i]
newt.doUserEvent() n.doUserEvent()
}) })
n.tk = newt n.tk = newt
@ -53,28 +53,26 @@ func (t *andlabsT) SetDropdown(i int) {
t.uiCombobox.SetSelected(i) t.uiCombobox.SetSelected(i)
} }
func (n *node) AddDropdownName(a *toolkit.Action) { func (n *node) AddDropdownName(s string) {
log(debugToolkit, "gui.andlabs.AddDropdownName()", n.WidgetId, "add:", a.S) log(logInfo, "AddDropdownName()", n.WidgetId, "add:", s)
t := n.tk t := n.tk
if (t == nil) { if (t == nil) {
log(debugToolkit, "go.andlabs.AddDropdownName() toolkit struct == nil. name=", n.Name, a.S) log(logInfo, "AddDropdownName() toolkit struct == nil. name=", n.Name, s)
listMap(debugToolkit)
return return
} }
t.addDropdownName(a.S) t.addDropdownName(s)
} }
func (n *node) SetDropdownName(a *toolkit.Action, s string) { 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 t := n.tk
if (t == nil) { if (t == nil) {
log(debugError, "ERROR: SetDropdown() FAILED mapToolkits[w] == nil. name=", n.WidgetId, s) log(debugError, "SetDropdown() FAILED mapToolkits[w] == nil. name=", n.WidgetId, s)
listMap(debugError)
return return
} }
t.SetDropdown(1) t.SetDropdown(1)
// TODO: send back to wit/gui goroutine with the chan // TODO: send back to wit/gui goroutine with the chan
t.s = s n.S = s
} }

View File

@ -8,27 +8,15 @@ import (
func (p *node) newGroup(n *node) { func (p *node) newGroup(n *node) {
log(debugToolkit, "NewGroup()", n.Name) log(debugToolkit, "NewGroup()", n.Name)
t := p.tk newt := new(andlabsT)
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)
}
// make new Group here log(debugToolkit, "NewGroup() create", n.Name)
func (t *andlabsT) rawGroup(title string) *andlabsT {
var newt andlabsT
newt.Name = title
log(debugToolkit, "NewGroup() create", newt.Name) g := ui.NewGroup(n.Name)
g := ui.NewGroup(newt.Name)
g.SetMargined(margin) g.SetMargined(margin)
newt.uiGroup = g newt.uiGroup = g
newt.uiControl = g newt.uiControl = g
return &newt n.tk = newt
p.place(n)
} }

View File

@ -60,7 +60,7 @@ func init() {
// log(debugToolkit, "gui/toolkit init() Setting defaultBehavior = true") // log(debugToolkit, "gui/toolkit init() Setting defaultBehavior = true")
setDefaultBehavior(true) setDefaultBehavior(true)
andlabs = make(map[int]*andlabsT) // andlabs = make(map[int]*andlabsT)
pluginChan = make(chan toolkit.Action, 1) pluginChan = make(chan toolkit.Action, 1)
log(logNow, "Init() start channel reciever") log(logNow, "Init() start channel reciever")

View File

@ -1,84 +1,9 @@
package main package main
import ( import (
"github.com/andlabs/ui"
"git.wit.org/wit/gui/toolkit" "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) { func flag(a *toolkit.Action) {
// log(debugFlags, "plugin Send() flag parent =", p.Name, p.Type) // log(debugFlags, "plugin Send() flag parent =", p.Name, p.Type)
// log(debugFlags, "plugin Send() flag child =", c.Name, c.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) { func (n *node) setText(a *toolkit.Action) {
t := andlabs[a.WidgetId] t := n.tk
if (t == nil) { 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) actionDump(debugError, a)
return 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: case toolkit.Window:
t.uiWindow.SetTitle(a.S) t.uiWindow.SetTitle(a.S)
case toolkit.Tab: case toolkit.Tab:
@ -169,7 +94,7 @@ func (n *node) setText(a *toolkit.Action) {
case toolkit.Dropdown: case toolkit.Dropdown:
switch a.ActionType { switch a.ActionType {
case toolkit.AddText: case toolkit.AddText:
n.AddDropdownName(a) n.AddDropdownName(a.S)
case toolkit.Set: case toolkit.Set:
var orig int var orig int
var i int = -1 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) log(debugError, "setText() unknown", a.ActionType, "on checkbox", t.Name)
} }
default: 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)
} }
} }

View File

@ -13,8 +13,8 @@ func (p *node) newSlider(n *node) {
newt.uiControl = s newt.uiControl = s
s.OnChanged(func(spin *ui.Slider) { s.OnChanged(func(spin *ui.Slider) {
newt.i = newt.uiSlider.Value() n.I = newt.uiSlider.Value()
newt.doUserEvent() n.doUserEvent()
}) })
n.tk = newt n.tk = newt

View File

@ -13,8 +13,8 @@ func (p *node) newSpinner(n *node) {
newt.uiControl = s newt.uiControl = s
s.OnChanged(func(s *ui.Spinbox) { s.OnChanged(func(s *ui.Spinbox) {
newt.i = newt.uiSpinbox.Value() n.I = newt.uiSpinbox.Value()
newt.doUserEvent() n.doUserEvent()
}) })
n.tk = newt n.tk = newt

View File

@ -5,7 +5,7 @@ import "git.wit.org/wit/gui/toolkit"
import "github.com/andlabs/ui" import "github.com/andlabs/ui"
import _ "github.com/andlabs/ui/winmanifest" import _ "github.com/andlabs/ui/winmanifest"
var andlabs map[int]*andlabsT // var andlabs map[int]*andlabsT
// var callback func(int) bool // var callback func(int) bool
var callback chan toolkit.Action var callback chan toolkit.Action
@ -38,8 +38,8 @@ type node struct {
// stores the raw toolkit internals // stores the raw toolkit internals
type andlabsT struct { type andlabsT struct {
wId int // widget ID // wId int // widget ID
WidgetType toolkit.WidgetType // WidgetType toolkit.WidgetType
Name string Name string
Text string Text string

View File

@ -1,7 +1,7 @@
package main package main
import ( import (
// "git.wit.org/wit/gui/toolkit" "git.wit.org/wit/gui/toolkit"
"github.com/andlabs/ui" "github.com/andlabs/ui"
_ "github.com/andlabs/ui/winmanifest" _ "github.com/andlabs/ui/winmanifest"
@ -22,15 +22,15 @@ import (
func (p *node) newTab(n *node) { func (p *node) newTab(n *node) {
var newt *andlabsT 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 t := p.tk
log(debugToolkit, "newTab() START", n.WidgetId, n.ParentId) log(debugToolkit, "newTab() START", n.WidgetId, n.ParentId)
if (t.uiTab == nil) { 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 // this means you have to make a new tab
log(debugToolkit, "newTab() GOOD. This should be the first tab:", n.WidgetId, n.ParentId) log(debugToolkit, "newTab() GOOD. This should be the first tab:", n.WidgetId, n.ParentId)
newt = rawTab(t.uiWindow, n.Text) newt = rawTab(t.uiWindow, n.Text)
@ -41,22 +41,6 @@ func (p *node) newTab(n *node) {
newt = t.appendTab(n.Text) 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 n.tk = newt
} }

View File

@ -13,8 +13,8 @@ func (p *node) newTextbox(n *node) {
newt.uiControl = e newt.uiControl = e
e.OnChanged(func(spin *ui.MultilineEntry) { e.OnChanged(func(spin *ui.MultilineEntry) {
newt.s = spin.Text() n.S = spin.Text()
newt.doUserEvent() n.doUserEvent()
}) })
n.tk = newt n.tk = newt
p.place(n) p.place(n)

View File

@ -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")
}

View File

@ -3,8 +3,6 @@ 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) MessageWindow(msg1 string, msg2 string) { func (t *andlabsT) MessageWindow(msg1 string, msg2 string) {
@ -19,31 +17,28 @@ func newWindow(n *node) {
var newt *andlabsT var newt *andlabsT
newt = new(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 // 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 := ui.NewWindow(n.Name, n.X, n.Y, menubar)
win.SetBorderless(canvas) win.SetBorderless(canvas)
win.SetMargined(margin) win.SetMargined(margin)
win.OnClosing(func(*ui.Window) bool { win.OnClosing(func(*ui.Window) bool {
newt.doUserEvent() n.doUserEvent()
return true return true
}) })
newt.uiWindow = win newt.uiWindow = win
newt.uiControl = win newt.uiControl = win
newt.Name = n.Name
n.tk = newt n.tk = newt
win.Show() win.Show()
return return
} }
func (t *andlabsT) SetWindowTitle(title string) { func (n *node) SetWindowTitle(title string) {
log(debugToolkit, "toolkit NewWindow", t.Name, "title", title) log(debugToolkit, "toolkit NewWindow", n.Text, "title", title)
win := t.uiWindow win := n.tk.uiWindow
if (win == nil) { if (win == nil) {
log(debugError, "Error: no window", t.wId) log(debugError, "Error: no window", n.WidgetId)
} else { } else {
win.SetTitle(title) win.SetTitle(title)
log(debugToolkit, "Setting the window title", title) log(debugToolkit, "Setting the window title", title)