summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--place.go100
-rw-r--r--structs.go3
-rw-r--r--tab.go2
3 files changed, 68 insertions, 37 deletions
diff --git a/place.go b/place.go
index 53a0995..c792e45 100644
--- a/place.go
+++ b/place.go
@@ -8,60 +8,75 @@ import (
"go.wit.com/widget"
)
-func (tk *guiWidget) placeBox(startW int, startH int) {
+func (tk *guiWidget) placeBox(startW int, startH int) (int, int) {
if tk.WidgetType != widget.Box {
- return
+ return 0, 0
}
- tk.showWidgetPlacement("boxS()")
+ tk.dumpTree("beforebox")
newW := startW
newH := startH
+ var maxW int = 0
+ var maxH int = 0
+
for _, child := range tk.children {
- child.placeWidgets(newW, newH)
- // n.showWidgetPlacement("boxS()")
- newR := child.realGocuiSize()
- w := newR.w1 - newR.w0
- h := newR.h1 - newR.h0
+ sizeW, sizeH := child.placeWidgets(newW, newH)
if child.direction == widget.Horizontal {
- log.Log(NOW, "BOX IS HORIZONTAL", tk.String(), "newWH()", newW, newH, "child()", w, h, child.String())
+ log.Log(NOW, "BOX IS HORIZONTAL", tk.String(), "newWH()", newW, newH, "child()", sizeW, sizeH, child.String())
// expand based on the child width
- newW += w
+ newW += sizeW
+ maxW += sizeW
+ if sizeH > maxH {
+ maxH = sizeH
+ }
} else {
- log.Log(NOW, "BOX IS VERTICAL ", tk.String(), "newWH()", newW, newH, "child()", w, h, child.String())
+ log.Log(NOW, "BOX IS VERTICAL ", tk.String(), "newWH()", newW, newH, "child()", sizeW, sizeH, child.String())
// expand based on the child height
- newH += h
+ newH += sizeH
+ maxH += sizeH
+ if sizeW > maxW {
+ maxW = sizeW
+ }
}
}
// just compute this every time?
// newR := n.realGocuiSize()
- tk.showWidgetPlacement("boxE()")
+ tk.dumpTree("afterbox")
+ return maxW, maxH
}
-func (tk *guiWidget) placeWidgets(startW int, startH int) {
+func (tk *guiWidget) placeWidgets(startW int, startH int) (int, int) {
if tk == nil {
- return
+ return 0, 0
}
if me.treeRoot == nil {
- return
+ return 0, 0
}
switch tk.WidgetType {
case widget.Window:
+ newW := startW
+ newH := startH
+ var maxH int = 0
for _, child := range tk.children {
- child.placeWidgets(me.RawW, me.RawH)
- return
+ sizeW, sizeH := child.placeWidgets(newW, newH)
+ if sizeW < 20 {
+ sizeW = 20
+ }
+ newW += sizeW
+ if sizeH > maxH {
+ maxH = sizeH
+ }
+
}
+ return newW - startW, maxH
case widget.Tab:
- for _, child := range tk.children {
- child.placeWidgets(me.RawW, me.RawH)
- return
- }
case widget.Grid:
- tk.placeGrid(startW, startH)
+ return tk.placeGrid(startW, startH)
case widget.Box:
- tk.placeBox(startW, startH)
+ return tk.placeBox(startW, startH)
case widget.Group:
// move the group to the parent's next location
tk.gocuiSetWH(startW, startH)
@@ -69,35 +84,39 @@ func (tk *guiWidget) placeWidgets(startW int, startH int) {
newW := startW + me.GroupPadW
newH := startH + 3 // normal hight of the group label
+ var maxW int = 0
// now move all the children aka: run place() on them
for _, child := range tk.children {
- child.placeWidgets(newW, newH)
- newR := child.realGocuiSize()
+ sizeW, sizeH := child.placeWidgets(newW, newH)
+ // newR := child.realGocuiSize()
// w := newR.w1 - newR.w0
- h := newR.h1 - newR.h0
+ // h := newR.h1 - newR.h0
// increment straight down
- newH += h
- log.Log(INFO, "REAL HIGHT ADDED", h, "newH", newH)
+ newH += sizeH
+ if sizeW > maxW {
+ maxW = sizeW
+ }
+ log.Log(INFO, "REAL HEIGHT sizeW:", sizeW, "sizeH:", sizeH)
}
tk.dumpTree("end place")
+ return maxW, newH - startH
default:
tk.gocuiSetWH(startW, startH)
- // n.moveTo(startW, startH)
+ return tk.Width(), tk.Height()
}
+ return 0, 0
}
-func (w *guiWidget) placeGrid(startW int, startH int) {
+func (w *guiWidget) placeGrid(startW int, startH int) (int, int) {
w.showWidgetPlacement("grid0:")
if w.WidgetType != widget.Grid {
- return
+ return 0, 0
}
// first compute the max sizes of the rows and columns
for _, child := range w.children {
- newR := child.realGocuiSize()
- childW := newR.w1 - newR.w0
- childH := newR.h1 - newR.h0
+ childW, childH := child.placeWidgets(startW, startH)
// set the child's realWidth, and grid offset
if w.widths[child.AtW] < childW {
@@ -110,6 +129,9 @@ func (w *guiWidget) placeGrid(startW int, startH int) {
log.Log(INFO, "placeGrid:", child.String(), "child()", childW, childH, "At()", child.AtW, child.AtH)
}
+ var maxW int = 0
+ var maxH int = 0
+
// find the width and height offset of the grid for AtW,AtH
for _, child := range w.children {
child.showWidgetPlacement("grid1:")
@@ -130,11 +152,19 @@ func (w *guiWidget) placeGrid(startW int, startH int) {
newW := startW + totalW
newH := startH + totalH
+ if totalW > maxW {
+ maxW = totalW
+ }
+ if totalH > maxH {
+ maxH = totalH
+ }
+
log.Log(INFO, "placeGrid:", child.String(), "new()", newW, newH, "At()", child.AtW, child.AtH)
child.placeWidgets(newW, newH)
child.showWidgetPlacement("grid2:")
}
w.showWidgetPlacement("grid3:")
+ return maxW, maxH
}
// computes the real, actual size of all the gocli objects in a widget
diff --git a/structs.go b/structs.go
index 181db88..67555f1 100644
--- a/structs.go
+++ b/structs.go
@@ -160,6 +160,9 @@ type guiWidget struct {
// sometimes this isn't visible like with a Box or Grid
gocuiSize rectType
+ boxSizeW int
+ boxSizeH int
+
isCurrent bool // is this the currently displayed Window or Tab?
isFake bool // widget types like 'box' are 'false'
diff --git a/tab.go b/tab.go
index d92c427..0f0acb5 100644
--- a/tab.go
+++ b/tab.go
@@ -1,7 +1,5 @@
package main
-// implements widgets 'Window' and 'Tab'
-
import (
"strings"