summaryrefslogtreecommitdiff
path: root/place.go
diff options
context:
space:
mode:
Diffstat (limited to 'place.go')
-rw-r--r--place.go72
1 files changed, 31 insertions, 41 deletions
diff --git a/place.go b/place.go
index 9543e07..b6b96da 100644
--- a/place.go
+++ b/place.go
@@ -8,29 +8,26 @@ import (
"go.wit.com/widget"
)
-func placeBox(n *tree.Node, startW int, startH int) {
- var tk *guiWidget
- tk = n.TK.(*guiWidget)
-
- if n.WidgetType != widget.Box {
+func (tk *guiWidget) placeBox(startW int, startH int) {
+ if tk.WidgetType != widget.Box {
return
}
- showWidgetPlacement(n, true, "boxS()")
+ tk.showWidgetPlacement(true, "boxS()")
newW := startW
newH := startH
for _, child := range tk.children {
- placeWidgets(child.node, newW, newH)
+ child.placeWidgets(newW, newH)
// n.showWidgetPlacement(logNow, "boxS()")
- newR := realGocuiSize(child.node)
+ newR := child.realGocuiSize()
w := newR.w1 - newR.w0
h := newR.h1 - newR.h0
if child.direction == widget.Horizontal {
- log.Log(NOW, "BOX IS HORIZONTAL", n.String(), "newWH()", newW, newH, "child()", w, h, child.String())
+ log.Log(NOW, "BOX IS HORIZONTAL", tk.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.String(), "newWH()", newW, newH, "child()", w, h, child.String())
+ log.Log(NOW, "BOX IS VERTICAL ", tk.String(), "newWH()", newW, newH, "child()", w, h, child.String())
// expand based on the child height
newH += h
}
@@ -39,46 +36,43 @@ func placeBox(n *tree.Node, startW int, startH int) {
// just compute this every time?
// newR := n.realGocuiSize()
- showWidgetPlacement(n, true, "boxE()")
+ tk.showWidgetPlacement(true, "boxE()")
}
-func placeWidgets(n *tree.Node, startW int, startH int) {
- if n == nil {
+func (tk *guiWidget) placeWidgets(startW int, startH int) {
+ if tk == nil {
return
}
if me.treeRoot == nil {
return
}
- var tk *guiWidget
- tk = n.TK.(*guiWidget)
-
- switch n.WidgetType {
+ switch tk.WidgetType {
case widget.Window:
for _, child := range tk.children {
- placeWidgets(child.node, me.RawW, me.RawH)
+ child.placeWidgets(me.RawW, me.RawH)
return
}
case widget.Tab:
for _, child := range tk.children {
- placeWidgets(child.node, me.RawW, me.RawH)
+ child.placeWidgets(me.RawW, me.RawH)
return
}
case widget.Grid:
- placeGrid(n, startW, startH)
+ tk.placeGrid(startW, startH)
case widget.Box:
- placeBox(n, startW, startH)
+ tk.placeBox(startW, startH)
case widget.Group:
// move the group to the parent's next location
tk.gocuiSetWH(startW, startH)
- showWidgetPlacement(n, true, "group()")
+ tk.showWidgetPlacement(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 tk.children {
- placeWidgets(child.node, newW, newH)
- newR := realGocuiSize(child.node)
+ child.placeWidgets(newW, newH)
+ newR := child.realGocuiSize()
// w := newR.w1 - newR.w0
h := newR.h1 - newR.h0
@@ -91,17 +85,15 @@ func placeWidgets(n *tree.Node, startW int, startH int) {
}
}
-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 {
+func (w *guiWidget) placeGrid(startW int, startH int) {
+ w.showWidgetPlacement(true, "grid0:")
+ if w.WidgetType != widget.Grid {
return
}
// first compute the max sizes of the rows and columns
for _, child := range w.children {
- newR := realGocuiSize(child.node)
+ newR := child.realGocuiSize()
childW := newR.w1 - newR.w0
childH := newR.h1 - newR.h0
@@ -118,7 +110,7 @@ func placeGrid(n *tree.Node, startW int, startH int) {
// find the width and height offset of the grid for AtW,AtH
for _, child := range w.children {
- showWidgetPlacement(w.node, true, "grid1:")
+ child.showWidgetPlacement(true, "grid1:")
var totalW, totalH int
for i, w := range w.widths {
@@ -137,15 +129,15 @@ func placeGrid(n *tree.Node, startW int, startH int) {
newH := startH + totalH
log.Log(INFO, "placeGrid:", child.String(), "new()", newW, newH, "At()", child.AtW, child.AtH)
- placeWidgets(child.node, newW, newH)
- showWidgetPlacement(child.node, true, "grid2:")
+ child.placeWidgets(newW, newH)
+ child.showWidgetPlacement(true, "grid2:")
}
- showWidgetPlacement(n, true, "grid3:")
+ w.showWidgetPlacement(true, "grid3:")
}
// computes the real, actual size of all the gocli objects in a widget
-func realGocuiSize(n *tree.Node) *rectType {
- var f func(n *tree.Node, r *rectType)
+func (w *guiWidget) realGocuiSize() *rectType {
+ var f func(tk *guiWidget, r *rectType)
newR := new(rectType)
// initialize the values to opposite
newR.w0 = 80
@@ -159,9 +151,7 @@ func realGocuiSize(n *tree.Node) *rectType {
newR.h1 = 0
// expand the rectangle to the biggest thing displayed
- f = func(n *tree.Node, r *rectType) {
- var tk *guiWidget
- tk = n.TK.(*guiWidget)
+ f = func(tk *guiWidget, r *rectType) {
newR := tk.gocuiSize
if !tk.isFake {
if r.w0 > newR.w0 {
@@ -178,10 +168,10 @@ func realGocuiSize(n *tree.Node) *rectType {
}
}
for _, child := range tk.children {
- f(child.node, r)
+ f(child, r)
}
}
- f(n, newR)
+ f(w, newR)
return newR
}