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 11:07:51 -06:00
|
|
|
func (tk *guiWidget) placeBox(startW int, startH int) {
|
|
|
|
if tk.WidgetType != widget.Box {
|
2024-01-18 00:08:37 -06:00
|
|
|
return
|
|
|
|
}
|
2024-01-28 11:07:51 -06:00
|
|
|
tk.showWidgetPlacement(true, "boxS()")
|
2024-01-18 00:08:37 -06:00
|
|
|
|
|
|
|
newW := startW
|
|
|
|
newH := startH
|
2024-01-28 02:20:31 -06:00
|
|
|
for _, child := range tk.children {
|
2024-01-28 11:07:51 -06:00
|
|
|
child.placeWidgets(newW, newH)
|
2024-01-18 00:08:37 -06:00
|
|
|
// n.showWidgetPlacement(logNow, "boxS()")
|
2024-01-28 11:07:51 -06:00
|
|
|
newR := child.realGocuiSize()
|
2024-01-18 00:08:37 -06:00
|
|
|
w := newR.w1 - newR.w0
|
|
|
|
h := newR.h1 - newR.h0
|
2024-01-28 02:20:31 -06:00
|
|
|
if child.direction == widget.Horizontal {
|
2024-01-28 11:07:51 -06:00
|
|
|
log.Log(NOW, "BOX IS HORIZONTAL", tk.String(), "newWH()", newW, newH, "child()", w, h, child.String())
|
2024-01-18 00:08:37 -06:00
|
|
|
// expand based on the child width
|
|
|
|
newW += w
|
|
|
|
} else {
|
2024-01-28 11:07:51 -06:00
|
|
|
log.Log(NOW, "BOX IS VERTICAL ", tk.String(), "newWH()", newW, newH, "child()", w, h, child.String())
|
2024-01-18 00:08:37 -06:00
|
|
|
// expand based on the child height
|
|
|
|
newH += h
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// just compute this every time?
|
|
|
|
// newR := n.realGocuiSize()
|
|
|
|
|
2024-01-28 11:07:51 -06:00
|
|
|
tk.showWidgetPlacement(true, "boxE()")
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
|
|
|
|
2024-01-28 11:07:51 -06:00
|
|
|
func (tk *guiWidget) placeWidgets(startW int, startH int) {
|
|
|
|
if tk == nil {
|
2024-01-18 00:08:37 -06:00
|
|
|
return
|
|
|
|
}
|
2024-01-28 02:20:31 -06:00
|
|
|
if me.treeRoot == nil {
|
2024-01-18 00:08:37 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
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 02:20:31 -06:00
|
|
|
for _, child := range tk.children {
|
2024-01-28 11:07:51 -06:00
|
|
|
child.placeWidgets(me.RawW, me.RawH)
|
2024-01-18 00:08:37 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
case widget.Tab:
|
2024-01-28 02:20:31 -06:00
|
|
|
for _, child := range tk.children {
|
2024-01-28 11:07:51 -06:00
|
|
|
child.placeWidgets(me.RawW, me.RawH)
|
2024-01-18 00:08:37 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
case widget.Grid:
|
2024-01-28 11:07:51 -06:00
|
|
|
tk.placeGrid(startW, startH)
|
2024-01-18 00:08:37 -06:00
|
|
|
case widget.Box:
|
2024-01-28 11:07:51 -06:00
|
|
|
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 11:07:51 -06:00
|
|
|
tk.showWidgetPlacement(true, "group()")
|
2024-01-18 00:08:37 -06:00
|
|
|
|
|
|
|
newW := startW + me.GroupPadW
|
|
|
|
newH := startH + 3 // normal hight of the group label
|
|
|
|
// 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 11:07:51 -06:00
|
|
|
child.placeWidgets(newW, newH)
|
|
|
|
newR := child.realGocuiSize()
|
2024-01-18 00:08:37 -06:00
|
|
|
// w := newR.w1 - newR.w0
|
|
|
|
h := newR.h1 - newR.h0
|
|
|
|
|
|
|
|
// increment straight down
|
|
|
|
newH += h
|
|
|
|
}
|
|
|
|
default:
|
2024-01-28 02:20:31 -06:00
|
|
|
tk.gocuiSetWH(startW, startH)
|
2024-01-18 00:08:37 -06:00
|
|
|
// n.moveTo(startW, startH)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-28 11:07:51 -06:00
|
|
|
func (w *guiWidget) placeGrid(startW int, startH int) {
|
|
|
|
w.showWidgetPlacement(true, "grid0:")
|
|
|
|
if w.WidgetType != widget.Grid {
|
2024-01-18 00:08:37 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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 11:07:51 -06:00
|
|
|
newR := child.realGocuiSize()
|
2024-01-18 00:08:37 -06:00
|
|
|
childW := newR.w1 - newR.w0
|
|
|
|
childH := newR.h1 - newR.h0
|
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|
|
|
|
// child.showWidgetPlacement(logInfo, "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
|
|
|
}
|
|
|
|
|
|
|
|
// 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 11:07:51 -06:00
|
|
|
child.showWidgetPlacement(true, "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 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)
|
|
|
|
child.showWidgetPlacement(true, "grid2:")
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
2024-01-28 11:07:51 -06:00
|
|
|
w.showWidgetPlacement(true, "grid3:")
|
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
|
|
|
|
}
|