andlabs: window and tab now in binary tree
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
b789fbbe56
commit
3cdbc285e3
|
@ -21,36 +21,18 @@ func add(a toolkit.Action) {
|
||||||
actionDump(debugError, &a)
|
actionDump(debugError, &a)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (a.WidgetId == 0) {
|
if (a.WidgetType == toolkit.Root) {
|
||||||
log(debugError, "add() error. w.WidgetId == 0")
|
rootNode = addWidget(&a, nil)
|
||||||
actionDump(debugError, &a)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
n := addWidget(&a, nil)
|
||||||
|
|
||||||
// for now, window gets handled without checking where == nil)
|
switch n.WidgetType {
|
||||||
if (a.WidgetType == toolkit.Window) {
|
|
||||||
newWindow(a)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (andlabs[a.ParentId] == nil) {
|
|
||||||
// listMap(debugError) // memory corruption?
|
|
||||||
log(debugError, "add() Widget.Name =", a.Name)
|
|
||||||
log(debugError, "add() Widget.Type =", a.WidgetType)
|
|
||||||
log(debugError, "ERROR add() ERROR a.Parent map to t == nil. WidgetId =", a.WidgetId, "ParentId =", a.ParentId)
|
|
||||||
exit("can not add()")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
switch a.WidgetType {
|
|
||||||
case toolkit.Window:
|
case toolkit.Window:
|
||||||
newWindow(a)
|
newWindow(n)
|
||||||
return
|
return
|
||||||
case toolkit.Tab:
|
case toolkit.Tab:
|
||||||
log(debugError, "add() CAME AT THIS FROM add() =", a.Name)
|
newTab(n)
|
||||||
log(debugError, "add() CAME AT THIS FROM add() =", a.Name)
|
|
||||||
log(debugError, "add() CAME AT THIS FROM add() =", a.Name)
|
|
||||||
newTab(a)
|
|
||||||
return
|
return
|
||||||
case toolkit.Label:
|
case toolkit.Label:
|
||||||
newLabel(&a)
|
newLabel(&a)
|
||||||
|
@ -89,7 +71,7 @@ func add(a toolkit.Action) {
|
||||||
newImage(&a)
|
newImage(&a)
|
||||||
return
|
return
|
||||||
default:
|
default:
|
||||||
log(debugError, "add() error TODO: ", a.WidgetType, a.Name)
|
log(debugError, "add() error TODO: ", n.WidgetType, n.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,67 @@ import (
|
||||||
"git.wit.org/wit/gui/toolkit"
|
"git.wit.org/wit/gui/toolkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// searches the binary tree for a WidgetId
|
||||||
|
func (n *node) findWidgetId(id int) *node {
|
||||||
|
if (n == nil) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if n.WidgetId == id {
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, child := range n.children {
|
||||||
|
newN := child.findWidgetId(id)
|
||||||
|
if (newN != nil) {
|
||||||
|
return newN
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func addWidget(a *toolkit.Action, tk *andlabsT) *node {
|
||||||
|
n := new(node)
|
||||||
|
n.WidgetType = a.WidgetType
|
||||||
|
n.WidgetId = a.WidgetId
|
||||||
|
n.ParentId = a.ParentId
|
||||||
|
|
||||||
|
// copy the data from the action message
|
||||||
|
n.Name = a.Name
|
||||||
|
n.Text = a.Text
|
||||||
|
n.I = a.I
|
||||||
|
n.S = a.S
|
||||||
|
n.B = a.B
|
||||||
|
n.X = a.X
|
||||||
|
n.Y = a.Y
|
||||||
|
|
||||||
|
// store the internal toolkit information
|
||||||
|
n.tk = tk
|
||||||
|
|
||||||
|
if (a.WidgetType == toolkit.Root) {
|
||||||
|
log(logInfo, "addWidget() Root")
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rootNode.findWidgetId(a.WidgetId) != nil) {
|
||||||
|
log(logError, "addWidget() WidgetId already exists", a.WidgetId)
|
||||||
|
return rootNode.findWidgetId(a.WidgetId)
|
||||||
|
}
|
||||||
|
|
||||||
|
// add this new widget on the binary tree
|
||||||
|
n.parent = rootNode.findWidgetId(a.ParentId)
|
||||||
|
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 (t *andlabsT) doUserEvent() {
|
||||||
if (callback == nil) {
|
if (callback == nil) {
|
||||||
log(debugError, "doUserEvent() callback == nil", t.wId)
|
log(debugError, "doUserEvent() callback == nil", t.wId)
|
||||||
|
|
|
@ -12,6 +12,9 @@ import (
|
||||||
// this is the channel we get requests to make widgets
|
// this is the channel we get requests to make widgets
|
||||||
var pluginChan chan toolkit.Action
|
var pluginChan chan toolkit.Action
|
||||||
|
|
||||||
|
// the starting point of the binary tree
|
||||||
|
var rootNode *node
|
||||||
|
|
||||||
var uiMainUndef bool = true
|
var uiMainUndef bool = true
|
||||||
var uiMain sync.Once
|
var uiMain sync.Once
|
||||||
var muAction sync.Mutex
|
var muAction sync.Mutex
|
||||||
|
|
|
@ -9,6 +9,33 @@ 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
|
||||||
|
|
||||||
|
type node struct {
|
||||||
|
parent *node
|
||||||
|
children []*node
|
||||||
|
|
||||||
|
WidgetId int // widget ID
|
||||||
|
WidgetType toolkit.WidgetType
|
||||||
|
ParentId int // parent ID
|
||||||
|
|
||||||
|
Name string
|
||||||
|
Text string
|
||||||
|
|
||||||
|
// This is how the values are passed back and forth
|
||||||
|
// values from things like checkboxes & dropdown's
|
||||||
|
B bool
|
||||||
|
I int
|
||||||
|
S string
|
||||||
|
|
||||||
|
A any // switch to this or deprecate this? pros/cons?
|
||||||
|
|
||||||
|
// This is used for things like a slider(0,100)
|
||||||
|
X int
|
||||||
|
Y int
|
||||||
|
|
||||||
|
// the internal plugin toolkit structure
|
||||||
|
tk *andlabsT
|
||||||
|
}
|
||||||
|
|
||||||
// stores the raw toolkit internals
|
// stores the raw toolkit internals
|
||||||
type andlabsT struct {
|
type andlabsT struct {
|
||||||
wId int // widget ID
|
wId int // widget ID
|
||||||
|
@ -22,7 +49,7 @@ type andlabsT struct {
|
||||||
|
|
||||||
// tw *toolkit.Widget
|
// tw *toolkit.Widget
|
||||||
parent *andlabsT
|
parent *andlabsT
|
||||||
a toolkit.Action
|
children []*andlabsT
|
||||||
|
|
||||||
uiControl ui.Control
|
uiControl ui.Control
|
||||||
|
|
||||||
|
|
|
@ -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"
|
||||||
|
@ -19,38 +19,40 @@ import (
|
||||||
once there is one. If you send a Window here, it will replace
|
once there is one. If you send a Window here, it will replace
|
||||||
any existing tabs rather than adding a new one
|
any existing tabs rather than adding a new one
|
||||||
*/
|
*/
|
||||||
func (t *andlabsT) newTab(a toolkit.Action) {
|
func (p *node) newTab(n *node) {
|
||||||
// var w *ui.Window
|
// var w *ui.Window
|
||||||
var newt *andlabsT
|
var newt *andlabsT
|
||||||
|
|
||||||
log(debugToolkit, "newTab() START", a.WidgetId, a.ParentId)
|
t := p.tk
|
||||||
|
|
||||||
|
log(debugToolkit, "newTab() START", n.WidgetId, n.ParentId)
|
||||||
|
|
||||||
if (t.uiTab == nil) {
|
if (t.uiTab == nil) {
|
||||||
if (t.uiWindow == nil) {
|
if (t.uiWindow == nil) {
|
||||||
log(debugToolkit, "newTab() uiWindow == nil. I can't add a toolbar without window", a.WidgetId, a.ParentId)
|
log(debugToolkit, "newTab() uiWindow == nil. I can't add a toolbar without window", n.WidgetId, n.ParentId)
|
||||||
return
|
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:", a.WidgetId, a.ParentId)
|
log(debugToolkit, "newTab() GOOD. This should be the first tab:", n.WidgetId, n.ParentId)
|
||||||
newt = rawTab(t.uiWindow, a.Text)
|
newt = rawTab(t.uiWindow, n.Text)
|
||||||
t.uiTab = newt.uiTab
|
t.uiTab = newt.uiTab
|
||||||
} else {
|
} else {
|
||||||
// this means you have to append a tab
|
// this means you have to append a tab
|
||||||
log(debugToolkit, "newTab() GOOD. This should be an additional tab:", a.WidgetId, a.ParentId)
|
log(debugToolkit, "newTab() GOOD. This should be an additional tab:", n.WidgetId, n.ParentId)
|
||||||
newt = t.appendTab(a.Text)
|
newt = t.appendTab(n.Text)
|
||||||
}
|
}
|
||||||
|
|
||||||
// add the structure to the array
|
// add the structure to the array
|
||||||
if (andlabs[a.WidgetId] == nil) {
|
if (andlabs[n.WidgetId] == nil) {
|
||||||
log(logInfo, "newTab() MAPPED", a.WidgetId, a.ParentId)
|
log(logInfo, "newTab() MAPPED", n.WidgetId, n.ParentId)
|
||||||
andlabs[a.WidgetId] = newt
|
andlabs[n.WidgetId] = newt
|
||||||
newt.WidgetType = a.WidgetType
|
newt.WidgetType = n.WidgetType
|
||||||
} else {
|
} else {
|
||||||
log(debugError, "newTab() DO WHAT?", a.WidgetId, a.ParentId)
|
log(debugError, "newTab() DO WHAT?", n.WidgetId, n.ParentId)
|
||||||
log(debugError, "THIS IS BAD")
|
log(debugError, "THIS IS BAD")
|
||||||
}
|
}
|
||||||
|
|
||||||
newt.Name = a.Name
|
newt.Name = n.Name
|
||||||
|
|
||||||
log(debugToolkit, "t:")
|
log(debugToolkit, "t:")
|
||||||
t.Dump(debugToolkit)
|
t.Dump(debugToolkit)
|
||||||
|
@ -118,15 +120,9 @@ func (t *andlabsT) appendTab(name string) *andlabsT {
|
||||||
return &newT
|
return &newT
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTab(a toolkit.Action) {
|
func newTab(n *node) {
|
||||||
// w := a.Widget
|
log(logInfo, "newTab() add to parent id:", n.ParentId)
|
||||||
log(debugToolkit, "newTab()", a.ParentId)
|
|
||||||
|
|
||||||
t := andlabs[a.ParentId]
|
p := n.parent
|
||||||
if (t == nil) {
|
p.newTab(n)
|
||||||
log(debugToolkit, "newTab() parent toolkit == nil. new tab can not be made =", a.ParentId)
|
|
||||||
log(debugToolkit, "look for a window? check for an existing tab?")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
t.newTab(a)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,15 +15,15 @@ func (t *andlabsT) ErrorWindow(msg1 string, msg2 string) {
|
||||||
ui.MsgBoxError(t.uiWindow, msg1, msg2)
|
ui.MsgBoxError(t.uiWindow, msg1, msg2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func newWindow(a toolkit.Action) {
|
func newWindow(n *node) {
|
||||||
var newt *andlabsT
|
var newt *andlabsT
|
||||||
|
|
||||||
newt = new(andlabsT)
|
newt = new(andlabsT)
|
||||||
newt.WidgetType = toolkit.Window
|
newt.WidgetType = toolkit.Window
|
||||||
newt.wId = a.WidgetId
|
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(a.Name, a.X, a.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 {
|
||||||
|
@ -32,9 +32,9 @@ func newWindow(a toolkit.Action) {
|
||||||
})
|
})
|
||||||
newt.uiWindow = win
|
newt.uiWindow = win
|
||||||
newt.uiControl = win
|
newt.uiControl = win
|
||||||
newt.Name = a.Name
|
newt.Name = n.Name
|
||||||
|
|
||||||
andlabs[a.WidgetId] = newt
|
n.tk = newt
|
||||||
win.Show()
|
win.Show()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue