andlabs: more into the binary tree

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2023-04-27 09:47:31 -05:00
parent 3cdbc285e3
commit bec9a99a15
4 changed files with 77 additions and 22 deletions

View File

@ -27,12 +27,13 @@ func add(a toolkit.Action) {
} }
n := addWidget(&a, nil) n := addWidget(&a, nil)
p := n.parent
switch n.WidgetType { switch n.WidgetType {
case toolkit.Window: case toolkit.Window:
newWindow(n) newWindow(n)
return return
case toolkit.Tab: case toolkit.Tab:
newTab(n) p.newTab(n)
return return
case toolkit.Label: case toolkit.Label:
newLabel(&a) newLabel(&a)
@ -62,10 +63,10 @@ func add(a toolkit.Action) {
newTextbox(&a) newTextbox(&a)
return return
case toolkit.Group: case toolkit.Group:
newGroup(&a) p.newGroup(n)
return return
case toolkit.Box: case toolkit.Box:
newBox(&a) p.newBox(n)
return return
case toolkit.Image: case toolkit.Image:
newImage(&a) newImage(&a)
@ -163,3 +164,59 @@ func place(a *toolkit.Action, t *andlabsT, newt *andlabsT) bool {
} }
return false return false
} }
func (p *node) place(n *node) bool {
log(logInfo, "place() START", n.WidgetType, n.Name)
if (p.tk == nil) {
log(logError, "p.tk == nil", p.Name, p.ParentId, p.WidgetType, p.tk)
log(logError, "n = ", n.Name, n.ParentId, n.WidgetType, n.tk)
panic("p.tk == nil")
}
log(logInfo, "place() switch", p.WidgetType)
switch p.WidgetType {
case toolkit.Grid:
log(debugGrid, "place() Grid try at Parent X,Y =", n.X, n.Y)
n.tk.gridX = n.X
n.tk.gridY = n.Y
log(debugGrid, "place() Grid try at gridX,gridY", n.tk.gridX, n.tk.gridY)
// at the very end, subtract 1 from X & Y since andlabs/ui starts counting at zero
p.tk.uiGrid.Append(n.tk.uiControl,
n.tk.gridY - 1, n.tk.gridX - 1, 1, 1,
false, ui.AlignFill, false, ui.AlignFill)
return true
case toolkit.Group:
if (p.tk.uiBox == nil) {
p.tk.uiGroup.SetChild(n.tk.uiControl)
log(debugGrid, "place() hack Group to use this as the box?", n.Name, n.WidgetType)
p.tk.uiBox = n.tk.uiBox
} else {
p.tk.uiBox.Append(n.tk.uiControl, stretchy)
}
return true
case toolkit.Tab:
if (p.tk.uiTab == nil) {
log(logError, "p.tk.uiTab == nil", p.tk)
panic("p.tk.uiTab == nil")
}
if (n.tk.uiControl == nil) {
log(logError, "n.tk.uiControl == nil", n.tk)
panic("n.tk.uiControl == nil")
}
p.tk.uiTab.Append(n.Text, n.tk.uiControl)
p.tk.boxC += 1
return true
case toolkit.Box:
log(logInfo, "place() uiBox =", p.tk.uiBox)
log(logInfo, "place() uiControl =", n.tk.uiControl)
p.tk.uiBox.Append(n.tk.uiControl, stretchy)
p.tk.boxC += 1
return true
case toolkit.Window:
p.tk.uiWindow.SetChild(n.tk.uiControl)
return true
default:
log(debugError, "place() how? Parent =", p.WidgetId, p.WidgetType)
}
return false
}

View File

@ -1,25 +1,23 @@
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"
) )
// make new Box here // make new Box here
func newBox(a *toolkit.Action) { func (p *node) newBox(n *node) {
log(debugToolkit, "newBox()", a.Name) log(debugToolkit, "newBox()", n.Name)
t := andlabs[a.ParentId] t := p.tk
if (t == nil) { if (t == nil) {
log(debugToolkit, "newBox() toolkit struct == nil. name=", a.Name) log(debugToolkit, "newBox() toolkit struct == nil. name=", n.Name)
listMap(debugToolkit) listMap(debugToolkit)
} }
newt := t.rawBox(a.Text, a.B) newt := t.rawBox(n.Text, n.B)
newt.boxC = 0 newt.boxC = 0
place(a, t, newt) n.tk = newt
andlabs[a.WidgetId] = newt p.place(n)
} }
// make new Box using andlabs/ui // make new Box using andlabs/ui

View File

@ -1,23 +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 newGroup(a *toolkit.Action) { func (p *node) newGroup(n *node) {
// w := a.Widget log(debugToolkit, "NewGroup()", n.Name)
log(debugToolkit, "NewGroup()", a.Name)
t := andlabs[a.ParentId] t := p.tk
if (t == nil) { if (t == nil) {
log(debugToolkit, "NewGroup() toolkit struct == nil. name=", a.Name) log(debugToolkit, "NewGroup() toolkit struct == nil. name=", n.Name)
listMap(debugToolkit) listMap(debugToolkit)
} }
newt := t.rawGroup(a.Name) newt := t.rawGroup(n.Name)
place(a, t, newt) n.tk = newt
p.place(n)
} }
// make new Group here // make new Group here

View File

@ -20,7 +20,6 @@ import (
any existing tabs rather than adding a new one any existing tabs rather than adding a new one
*/ */
func (p *node) newTab(n *node) { func (p *node) newTab(n *node) {
// var w *ui.Window
var newt *andlabsT var newt *andlabsT
t := p.tk t := p.tk
@ -58,6 +57,7 @@ func (p *node) newTab(n *node) {
t.Dump(debugToolkit) t.Dump(debugToolkit)
log(debugToolkit, "newt:") log(debugToolkit, "newt:")
newt.Dump(debugToolkit) newt.Dump(debugToolkit)
n.tk = newt
} }
// This sets _all_ the tabs to Margin = true // This sets _all_ the tabs to Margin = true
@ -120,9 +120,11 @@ func (t *andlabsT) appendTab(name string) *andlabsT {
return &newT return &newT
} }
/*
func newTab(n *node) { func newTab(n *node) {
log(logInfo, "newTab() add to parent id:", n.ParentId) log(logInfo, "newTab() add to parent id:", n.ParentId)
p := n.parent p := n.parent
p.newTab(n) p.newTab(n)
} }
*/