2024-01-18 00:08:37 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"go.wit.com/log"
|
2024-01-28 02:20:31 -06:00
|
|
|
"go.wit.com/toolkits/tree"
|
2024-01-18 04:10:08 -06:00
|
|
|
"go.wit.com/widget"
|
2024-01-18 00:08:37 -06:00
|
|
|
)
|
|
|
|
|
2024-01-28 17:40:02 -06:00
|
|
|
func (tk *guiWidget) placeBox(startW int, startH int) (int, int) {
|
2024-01-28 11:07:51 -06:00
|
|
|
if tk.WidgetType != widget.Box {
|
2024-01-28 17:40:02 -06:00
|
|
|
return 0, 0
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
2024-01-28 17:40:02 -06:00
|
|
|
tk.dumpTree("beforebox")
|
2024-01-18 00:08:37 -06:00
|
|
|
|
|
|
|
newW := startW
|
|
|
|
newH := startH
|
2024-01-28 17:40:02 -06:00
|
|
|
var maxW int = 0
|
|
|
|
var maxH int = 0
|
|
|
|
|
2024-01-28 02:20:31 -06:00
|
|
|
for _, child := range tk.children {
|
2024-01-28 17:40:02 -06:00
|
|
|
sizeW, sizeH := child.placeWidgets(newW, newH)
|
2024-01-28 02:20:31 -06:00
|
|
|
if child.direction == widget.Horizontal {
|
2024-01-28 17:40:02 -06:00
|
|
|
log.Log(NOW, "BOX IS HORIZONTAL", tk.String(), "newWH()", newW, newH, "child()", sizeW, sizeH, child.String())
|
2024-01-18 00:08:37 -06:00
|
|
|
// expand based on the child width
|
2024-01-28 17:40:02 -06:00
|
|
|
newW += sizeW
|
|
|
|
maxW += sizeW
|
|
|
|
if sizeH > maxH {
|
|
|
|
maxH = sizeH
|
|
|
|
}
|
2024-01-18 00:08:37 -06:00
|
|
|
} else {
|
2024-01-28 17:40:02 -06:00
|
|
|
log.Log(NOW, "BOX IS VERTICAL ", tk.String(), "newWH()", newW, newH, "child()", sizeW, sizeH, child.String())
|
2024-01-18 00:08:37 -06:00
|
|
|
// expand based on the child height
|
2024-01-28 17:40:02 -06:00
|
|
|
newH += sizeH
|
|
|
|
maxH += sizeH
|
|
|
|
if sizeW > maxW {
|
|
|
|
maxW = sizeW
|
|
|
|
}
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// just compute this every time?
|
|
|
|
// newR := n.realGocuiSize()
|
|
|
|
|
2024-01-28 17:40:02 -06:00
|
|
|
tk.dumpTree("afterbox")
|
|
|
|
return maxW, maxH
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
|
|
|
|
2024-01-28 17:40:02 -06:00
|
|
|
func (tk *guiWidget) placeWidgets(startW int, startH int) (int, int) {
|
2024-01-28 11:07:51 -06:00
|
|
|
if tk == nil {
|
2024-01-28 17:40:02 -06:00
|
|
|
return 0, 0
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
2024-01-28 02:20:31 -06:00
|
|
|
if me.treeRoot == nil {
|
2024-01-28 17:40:02 -06:00
|
|
|
return 0, 0
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
|
|
|
|
2024-01-28 11:07:51 -06:00
|
|
|
switch tk.WidgetType {
|
2024-01-18 00:08:37 -06:00
|
|
|
case widget.Window:
|
2024-01-28 17:40:02 -06:00
|
|
|
newW := startW
|
|
|
|
newH := startH
|
|
|
|
var maxH int = 0
|
2024-01-28 02:20:31 -06:00
|
|
|
for _, child := range tk.children {
|
2024-01-28 17:40:02 -06:00
|
|
|
sizeW, sizeH := child.placeWidgets(newW, newH)
|
|
|
|
if sizeW < 20 {
|
|
|
|
sizeW = 20
|
|
|
|
}
|
|
|
|
newW += sizeW
|
|
|
|
if sizeH > maxH {
|
|
|
|
maxH = sizeH
|
|
|
|
}
|
|
|
|
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
2024-01-28 17:40:02 -06:00
|
|
|
return newW - startW, maxH
|
2024-01-18 00:08:37 -06:00
|
|
|
case widget.Tab:
|
|
|
|
case widget.Grid:
|
2024-01-28 17:40:02 -06:00
|
|
|
return tk.placeGrid(startW, startH)
|
2024-01-18 00:08:37 -06:00
|
|
|
case widget.Box:
|
2024-01-28 17:40:02 -06:00
|
|
|
return tk.placeBox(startW, startH)
|
2024-01-18 00:08:37 -06:00
|
|
|
case widget.Group:
|
|
|
|
// move the group to the parent's next location
|
2024-01-28 02:20:31 -06:00
|
|
|
tk.gocuiSetWH(startW, startH)
|
2024-01-28 14:03:06 -06:00
|
|
|
tk.dumpTree("start place")
|
2024-01-18 00:08:37 -06:00
|
|
|
|
|
|
|
newW := startW + me.GroupPadW
|
|
|
|
newH := startH + 3 // normal hight of the group label
|
2024-01-28 17:40:02 -06:00
|
|
|
var maxW int = 0
|
2024-01-18 00:08:37 -06:00
|
|
|
// now move all the children aka: run place() on them
|
2024-01-28 02:20:31 -06:00
|
|
|
for _, child := range tk.children {
|
2024-01-28 17:40:02 -06:00
|
|
|
sizeW, sizeH := child.placeWidgets(newW, newH)
|
|
|
|
// newR := child.realGocuiSize()
|
2024-01-18 00:08:37 -06:00
|
|
|
// w := newR.w1 - newR.w0
|
2024-01-28 17:40:02 -06:00
|
|
|
// h := newR.h1 - newR.h0
|
2024-01-18 00:08:37 -06:00
|
|
|
|
|
|
|
// increment straight down
|
2024-01-28 17:40:02 -06:00
|
|
|
newH += sizeH
|
|
|
|
if sizeW > maxW {
|
|
|
|
maxW = sizeW
|
|
|
|
}
|
|
|
|
log.Log(INFO, "REAL HEIGHT sizeW:", sizeW, "sizeH:", sizeH)
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
2024-01-28 14:03:06 -06:00
|
|
|
tk.dumpTree("end place")
|
2024-01-28 17:40:02 -06:00
|
|
|
return maxW, newH - startH
|
2024-01-18 00:08:37 -06:00
|
|
|
default:
|
2024-01-28 02:20:31 -06:00
|
|
|
tk.gocuiSetWH(startW, startH)
|
2024-01-28 17:40:02 -06:00
|
|
|
return tk.Width(), tk.Height()
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
2024-01-28 17:40:02 -06:00
|
|
|
return 0, 0
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
|
|
|
|
2024-01-28 17:40:02 -06:00
|
|
|
func (w *guiWidget) placeGrid(startW int, startH int) (int, int) {
|
2024-01-28 13:14:43 -06:00
|
|
|
w.showWidgetPlacement("grid0:")
|
2024-01-28 11:07:51 -06:00
|
|
|
if w.WidgetType != widget.Grid {
|
2024-01-28 17:40:02 -06:00
|
|
|
return 0, 0
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// first compute the max sizes of the rows and columns
|
2024-01-28 02:20:31 -06:00
|
|
|
for _, child := range w.children {
|
2024-01-28 17:40:02 -06:00
|
|
|
childW, childH := child.placeWidgets(startW, startH)
|
2024-01-18 00:08:37 -06:00
|
|
|
|
|
|
|
// set the child's realWidth, and grid offset
|
|
|
|
if w.widths[child.AtW] < childW {
|
|
|
|
w.widths[child.AtW] = childW
|
|
|
|
}
|
|
|
|
if w.heights[child.AtH] < childH {
|
|
|
|
w.heights[child.AtH] = childH
|
|
|
|
}
|
2024-01-28 13:14:43 -06:00
|
|
|
// child.showWidgetPlacement("grid: ")
|
2024-01-28 02:20:31 -06:00
|
|
|
log.Log(INFO, "placeGrid:", child.String(), "child()", childW, childH, "At()", child.AtW, child.AtH)
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
|
|
|
|
2024-01-28 17:40:02 -06:00
|
|
|
var maxW int = 0
|
|
|
|
var maxH int = 0
|
|
|
|
|
2024-01-18 00:08:37 -06:00
|
|
|
// find the width and height offset of the grid for AtW,AtH
|
2024-01-28 02:20:31 -06:00
|
|
|
for _, child := range w.children {
|
2024-01-28 13:14:43 -06:00
|
|
|
child.showWidgetPlacement("grid1:")
|
2024-01-18 00:08:37 -06:00
|
|
|
|
|
|
|
var totalW, totalH int
|
|
|
|
for i, w := range w.widths {
|
|
|
|
if i < child.AtW {
|
|
|
|
totalW += w
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for i, h := range w.heights {
|
|
|
|
if i < child.AtH {
|
|
|
|
totalH += h
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// the new corner to move the child to
|
|
|
|
newW := startW + totalW
|
|
|
|
newH := startH + totalH
|
|
|
|
|
2024-01-28 17:40:02 -06:00
|
|
|
if totalW > maxW {
|
|
|
|
maxW = totalW
|
|
|
|
}
|
|
|
|
if totalH > maxH {
|
|
|
|
maxH = totalH
|
|
|
|
}
|
|
|
|
|
2024-01-28 02:20:31 -06:00
|
|
|
log.Log(INFO, "placeGrid:", child.String(), "new()", newW, newH, "At()", child.AtW, child.AtH)
|
2024-01-28 11:07:51 -06:00
|
|
|
child.placeWidgets(newW, newH)
|
2024-01-28 13:14:43 -06:00
|
|
|
child.showWidgetPlacement("grid2:")
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
2024-01-28 13:14:43 -06:00
|
|
|
w.showWidgetPlacement("grid3:")
|
2024-01-28 17:40:02 -06:00
|
|
|
return maxW, maxH
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// computes the real, actual size of all the gocli objects in a widget
|
2024-01-28 11:07:51 -06:00
|
|
|
func (w *guiWidget) realGocuiSize() *rectType {
|
|
|
|
var f func(tk *guiWidget, r *rectType)
|
2024-01-18 00:08:37 -06:00
|
|
|
newR := new(rectType)
|
|
|
|
// initialize the values to opposite
|
|
|
|
newR.w0 = 80
|
|
|
|
newR.h0 = 24
|
|
|
|
if me.baseGui != nil {
|
|
|
|
maxW, maxH := me.baseGui.Size()
|
|
|
|
newR.w0 = maxW
|
|
|
|
newR.h0 = maxH
|
|
|
|
}
|
|
|
|
newR.w1 = 0
|
|
|
|
newR.h1 = 0
|
|
|
|
|
|
|
|
// expand the rectangle to the biggest thing displayed
|
2024-01-28 11:07:51 -06:00
|
|
|
f = func(tk *guiWidget, r *rectType) {
|
2024-01-28 02:20:31 -06:00
|
|
|
newR := tk.gocuiSize
|
|
|
|
if !tk.isFake {
|
2024-01-18 00:08:37 -06:00
|
|
|
if r.w0 > newR.w0 {
|
|
|
|
r.w0 = newR.w0
|
|
|
|
}
|
|
|
|
if r.h0 > newR.h0 {
|
|
|
|
r.h0 = newR.h0
|
|
|
|
}
|
|
|
|
if r.w1 < newR.w1 {
|
|
|
|
r.w1 = newR.w1
|
|
|
|
}
|
|
|
|
if r.h1 < newR.h1 {
|
|
|
|
r.h1 = newR.h1
|
|
|
|
}
|
|
|
|
}
|
2024-01-28 02:20:31 -06:00
|
|
|
for _, child := range tk.children {
|
2024-01-28 11:07:51 -06:00
|
|
|
f(child, r)
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
|
|
|
}
|
2024-01-28 11:07:51 -06:00
|
|
|
f(w, newR)
|
2024-01-18 00:08:37 -06:00
|
|
|
return newR
|
|
|
|
}
|
|
|
|
|
2024-01-28 02:20:31 -06:00
|
|
|
func textSize(n *tree.Node) (int, int) {
|
|
|
|
var tk *guiWidget
|
|
|
|
tk = n.TK.(*guiWidget)
|
2024-01-18 00:08:37 -06:00
|
|
|
var width, height int
|
|
|
|
|
2024-01-28 02:20:31 -06:00
|
|
|
for _, s := range strings.Split(widget.GetString(tk.value), "\n") {
|
2024-01-18 00:08:37 -06:00
|
|
|
if width < len(s) {
|
|
|
|
width = len(s)
|
|
|
|
}
|
|
|
|
height += 1
|
|
|
|
}
|
|
|
|
return width, height
|
|
|
|
}
|