From a83110ec03ff5180a78829d5a7a39730000afad4 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Tue, 4 Apr 2023 06:31:30 -0500 Subject: [PATCH] gocui: use (w,h) and avoid (x,y) names Signed-off-by: Jeff Carr --- grid.go | 22 ++++++++------- plugin.go | 6 ----- toolkit/gocui/click.go | 35 ++++++++++++++++++++++-- toolkit/gocui/common.go | 4 +++ toolkit/gocui/debug.go | 2 +- toolkit/gocui/place.go | 58 +++++++++++++++------------------------- toolkit/gocui/structs.go | 7 +++++ 7 files changed, 80 insertions(+), 54 deletions(-) diff --git a/grid.go b/grid.go index 859d2e3..18eb7d8 100644 --- a/grid.go +++ b/grid.go @@ -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) diff --git a/plugin.go b/plugin.go index a9cf4f9..f38559d 100644 --- a/plugin.go +++ b/plugin.go @@ -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: } } diff --git a/toolkit/gocui/click.go b/toolkit/gocui/click.go index ce61bb7..41b8780 100644 --- a/toolkit/gocui/click.go +++ b/toolkit/gocui/click.go @@ -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) { diff --git a/toolkit/gocui/common.go b/toolkit/gocui/common.go index 08f8e3c..6d0da27 100644 --- a/toolkit/gocui/common.go +++ b/toolkit/gocui/common.go @@ -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 diff --git a/toolkit/gocui/debug.go b/toolkit/gocui/debug.go index 0573f70..3995794 100644 --- a/toolkit/gocui/debug.go +++ b/toolkit/gocui/debug.go @@ -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) diff --git a/toolkit/gocui/place.go b/toolkit/gocui/place.go index d5d0f40..4a4d102 100644 --- a/toolkit/gocui/place.go +++ b/toolkit/gocui/place.go @@ -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") } diff --git a/toolkit/gocui/structs.go b/toolkit/gocui/structs.go index 2b91de4..b4a2ab6 100644 --- a/toolkit/gocui/structs.go +++ b/toolkit/gocui/structs.go @@ -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