things laying over each other

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-01-28 17:40:02 -06:00
parent 2e2e68ce07
commit 63b76b2912
3 changed files with 68 additions and 37 deletions

100
place.go
View File

@ -8,60 +8,75 @@ import (
"go.wit.com/widget" "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 { if tk.WidgetType != widget.Box {
return return 0, 0
} }
tk.showWidgetPlacement("boxS()") tk.dumpTree("beforebox")
newW := startW newW := startW
newH := startH newH := startH
var maxW int = 0
var maxH int = 0
for _, child := range tk.children { for _, child := range tk.children {
child.placeWidgets(newW, newH) sizeW, sizeH := child.placeWidgets(newW, newH)
// n.showWidgetPlacement("boxS()")
newR := child.realGocuiSize()
w := newR.w1 - newR.w0
h := newR.h1 - newR.h0
if child.direction == widget.Horizontal { 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 // expand based on the child width
newW += w newW += sizeW
maxW += sizeW
if sizeH > maxH {
maxH = sizeH
}
} else { } 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 // expand based on the child height
newH += h newH += sizeH
maxH += sizeH
if sizeW > maxW {
maxW = sizeW
}
} }
} }
// just compute this every time? // just compute this every time?
// newR := n.realGocuiSize() // 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 { if tk == nil {
return return 0, 0
} }
if me.treeRoot == nil { if me.treeRoot == nil {
return return 0, 0
} }
switch tk.WidgetType { switch tk.WidgetType {
case widget.Window: case widget.Window:
newW := startW
newH := startH
var maxH int = 0
for _, child := range tk.children { for _, child := range tk.children {
child.placeWidgets(me.RawW, me.RawH) sizeW, sizeH := child.placeWidgets(newW, newH)
return if sizeW < 20 {
sizeW = 20
} }
newW += sizeW
if sizeH > maxH {
maxH = sizeH
}
}
return newW - startW, maxH
case widget.Tab: case widget.Tab:
for _, child := range tk.children {
child.placeWidgets(me.RawW, me.RawH)
return
}
case widget.Grid: case widget.Grid:
tk.placeGrid(startW, startH) return tk.placeGrid(startW, startH)
case widget.Box: case widget.Box:
tk.placeBox(startW, startH) return tk.placeBox(startW, startH)
case widget.Group: case widget.Group:
// move the group to the parent's next location // move the group to the parent's next location
tk.gocuiSetWH(startW, startH) tk.gocuiSetWH(startW, startH)
@ -69,35 +84,39 @@ func (tk *guiWidget) placeWidgets(startW int, startH int) {
newW := startW + me.GroupPadW newW := startW + me.GroupPadW
newH := startH + 3 // normal hight of the group label newH := startH + 3 // normal hight of the group label
var maxW int = 0
// now move all the children aka: run place() on them // now move all the children aka: run place() on them
for _, child := range tk.children { for _, child := range tk.children {
child.placeWidgets(newW, newH) sizeW, sizeH := child.placeWidgets(newW, newH)
newR := child.realGocuiSize() // newR := child.realGocuiSize()
// w := newR.w1 - newR.w0 // w := newR.w1 - newR.w0
h := newR.h1 - newR.h0 // h := newR.h1 - newR.h0
// increment straight down // increment straight down
newH += h newH += sizeH
log.Log(INFO, "REAL HIGHT ADDED", h, "newH", newH) if sizeW > maxW {
maxW = sizeW
}
log.Log(INFO, "REAL HEIGHT sizeW:", sizeW, "sizeH:", sizeH)
} }
tk.dumpTree("end place") tk.dumpTree("end place")
return maxW, newH - startH
default: default:
tk.gocuiSetWH(startW, startH) 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:") w.showWidgetPlacement("grid0:")
if w.WidgetType != widget.Grid { if w.WidgetType != widget.Grid {
return return 0, 0
} }
// first compute the max sizes of the rows and columns // first compute the max sizes of the rows and columns
for _, child := range w.children { for _, child := range w.children {
newR := child.realGocuiSize() childW, childH := child.placeWidgets(startW, startH)
childW := newR.w1 - newR.w0
childH := newR.h1 - newR.h0
// set the child's realWidth, and grid offset // set the child's realWidth, and grid offset
if w.widths[child.AtW] < childW { 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) 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 // find the width and height offset of the grid for AtW,AtH
for _, child := range w.children { for _, child := range w.children {
child.showWidgetPlacement("grid1:") child.showWidgetPlacement("grid1:")
@ -130,11 +152,19 @@ func (w *guiWidget) placeGrid(startW int, startH int) {
newW := startW + totalW newW := startW + totalW
newH := startH + totalH 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) log.Log(INFO, "placeGrid:", child.String(), "new()", newW, newH, "At()", child.AtW, child.AtH)
child.placeWidgets(newW, newH) child.placeWidgets(newW, newH)
child.showWidgetPlacement("grid2:") child.showWidgetPlacement("grid2:")
} }
w.showWidgetPlacement("grid3:") w.showWidgetPlacement("grid3:")
return maxW, maxH
} }
// computes the real, actual size of all the gocli objects in a widget // computes the real, actual size of all the gocli objects in a widget

View File

@ -160,6 +160,9 @@ type guiWidget struct {
// sometimes this isn't visible like with a Box or Grid // sometimes this isn't visible like with a Box or Grid
gocuiSize rectType gocuiSize rectType
boxSizeW int
boxSizeH int
isCurrent bool // is this the currently displayed Window or Tab? isCurrent bool // is this the currently displayed Window or Tab?
isFake bool // widget types like 'box' are 'false' isFake bool // widget types like 'box' are 'false'

2
tab.go
View File

@ -1,7 +1,5 @@
package main package main
// implements widgets 'Window' and 'Tab'
import ( import (
"strings" "strings"