gocui: use (w,h) and avoid (x,y) names

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2023-04-04 06:31:30 -05:00
parent 40ad372361
commit a83110ec03
7 changed files with 80 additions and 54 deletions

22
grid.go
View File

@ -4,29 +4,33 @@ import (
"git.wit.org/wit/gui/toolkit"
)
// Grid numbering examples (X) or (X,Y)
// Grid numbering examples (H) or (W,H)
// ---------
// -- (1) --
// -- (2) --
// ---------
//
// -----------------------------
// -- (1,1) -- (1,2) -- (1,3) --
// -- (2,1) -- (2,2) -- (2,3) --
// -- (3,1) -- -- (2,3) --
// -- (1,1) -- (2,1) -- (3,1) --
// -- (1,2) -- (2,2) -- (3,2) --
// -- (1,3) -- -- (3,3) --
// -----------------------------
func (n *Node) NewGrid(name string, x int, y int) *Node {
func (n *Node) NewGrid(name string, w int, h int) *Node {
newNode := n.New(name, toolkit.Grid, func() {
log(debugChange, "click() NewGrid not defined =", name)
})
var a toolkit.Action
a.ActionType = toolkit.Add
a.X = x
a.Y = y
newNode.X = x
newNode.Y = y
a.Name = name
a.Text = name
a.X = w
a.Y = h
a.Width = w
a.Height = h
newNode.X = w
newNode.Y = h
newNode.NextX = 1
newNode.NextY = 1
newaction(&a, newNode, n)

View File

@ -283,12 +283,6 @@ func newaction(a *toolkit.Action, n *Node, where *Node) {
where.NextY = 1
}
log(logInfo, "Action() END size (X,Y)", where.X, where.Y, "put next thing at (X,Y) =", where.NextX, where.NextY)
where.Name = "jwc gridlaksdfjkl"
where.Width = 320
where.Height = 240
// where.NextX = 5
// where.NextY = 7
// where.Dump(logInfo)
default:
}
}

View File

@ -10,6 +10,36 @@ import (
"git.wit.org/wit/gui/toolkit"
)
func (w *cuiWidget) gridBounds() {
for a := 0; a < w.x; a++ {
for b := 0; b < w.y; b++ {
p := w.parent
log(logNow, "gridBounds() (w,h)", a, b,
"logical(W,H)", w.logicalW[a], w.logicalH[b],
"p.next(W,H)", p.nextW, p.nextH)
}
log("\n")
}
for _, child := range w.children {
child.showWidgetPlacement(logNow, "gridBounds:")
var totalW, totalH int
for i, val := range w.logicalW {
if (i < child.parentW) {
log(logNow, "gridBounds() (w, logicalW[])", i, val)
totalW += w.logicalW[i]
}
}
for i, h := range w.logicalH {
if (i < child.parentH) {
totalH += h
}
}
log(logNow, "gridBounds()", child.id, "parent (W,H) =", child.parentW, child.parentH,
"total (W,H) =", totalW, totalH, child.name)
}
}
func (w *cuiWidget) doWidgetClick() {
switch w.widgetType {
case toolkit.Root:
@ -24,8 +54,9 @@ func (w *cuiWidget) doWidgetClick() {
w.redoBox(true)
w.toggleTree()
case toolkit.Grid:
w.redoBox(true)
w.toggleTree()
w.gridBounds()
// w.redoBox(true)
// w.toggleTree()
case toolkit.Box:
// w.showWidgetPlacement(logNow, "drawTree()")
if (w.horizontal) {

View File

@ -53,6 +53,10 @@ func setupWidget(a *toolkit.Action) *cuiWidget {
w.horizontal = false
}
}
if (a.WidgetType == toolkit.Grid) {
w.logicalW = make(map[int]int) // how tall each row in the grid is
w.logicalH = make(map[int]int) // how wide each column in the grid is
}
// w.showWidgetPlacement(logNow)
return w

View File

@ -47,7 +47,7 @@ func (w *cuiWidget) showWidgetPlacement(b bool, s string) {
log(b, "dump()", s,
fmt.Sprintf("(wId,pId)=(%3d,%3d)", w.id, w.parent.id),
fmt.Sprintf("real()=(%3d,%3d,%3d,%3d)", w.realSize.w0, w.realSize.h0, w.realSize.w1, w.realSize.h1),
"next()=(", w.nextW, ",", w.nextH, ")",
"size()=(", w.realWidth, ",", w.realHeight, ")",
"logical()=(", w.logicalSize.w0, ",", w.logicalSize.h0, ",", w.logicalSize.w1, ",", w.logicalSize.h1, ")",
w.widgetType, ",", w.name, "text=", w.text)

View File

@ -86,9 +86,18 @@ func (w *cuiWidget) redoBox(draw bool) {
for _, child := range w.children {
// increment for the next child
w.nextW = p.nextW + wCount * 20
w.nextH = p.nextH + hCount * 4
w.nextH = p.nextH + hCount * 2
child.redoBox(draw)
// 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
}
log(logNow, "redoBox(GRID) (w,h count)", wCount, hCount, "(X,Y)", w.x, w.y, w.name)
child.showWidgetPlacement(logNow, "grid:")
@ -156,50 +165,27 @@ func (w *cuiWidget) redoBox(draw bool) {
// p.nextH = w.nextH
w.showWidgetPlacement(logNow, "group:")
default:
w.realWidth = t + 3
w.realHeight = me.defaultHeight
w.realSize.w0 = p.nextW
w.realSize.h0 = p.nextH
w.realSize.w1 = p.nextW + w.realWidth
w.realSize.h1 = p.nextH + w.realHeight
w.logicalSize.w0 = p.nextW
w.logicalSize.h0 = p.nextH
w.logicalSize.w1 = p.nextW + w.realWidth
w.logicalSize.h1 = p.nextH + w.realHeight
w.boxedPlace(p.nextW, p.nextH)
w.nextW = w.realSize.w1
w.nextH = w.realSize.h1
}
}
func (w *cuiWidget) boxedPlace() {
t := len(w.name)
if (w.id == 0) {
w.realWidth = 0
w.realHeight = 0
return
}
p := w.parent
if (p == nil) {
log(logError, "boxedPlace() parentId widget == nil")
return
}
func (w *cuiWidget) boxedPlace(leftW int, topH int) {
t := len(w.text)
w.realWidth = t + 3
w.realWidth = t + me.buttonPadding
w.realHeight = me.defaultHeight
w.realSize.w0 = p.nextW
w.realSize.h0 = p.nextH
w.realSize.w1 = p.nextW + w.realWidth
w.realSize.h1 = p.nextH + w.realHeight
w.logicalSize.w0 = p.nextW
w.logicalSize.h0 = p.nextH
w.logicalSize.w1 = p.nextW + w.realWidth
w.logicalSize.h1 = p.nextH + w.realHeight
w.realSize.w0 = leftW
w.realSize.h0 = topH
w.realSize.w1 = leftW + w.realWidth
w.realSize.h1 = topH + w.realHeight
w.nextW = w.realSize.w1
w.nextH = w.realSize.h1
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.showWidgetPlacement(logNow, "bP widget")
}

View File

@ -94,6 +94,13 @@ type cuiWidget struct {
realSize rectType // the display size of this widget
logicalSize rectType // the logical size. Includes all the child widgets
// used to track the size of grids
logicalW map[int]int // how tall each row in the grid is
logicalH map[int]int // how wide each column in the grid is
// where in the parent grid this widget should go
parentW int
parentH int
nextW int
nextH int