2023-04-03 10:26:47 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
// "github.com/awesome-gocui/gocui"
|
|
|
|
"git.wit.org/wit/gui/toolkit"
|
|
|
|
)
|
|
|
|
|
2023-04-03 16:08:58 -05:00
|
|
|
var fakeStartWidth int = 40
|
2023-04-03 11:52:54 -05:00
|
|
|
var fakeStartHeight int = 3
|
2023-04-03 10:26:47 -05:00
|
|
|
func (w *cuiWidget) setFake() {
|
2023-04-03 11:52:54 -05:00
|
|
|
if (w.isFake == false) {
|
2023-04-03 10:26:47 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
t := len(w.name)
|
|
|
|
// setup fake labels for non-visable things off screen
|
|
|
|
w.realWidth = t + 2
|
|
|
|
w.realHeight = me.defaultHeight
|
|
|
|
w.realSize.w0 = fakeStartWidth
|
|
|
|
w.realSize.h0 = fakeStartHeight
|
|
|
|
w.realSize.w1 = w.realSize.w0 + w.realWidth
|
|
|
|
w.realSize.h1 = w.realSize.h0 + w.realHeight
|
|
|
|
fakeStartHeight += 3
|
|
|
|
if (fakeStartHeight > 24) {
|
2023-04-03 11:52:54 -05:00
|
|
|
fakeStartHeight = 3
|
2023-04-03 10:26:47 -05:00
|
|
|
fakeStartWidth += 20
|
|
|
|
}
|
|
|
|
w.showWidgetPlacement(logNow, "setFake()")
|
|
|
|
}
|
|
|
|
|
|
|
|
func findPlace(w *cuiWidget) {
|
2023-04-03 11:52:54 -05:00
|
|
|
w.isFake = false
|
2023-04-03 10:26:47 -05:00
|
|
|
w.visable = true
|
|
|
|
switch w.widgetType {
|
|
|
|
case toolkit.Root:
|
2023-04-03 11:52:54 -05:00
|
|
|
w.isFake = true
|
2023-04-03 10:26:47 -05:00
|
|
|
w.setFake()
|
|
|
|
case toolkit.Flag:
|
2023-04-03 11:52:54 -05:00
|
|
|
w.isFake = true
|
2023-04-03 10:26:47 -05:00
|
|
|
w.setFake()
|
|
|
|
case toolkit.Grid:
|
2023-04-03 11:52:54 -05:00
|
|
|
w.isFake = true
|
2023-04-03 10:26:47 -05:00
|
|
|
w.setFake()
|
|
|
|
case toolkit.Box:
|
2023-04-03 11:52:54 -05:00
|
|
|
w.isFake = true
|
2023-04-03 10:26:47 -05:00
|
|
|
w.setFake()
|
|
|
|
default:
|
2023-04-03 11:52:54 -05:00
|
|
|
// w.redoBox(true)
|
2023-04-03 10:26:47 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *cuiWidget) redoBox(draw bool) {
|
|
|
|
if (w == nil) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if (me.rootNode == nil) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
p := w.parent
|
|
|
|
if (p == nil) {
|
|
|
|
log(logInfo, "redoBox()", w.id, "parent == nil")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
t := len(w.text)
|
|
|
|
w.visable = true
|
|
|
|
switch w.widgetType {
|
|
|
|
case toolkit.Window:
|
|
|
|
for _, child := range w.children {
|
|
|
|
child.redoBox(draw)
|
|
|
|
}
|
|
|
|
case toolkit.Tab:
|
|
|
|
for _, child := range w.children {
|
|
|
|
child.redoBox(draw)
|
|
|
|
}
|
|
|
|
case toolkit.Grid:
|
2023-04-03 17:49:37 -05:00
|
|
|
log("redoBox GRID", p.nextW, p.nextH, p.name)
|
|
|
|
log("redoBox GRID", p.nextW, p.nextH, p.name)
|
|
|
|
log("redoBox GRID", w.nextW, w.nextH, w.name, w.text)
|
2023-04-03 10:26:47 -05:00
|
|
|
// hmm
|
|
|
|
|
|
|
|
w.nextW = p.nextW
|
|
|
|
w.nextH = p.nextH
|
|
|
|
|
2023-04-03 17:49:37 -05:00
|
|
|
var wCount int = 0
|
|
|
|
var hCount int = 0
|
2023-04-03 10:26:47 -05:00
|
|
|
for _, child := range w.children {
|
2023-04-03 17:49:37 -05:00
|
|
|
// increment for the next child
|
|
|
|
w.nextW = p.nextW + wCount * 20
|
2023-04-04 06:31:30 -05:00
|
|
|
w.nextH = p.nextH + hCount * 2
|
2023-04-03 10:26:47 -05:00
|
|
|
child.redoBox(draw)
|
2023-04-03 17:49:37 -05:00
|
|
|
|
2023-04-04 06:31:30 -05:00
|
|
|
// set the child's realWidth, and grid offset
|
|
|
|
child.parentH = hCount
|
|
|
|
child.parentW = wCount
|
|
|
|
if (w.logicalW[wCount] < child.realWidth) {
|
|
|
|
w.logicalW[wCount] = child.realWidth
|
|
|
|
}
|
|
|
|
if (w.logicalH[hCount] < child.realHeight) {
|
|
|
|
w.logicalH[hCount] = child.realHeight
|
|
|
|
}
|
2023-04-03 17:49:37 -05:00
|
|
|
log(logNow, "redoBox(GRID) (w,h count)", wCount, hCount, "(X,Y)", w.x, w.y, w.name)
|
|
|
|
child.showWidgetPlacement(logNow, "grid:")
|
|
|
|
|
|
|
|
if ((wCount + 1) < w.y) {
|
2023-04-03 10:26:47 -05:00
|
|
|
wCount += 1
|
|
|
|
} else {
|
|
|
|
wCount = 0
|
2023-04-03 17:49:37 -05:00
|
|
|
hCount += 1
|
2023-04-03 10:26:47 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
w.showWidgetPlacement(logNow, "grid:")
|
|
|
|
case toolkit.Box:
|
|
|
|
w.logicalSize.w0 = p.nextW
|
|
|
|
w.logicalSize.h0 = p.nextH
|
|
|
|
w.logicalSize.w1 = p.nextW
|
|
|
|
w.logicalSize.h1 = p.nextH
|
|
|
|
|
|
|
|
w.nextW = p.nextW
|
|
|
|
w.nextH = p.nextH
|
|
|
|
for _, child := range w.children {
|
|
|
|
child.redoBox(draw)
|
|
|
|
if (w.horizontal) {
|
|
|
|
log("BOX IS HORIZONTAL", p.nextW, p.nextW, p.name)
|
|
|
|
log("BOX IS HORIZONTAL", w.nextW, w.nextH, w.name)
|
|
|
|
log("BOX IS HORIZONTAL")
|
|
|
|
// expand based on the child width
|
|
|
|
w.nextW = child.nextW + me.horizontalPadding
|
|
|
|
// reset height to parent
|
|
|
|
w.nextH = p.nextH
|
|
|
|
} else {
|
|
|
|
log("BOX IS VERTICAL", p.nextW, p.nextW, p.name)
|
|
|
|
log("BOX IS VERTICAL", w.nextW, w.nextH, w.name)
|
|
|
|
log("BOX IS VERTICAL")
|
|
|
|
// go straight down
|
|
|
|
w.nextW = p.nextW
|
|
|
|
// expand based on the child height
|
|
|
|
w.nextH = child.nextH
|
|
|
|
}
|
|
|
|
}
|
|
|
|
w.showWidgetPlacement(logNow, "box:")
|
|
|
|
case toolkit.Group:
|
|
|
|
w.realWidth = t + me.buttonPadding
|
|
|
|
w.realHeight = me.defaultHeight
|
|
|
|
|
|
|
|
w.realSize.w0 = p.nextW
|
|
|
|
w.realSize.h0 = p.nextH
|
|
|
|
w.realSize.w1 = w.realSize.w0 + w.realWidth
|
|
|
|
w.realSize.h1 = w.realHeight
|
|
|
|
|
|
|
|
w.logicalSize.w0 = w.realSize.w0
|
|
|
|
w.logicalSize.h0 = w.realSize.h0
|
|
|
|
w.logicalSize.w1 = w.realSize.w1
|
|
|
|
w.logicalSize.h1 = w.realSize.h1
|
|
|
|
|
|
|
|
w.nextW = p.nextW + me.groupPadding
|
|
|
|
w.nextH = p.nextH + me.buttonPadding
|
|
|
|
for _, child := range w.children {
|
|
|
|
child.redoBox(draw)
|
|
|
|
// reset nextW to straight down
|
|
|
|
w.nextW = p.nextW + 4
|
|
|
|
w.nextH = child.nextH
|
|
|
|
}
|
|
|
|
// expand the height of the parent now that the group is done
|
|
|
|
// p.nextW = w.nextW
|
|
|
|
// p.nextH = w.nextH
|
|
|
|
w.showWidgetPlacement(logNow, "group:")
|
|
|
|
default:
|
2023-04-04 06:31:30 -05:00
|
|
|
w.boxedPlace(p.nextW, p.nextH)
|
2023-04-03 10:26:47 -05:00
|
|
|
w.nextW = w.realSize.w1
|
|
|
|
w.nextH = w.realSize.h1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-04 06:31:30 -05:00
|
|
|
func (w *cuiWidget) boxedPlace(leftW int, topH int) {
|
|
|
|
t := len(w.text)
|
2023-04-03 10:26:47 -05:00
|
|
|
|
2023-04-04 06:31:30 -05:00
|
|
|
w.realWidth = t + me.buttonPadding
|
2023-04-03 10:26:47 -05:00
|
|
|
w.realHeight = me.defaultHeight
|
2023-04-04 06:31:30 -05:00
|
|
|
|
|
|
|
w.realSize.w0 = leftW
|
|
|
|
w.realSize.h0 = topH
|
|
|
|
w.realSize.w1 = leftW + w.realWidth
|
|
|
|
w.realSize.h1 = topH + w.realHeight
|
|
|
|
|
|
|
|
w.logicalSize.w0 = w.realSize.w0
|
|
|
|
w.logicalSize.h0 = w.realSize.h0
|
|
|
|
w.logicalSize.w1 = w.realSize.w1
|
|
|
|
w.logicalSize.h1 = w.realSize.h1
|
2023-04-03 10:26:47 -05:00
|
|
|
|
|
|
|
w.showWidgetPlacement(logNow, "bP widget")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *cuiWidget) updateLogicalSizes() {
|
|
|
|
for _, child := range w.children {
|
|
|
|
child.updateLogicalSizes()
|
|
|
|
if (w.logicalSize.w0 > child.logicalSize.w0) {
|
|
|
|
w.logicalSize.w0 = child.logicalSize.w0
|
|
|
|
}
|
|
|
|
if (w.logicalSize.w1 < child.logicalSize.w1) {
|
|
|
|
w.logicalSize.w1 = child.logicalSize.w1
|
|
|
|
}
|
|
|
|
if (w.logicalSize.h0 > child.logicalSize.h0) {
|
|
|
|
w.logicalSize.h0 = child.logicalSize.h0
|
|
|
|
}
|
|
|
|
if (w.logicalSize.h1 < child.logicalSize.h1) {
|
|
|
|
w.logicalSize.h1 = child.logicalSize.h1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|