gocui: grid resize
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
a83110ec03
commit
3a4d07fd7a
|
@ -104,6 +104,15 @@ func buttonWindow() {
|
|||
})
|
||||
})
|
||||
|
||||
g.NewButton("NewButton(more2 d)", func () {
|
||||
log.Println("new foobar 2. Adding button 'foobar 3'")
|
||||
name := "d" + strconv.Itoa(counter)
|
||||
counter += 1
|
||||
more2.NewButton(name, func () {
|
||||
log.Println("Got all the way to main() name =", name)
|
||||
})
|
||||
})
|
||||
|
||||
g.NewButton("NewGroup()", func () {
|
||||
log.Println("new foobar 2. Adding button 'foobar 3'")
|
||||
name := "neat " + strconv.Itoa(counter)
|
||||
|
|
|
@ -11,22 +11,54 @@ import (
|
|||
)
|
||||
|
||||
func (w *cuiWidget) gridBounds() {
|
||||
w.showWidgetPlacement(logNow, "gridBounds:")
|
||||
p := w.parent
|
||||
|
||||
/*
|
||||
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")
|
||||
}
|
||||
*/
|
||||
var wCount int = 0
|
||||
var hCount int = 0
|
||||
for _, child := range w.children {
|
||||
// increment for the next child
|
||||
w.nextW = p.nextW + wCount * 20
|
||||
w.nextH = p.nextH + hCount * 2
|
||||
child.redoBox(true)
|
||||
|
||||
// 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:")
|
||||
|
||||
if ((wCount + 1) < w.y) {
|
||||
wCount += 1
|
||||
} else {
|
||||
wCount = 0
|
||||
hCount += 1
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for _, child := range w.children {
|
||||
child.showWidgetPlacement(logNow, "gridBounds:")
|
||||
child.showWidgetPlacement(logVerbose, "gridBounds:")
|
||||
var totalW, totalH int
|
||||
for i, val := range w.logicalW {
|
||||
if (i < child.parentW) {
|
||||
log(logNow, "gridBounds() (w, logicalW[])", i, val)
|
||||
log(logVerbose, "gridBounds() (w, logicalW[])", i, val)
|
||||
totalW += w.logicalW[i]
|
||||
}
|
||||
}
|
||||
|
@ -35,9 +67,21 @@ func (w *cuiWidget) gridBounds() {
|
|||
totalH += h
|
||||
}
|
||||
}
|
||||
log(logNow, "gridBounds()", child.id, "parent (W,H) =", child.parentW, child.parentH,
|
||||
"total (W,H) =", totalW, totalH, child.name)
|
||||
|
||||
// the new corner to move the child to
|
||||
realW := w.nextW + totalW
|
||||
realH := w.nextH + totalH
|
||||
|
||||
|
||||
log(logInfo, "gridBounds()", child.id, "parent (W,H) =", child.parentW, child.parentH,
|
||||
"total (W,H) =", totalW, totalH,
|
||||
"real (W,H) =", realW, realH)
|
||||
child.moveTo(realW, realH)
|
||||
child.showWidgetPlacement(logInfo, "gridBounds:")
|
||||
log(logInfo)
|
||||
}
|
||||
w.updateLogicalSizes()
|
||||
w.showWidgetPlacement(logNow, "gridBounds:")
|
||||
}
|
||||
|
||||
func (w *cuiWidget) doWidgetClick() {
|
||||
|
@ -55,8 +99,16 @@ func (w *cuiWidget) doWidgetClick() {
|
|||
w.toggleTree()
|
||||
case toolkit.Grid:
|
||||
w.gridBounds()
|
||||
// w.redoBox(true)
|
||||
for _, child := range w.children {
|
||||
child.showWidgetPlacement(logNow, "gridBounds:")
|
||||
if (child.v == nil) {
|
||||
child.drawView()
|
||||
} else {
|
||||
child.deleteView()
|
||||
}
|
||||
}
|
||||
// w.toggleTree()
|
||||
// w.redoBox(true)
|
||||
case toolkit.Box:
|
||||
// w.showWidgetPlacement(logNow, "drawTree()")
|
||||
if (w.horizontal) {
|
||||
|
@ -67,8 +119,6 @@ func (w *cuiWidget) doWidgetClick() {
|
|||
w.redoBox(true)
|
||||
w.toggleTree()
|
||||
default:
|
||||
// w.textResize()
|
||||
// something
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -91,7 +141,7 @@ func (w *cuiWidget) drawTree(draw bool) {
|
|||
}
|
||||
w.showWidgetPlacement(logNow, "drawTree()")
|
||||
if (draw) {
|
||||
w.textResize()
|
||||
// w.textResize()
|
||||
w.drawView()
|
||||
} else {
|
||||
w.deleteView()
|
||||
|
@ -188,7 +238,6 @@ func ctrlDown(g *gocui.Gui, v *gocui.View) error {
|
|||
me.ctrlDown.realSize.w1 = found.logicalSize.w1
|
||||
me.ctrlDown.realSize.h0 = found.logicalSize.h0
|
||||
me.ctrlDown.realSize.h1 = found.logicalSize.h1
|
||||
// me.ctrlDown.textResize()
|
||||
|
||||
if (me.ctrlDown.v == nil) {
|
||||
me.ctrlDown.text = found.text
|
||||
|
|
|
@ -20,6 +20,10 @@ func setupWidget(a *toolkit.Action) *cuiWidget {
|
|||
w.width = a.Width
|
||||
w.height = a.Height
|
||||
|
||||
t := len(w.text)
|
||||
w.realWidth = t + me.buttonPadding
|
||||
w.realHeight = me.defaultHeight
|
||||
|
||||
w.widgetType = a.WidgetType
|
||||
w.id = a.WidgetId
|
||||
// set the name used by gocui to the id
|
||||
|
|
|
@ -61,8 +61,6 @@ func (w *cuiWidget) redoBox(draw bool) {
|
|||
return
|
||||
}
|
||||
|
||||
t := len(w.text)
|
||||
w.visable = true
|
||||
switch w.widgetType {
|
||||
case toolkit.Window:
|
||||
for _, child := range w.children {
|
||||
|
@ -73,42 +71,9 @@ func (w *cuiWidget) redoBox(draw bool) {
|
|||
child.redoBox(draw)
|
||||
}
|
||||
case toolkit.Grid:
|
||||
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)
|
||||
// hmm
|
||||
|
||||
w.nextW = p.nextW
|
||||
w.nextH = p.nextH
|
||||
|
||||
var wCount int = 0
|
||||
var hCount int = 0
|
||||
for _, child := range w.children {
|
||||
// increment for the next child
|
||||
w.nextW = p.nextW + wCount * 20
|
||||
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:")
|
||||
|
||||
if ((wCount + 1) < w.y) {
|
||||
wCount += 1
|
||||
} else {
|
||||
wCount = 0
|
||||
hCount += 1
|
||||
}
|
||||
}
|
||||
w.showWidgetPlacement(logNow, "grid:")
|
||||
w.gridBounds()
|
||||
case toolkit.Box:
|
||||
w.logicalSize.w0 = p.nextW
|
||||
w.logicalSize.h0 = p.nextH
|
||||
|
@ -139,18 +104,7 @@ func (w *cuiWidget) redoBox(draw bool) {
|
|||
}
|
||||
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.moveTo(p.nextW, p.nextH)
|
||||
|
||||
w.nextW = p.nextW + me.groupPadding
|
||||
w.nextH = p.nextH + me.buttonPadding
|
||||
|
@ -165,18 +119,13 @@ func (w *cuiWidget) redoBox(draw bool) {
|
|||
// p.nextH = w.nextH
|
||||
w.showWidgetPlacement(logNow, "group:")
|
||||
default:
|
||||
w.boxedPlace(p.nextW, p.nextH)
|
||||
w.moveTo(p.nextW, p.nextH)
|
||||
w.nextW = w.realSize.w1
|
||||
w.nextH = w.realSize.h1
|
||||
}
|
||||
}
|
||||
|
||||
func (w *cuiWidget) boxedPlace(leftW int, topH int) {
|
||||
t := len(w.text)
|
||||
|
||||
w.realWidth = t + me.buttonPadding
|
||||
w.realHeight = me.defaultHeight
|
||||
|
||||
func (w *cuiWidget) moveTo(leftW int, topH int) {
|
||||
w.realSize.w0 = leftW
|
||||
w.realSize.h0 = topH
|
||||
w.realSize.w1 = leftW + w.realWidth
|
||||
|
@ -187,7 +136,7 @@ func (w *cuiWidget) boxedPlace(leftW int, topH int) {
|
|||
w.logicalSize.w1 = w.realSize.w1
|
||||
w.logicalSize.h1 = w.realSize.h1
|
||||
|
||||
w.showWidgetPlacement(logNow, "bP widget")
|
||||
w.showWidgetPlacement(logNow, "moveTo()")
|
||||
}
|
||||
|
||||
func (w *cuiWidget) updateLogicalSizes() {
|
||||
|
|
Loading…
Reference in New Issue