summaryrefslogtreecommitdiff
path: root/place.go
diff options
context:
space:
mode:
Diffstat (limited to 'place.go')
-rw-r--r--place.go100
1 files changed, 56 insertions, 44 deletions
diff --git a/place.go b/place.go
index 217325d..9543e07 100644
--- a/place.go
+++ b/place.go
@@ -4,29 +4,33 @@ import (
"strings"
"go.wit.com/log"
+ "go.wit.com/toolkits/tree"
"go.wit.com/widget"
)
-func (n *node) placeBox(startW int, startH int) {
+func placeBox(n *tree.Node, startW int, startH int) {
+ var tk *guiWidget
+ tk = n.TK.(*guiWidget)
+
if n.WidgetType != widget.Box {
return
}
- n.showWidgetPlacement(true, "boxS()")
+ showWidgetPlacement(n, true, "boxS()")
newW := startW
newH := startH
- for _, child := range n.children {
- child.placeWidgets(newW, newH)
+ for _, child := range tk.children {
+ placeWidgets(child.node, newW, newH)
// n.showWidgetPlacement(logNow, "boxS()")
- newR := child.realGocuiSize()
+ newR := realGocuiSize(child.node)
w := newR.w1 - newR.w0
h := newR.h1 - newR.h0
- if n.direction == widget.Horizontal {
- log.Log(NOW, "BOX IS HORIZONTAL", n.progname, "newWH()", newW, newH, "child()", w, h, child.progname)
+ if child.direction == widget.Horizontal {
+ log.Log(NOW, "BOX IS HORIZONTAL", n.String(), "newWH()", newW, newH, "child()", w, h, child.String())
// expand based on the child width
newW += w
} else {
- log.Log(NOW, "BOX IS VERTICAL ", n.progname, "newWH()", newW, newH, "child()", w, h, child.progname)
+ log.Log(NOW, "BOX IS VERTICAL ", n.String(), "newWH()", newW, newH, "child()", w, h, child.String())
// expand based on the child height
newH += h
}
@@ -35,43 +39,46 @@ func (n *node) placeBox(startW int, startH int) {
// just compute this every time?
// newR := n.realGocuiSize()
- n.showWidgetPlacement(true, "boxE()")
+ showWidgetPlacement(n, true, "boxE()")
}
-func (n *node) placeWidgets(startW int, startH int) {
+func placeWidgets(n *tree.Node, startW int, startH int) {
if n == nil {
return
}
- if me.rootNode == nil {
+ if me.treeRoot == nil {
return
}
+ var tk *guiWidget
+ tk = n.TK.(*guiWidget)
+
switch n.WidgetType {
case widget.Window:
- for _, child := range n.children {
- child.placeWidgets(me.RawW, me.RawH)
+ for _, child := range tk.children {
+ placeWidgets(child.node, me.RawW, me.RawH)
return
}
case widget.Tab:
- for _, child := range n.children {
- child.placeWidgets(me.RawW, me.RawH)
+ for _, child := range tk.children {
+ placeWidgets(child.node, me.RawW, me.RawH)
return
}
case widget.Grid:
- n.placeGrid(startW, startH)
+ placeGrid(n, startW, startH)
case widget.Box:
- n.placeBox(startW, startH)
+ placeBox(n, startW, startH)
case widget.Group:
// move the group to the parent's next location
- n.gocuiSetWH(startW, startH)
- n.showWidgetPlacement(true, "group()")
+ tk.gocuiSetWH(startW, startH)
+ showWidgetPlacement(n, true, "group()")
newW := startW + me.GroupPadW
newH := startH + 3 // normal hight of the group label
// now move all the children aka: run place() on them
- for _, child := range n.children {
- child.placeWidgets(newW, newH)
- newR := child.realGocuiSize()
+ for _, child := range tk.children {
+ placeWidgets(child.node, newW, newH)
+ newR := realGocuiSize(child.node)
// w := newR.w1 - newR.w0
h := newR.h1 - newR.h0
@@ -79,21 +86,22 @@ func (n *node) placeWidgets(startW int, startH int) {
newH += h
}
default:
- n.gocuiSetWH(startW, startH)
+ tk.gocuiSetWH(startW, startH)
// n.moveTo(startW, startH)
}
}
-func (n *node) placeGrid(startW int, startH int) {
- w := n.tk
- n.showWidgetPlacement(true, "grid0:")
+func placeGrid(n *tree.Node, startW int, startH int) {
+ var w *guiWidget
+ w = n.TK.(*guiWidget)
+ showWidgetPlacement(n, true, "grid0:")
if n.WidgetType != widget.Grid {
return
}
// first compute the max sizes of the rows and columns
- for _, child := range n.children {
- newR := child.realGocuiSize()
+ for _, child := range w.children {
+ newR := realGocuiSize(child.node)
childW := newR.w1 - newR.w0
childH := newR.h1 - newR.h0
@@ -105,12 +113,12 @@ func (n *node) placeGrid(startW int, startH int) {
w.heights[child.AtH] = childH
}
// child.showWidgetPlacement(logInfo, "grid: ")
- log.Log(INFO, "placeGrid:", child.progname, "child()", childW, childH, "At()", child.AtW, child.AtH)
+ log.Log(INFO, "placeGrid:", child.String(), "child()", childW, childH, "At()", child.AtW, child.AtH)
}
// find the width and height offset of the grid for AtW,AtH
- for _, child := range n.children {
- child.showWidgetPlacement(true, "grid1:")
+ for _, child := range w.children {
+ showWidgetPlacement(w.node, true, "grid1:")
var totalW, totalH int
for i, w := range w.widths {
@@ -128,16 +136,16 @@ func (n *node) placeGrid(startW int, startH int) {
newW := startW + totalW
newH := startH + totalH
- log.Log(INFO, "placeGrid:", child.progname, "new()", newW, newH, "At()", child.AtW, child.AtH)
- child.placeWidgets(newW, newH)
- child.showWidgetPlacement(true, "grid2:")
+ log.Log(INFO, "placeGrid:", child.String(), "new()", newW, newH, "At()", child.AtW, child.AtH)
+ placeWidgets(child.node, newW, newH)
+ showWidgetPlacement(child.node, true, "grid2:")
}
- n.showWidgetPlacement(true, "grid3:")
+ showWidgetPlacement(n, true, "grid3:")
}
// computes the real, actual size of all the gocli objects in a widget
-func (n *node) realGocuiSize() *rectType {
- var f func(n *node, r *rectType)
+func realGocuiSize(n *tree.Node) *rectType {
+ var f func(n *tree.Node, r *rectType)
newR := new(rectType)
// initialize the values to opposite
newR.w0 = 80
@@ -151,9 +159,11 @@ func (n *node) realGocuiSize() *rectType {
newR.h1 = 0
// expand the rectangle to the biggest thing displayed
- f = func(n *node, r *rectType) {
- newR := n.tk.gocuiSize
- if !n.tk.isFake {
+ f = func(n *tree.Node, r *rectType) {
+ var tk *guiWidget
+ tk = n.TK.(*guiWidget)
+ newR := tk.gocuiSize
+ if !tk.isFake {
if r.w0 > newR.w0 {
r.w0 = newR.w0
}
@@ -167,18 +177,20 @@ func (n *node) realGocuiSize() *rectType {
r.h1 = newR.h1
}
}
- for _, child := range n.children {
- f(child, r)
+ for _, child := range tk.children {
+ f(child.node, r)
}
}
f(n, newR)
return newR
}
-func (n *node) textSize() (int, int) {
+func textSize(n *tree.Node) (int, int) {
+ var tk *guiWidget
+ tk = n.TK.(*guiWidget)
var width, height int
- for _, s := range strings.Split(widget.GetString(n.value), "\n") {
+ for _, s := range strings.Split(widget.GetString(tk.value), "\n") {
if width < len(s) {
width = len(s)
}