gocui: use (w,h) and avoid (x,y) names
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
40ad372361
commit
a83110ec03
22
grid.go
22
grid.go
|
@ -4,29 +4,33 @@ import (
|
||||||
"git.wit.org/wit/gui/toolkit"
|
"git.wit.org/wit/gui/toolkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Grid numbering examples (X) or (X,Y)
|
// Grid numbering examples (H) or (W,H)
|
||||||
// ---------
|
// ---------
|
||||||
// -- (1) --
|
// -- (1) --
|
||||||
// -- (2) --
|
// -- (2) --
|
||||||
// ---------
|
// ---------
|
||||||
//
|
//
|
||||||
// -----------------------------
|
// -----------------------------
|
||||||
// -- (1,1) -- (1,2) -- (1,3) --
|
// -- (1,1) -- (2,1) -- (3,1) --
|
||||||
// -- (2,1) -- (2,2) -- (2,3) --
|
// -- (1,2) -- (2,2) -- (3,2) --
|
||||||
// -- (3,1) -- -- (2,3) --
|
// -- (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() {
|
newNode := n.New(name, toolkit.Grid, func() {
|
||||||
log(debugChange, "click() NewGrid not defined =", name)
|
log(debugChange, "click() NewGrid not defined =", name)
|
||||||
})
|
})
|
||||||
|
|
||||||
var a toolkit.Action
|
var a toolkit.Action
|
||||||
a.ActionType = toolkit.Add
|
a.ActionType = toolkit.Add
|
||||||
a.X = x
|
a.Name = name
|
||||||
a.Y = y
|
a.Text = name
|
||||||
newNode.X = x
|
a.X = w
|
||||||
newNode.Y = y
|
a.Y = h
|
||||||
|
a.Width = w
|
||||||
|
a.Height = h
|
||||||
|
newNode.X = w
|
||||||
|
newNode.Y = h
|
||||||
newNode.NextX = 1
|
newNode.NextX = 1
|
||||||
newNode.NextY = 1
|
newNode.NextY = 1
|
||||||
newaction(&a, newNode, n)
|
newaction(&a, newNode, n)
|
||||||
|
|
|
@ -283,12 +283,6 @@ func newaction(a *toolkit.Action, n *Node, where *Node) {
|
||||||
where.NextY = 1
|
where.NextY = 1
|
||||||
}
|
}
|
||||||
log(logInfo, "Action() END size (X,Y)", where.X, where.Y, "put next thing at (X,Y) =", where.NextX, where.NextY)
|
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:
|
default:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,36 @@ import (
|
||||||
"git.wit.org/wit/gui/toolkit"
|
"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() {
|
func (w *cuiWidget) doWidgetClick() {
|
||||||
switch w.widgetType {
|
switch w.widgetType {
|
||||||
case toolkit.Root:
|
case toolkit.Root:
|
||||||
|
@ -24,8 +54,9 @@ func (w *cuiWidget) doWidgetClick() {
|
||||||
w.redoBox(true)
|
w.redoBox(true)
|
||||||
w.toggleTree()
|
w.toggleTree()
|
||||||
case toolkit.Grid:
|
case toolkit.Grid:
|
||||||
w.redoBox(true)
|
w.gridBounds()
|
||||||
w.toggleTree()
|
// w.redoBox(true)
|
||||||
|
// w.toggleTree()
|
||||||
case toolkit.Box:
|
case toolkit.Box:
|
||||||
// w.showWidgetPlacement(logNow, "drawTree()")
|
// w.showWidgetPlacement(logNow, "drawTree()")
|
||||||
if (w.horizontal) {
|
if (w.horizontal) {
|
||||||
|
|
|
@ -53,6 +53,10 @@ func setupWidget(a *toolkit.Action) *cuiWidget {
|
||||||
w.horizontal = false
|
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)
|
// w.showWidgetPlacement(logNow)
|
||||||
return w
|
return w
|
||||||
|
|
|
@ -47,7 +47,7 @@ func (w *cuiWidget) showWidgetPlacement(b bool, s string) {
|
||||||
log(b, "dump()", s,
|
log(b, "dump()", s,
|
||||||
fmt.Sprintf("(wId,pId)=(%3d,%3d)", w.id, w.parent.id),
|
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),
|
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, ")",
|
"logical()=(", w.logicalSize.w0, ",", w.logicalSize.h0, ",", w.logicalSize.w1, ",", w.logicalSize.h1, ")",
|
||||||
w.widgetType, ",", w.name, "text=", w.text)
|
w.widgetType, ",", w.name, "text=", w.text)
|
||||||
|
|
||||||
|
|
|
@ -86,9 +86,18 @@ func (w *cuiWidget) redoBox(draw bool) {
|
||||||
for _, child := range w.children {
|
for _, child := range w.children {
|
||||||
// increment for the next child
|
// increment for the next child
|
||||||
w.nextW = p.nextW + wCount * 20
|
w.nextW = p.nextW + wCount * 20
|
||||||
w.nextH = p.nextH + hCount * 4
|
w.nextH = p.nextH + hCount * 2
|
||||||
child.redoBox(draw)
|
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)
|
log(logNow, "redoBox(GRID) (w,h count)", wCount, hCount, "(X,Y)", w.x, w.y, w.name)
|
||||||
child.showWidgetPlacement(logNow, "grid:")
|
child.showWidgetPlacement(logNow, "grid:")
|
||||||
|
|
||||||
|
@ -156,50 +165,27 @@ func (w *cuiWidget) redoBox(draw bool) {
|
||||||
// p.nextH = w.nextH
|
// p.nextH = w.nextH
|
||||||
w.showWidgetPlacement(logNow, "group:")
|
w.showWidgetPlacement(logNow, "group:")
|
||||||
default:
|
default:
|
||||||
w.realWidth = t + 3
|
w.boxedPlace(p.nextW, p.nextH)
|
||||||
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.nextW = w.realSize.w1
|
w.nextW = w.realSize.w1
|
||||||
w.nextH = w.realSize.h1
|
w.nextH = w.realSize.h1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *cuiWidget) boxedPlace() {
|
func (w *cuiWidget) boxedPlace(leftW int, topH int) {
|
||||||
t := len(w.name)
|
t := len(w.text)
|
||||||
if (w.id == 0) {
|
|
||||||
w.realWidth = 0
|
|
||||||
w.realHeight = 0
|
|
||||||
return
|
|
||||||
}
|
|
||||||
p := w.parent
|
|
||||||
if (p == nil) {
|
|
||||||
log(logError, "boxedPlace() parentId widget == nil")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
w.realWidth = t + 3
|
w.realWidth = t + me.buttonPadding
|
||||||
w.realHeight = me.defaultHeight
|
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.realSize.w0 = leftW
|
||||||
w.logicalSize.h0 = p.nextH
|
w.realSize.h0 = topH
|
||||||
w.logicalSize.w1 = p.nextW + w.realWidth
|
w.realSize.w1 = leftW + w.realWidth
|
||||||
w.logicalSize.h1 = p.nextH + w.realHeight
|
w.realSize.h1 = topH + w.realHeight
|
||||||
|
|
||||||
w.nextW = w.realSize.w1
|
w.logicalSize.w0 = w.realSize.w0
|
||||||
w.nextH = w.realSize.h1
|
w.logicalSize.h0 = w.realSize.h0
|
||||||
|
w.logicalSize.w1 = w.realSize.w1
|
||||||
|
w.logicalSize.h1 = w.realSize.h1
|
||||||
|
|
||||||
w.showWidgetPlacement(logNow, "bP widget")
|
w.showWidgetPlacement(logNow, "bP widget")
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,6 +94,13 @@ type cuiWidget struct {
|
||||||
realSize rectType // the display size of this widget
|
realSize rectType // the display size of this widget
|
||||||
logicalSize rectType // the logical size. Includes all the child widgets
|
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
|
nextW int
|
||||||
nextH int
|
nextH int
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue