gocui: don't try to draw on add()

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2023-04-05 21:15:05 -05:00
parent 65f4d0e231
commit bd23ef8338
7 changed files with 62 additions and 194 deletions

View File

@ -13,7 +13,7 @@ import (
func (w *cuiWidget) doWidgetClick() { func (w *cuiWidget) doWidgetClick() {
switch w.widgetType { switch w.widgetType {
case toolkit.Root: case toolkit.Root:
me.rootNode.logicalSize.w1 = 1 // me.rootNode.logicalSize.w1 = 1
me.rootNode.redoTabs(true) me.rootNode.redoTabs(true)
case toolkit.Flag: case toolkit.Flag:
me.rootNode.redoColor(true) me.rootNode.redoColor(true)
@ -43,9 +43,9 @@ func (w *cuiWidget) doWidgetClick() {
case toolkit.Box: case toolkit.Box:
// w.showWidgetPlacement(logNow, "drawTree()") // w.showWidgetPlacement(logNow, "drawTree()")
if (w.horizontal) { if (w.horizontal) {
log("BOX IS HORIZONTAL", w.nextW, w.nextH, w.name) log("BOX IS HORIZONTAL", w.name)
} else { } else {
log("BOX IS VERTICAL", w.nextW, w.nextH, w.name) log("BOX IS VERTICAL", w.name)
} }
w.redoBox(true) w.redoBox(true)
w.toggleTree() w.toggleTree()
@ -164,11 +164,10 @@ func ctrlDown(g *gocui.Gui, v *gocui.View) error {
if (found == nil) { if (found == nil) {
found = me.rootNode found = me.rootNode
} }
found.updateLogicalSizes() me.ctrlDown.gocuiSize.startW = found.gocuiSize.startW
me.ctrlDown.gocuiSize.w0 = found.logicalSize.w0 me.ctrlDown.gocuiSize.startH = found.gocuiSize.startH
me.ctrlDown.gocuiSize.w1 = found.logicalSize.w1 me.ctrlDown.gocuiSize.width = found.gocuiSize.startW
me.ctrlDown.gocuiSize.h0 = found.logicalSize.h0 me.ctrlDown.gocuiSize.height = found.gocuiSize.startH
me.ctrlDown.gocuiSize.h1 = found.logicalSize.h1
if (me.ctrlDown.v == nil) { if (me.ctrlDown.v == nil) {
me.ctrlDown.text = found.text me.ctrlDown.text = found.text

View File

@ -55,23 +55,6 @@ func (w *cuiWidget) showWidgetPlacement(b bool, s string) {
case toolkit.Grid: case toolkit.Grid:
s1 += fmt.Sprintf("next()=(%2d,%2d)", w.nextW, w.nextH) s1 += fmt.Sprintf("next()=(%2d,%2d)", w.nextW, w.nextH)
default: default:
// s1 += fmt.Sprintf("L()=(%2d,%2d,%2d,%2d)",
// w.logicalSize.w0, w.logicalSize.h0, w.logicalSize.w1, w.logicalSize.h1)
} }
log(b, s1, s, w.widgetType, ",", w.name) // , "text=", w.text) log(b, s1, s, w.widgetType, ",", w.name) // , "text=", w.text)
/*
if (w.realWidth != (w.gocuiSize.w1 - w.gocuiSize.w0)) {
log(b, "dump()", s,
"badsize()=(", w.realWidth, ",", w.realHeight, ")",
"badreal()=(", w.gocuiSize.w0, ",", w.gocuiSize.h0, ",", w.gocuiSize.w1, ",", w.gocuiSize.h1, ")",
w.widgetType, ",", w.name)
}
if (w.realHeight != (w.gocuiSize.h1 - w.gocuiSize.h0)) {
log(b, "dump()", s,
"badsize()=(", w.realWidth, ",", w.realHeight, ")",
"badreal()=(", w.gocuiSize.w0, ",", w.gocuiSize.h0, ",", w.gocuiSize.w1, ",", w.gocuiSize.h1, ")",
w.widgetType, ",", w.name)
}
*/
} }

View File

@ -1,75 +0,0 @@
package main
import (
// "git.wit.org/wit/gui/toolkit"
)
var adjusted bool = false
/*
// expands the logical size of the parents
func (w *cuiWidget) setParentLogical() {
p := w.parent
if (w.isFake) {
// expand the parent logicalsize to include the widget logicalsize
if (p.logicalSize.w0 > w.logicalSize.w0) {
p.logicalSize.w0 = w.logicalSize.w0
adjusted = true
}
if (p.logicalSize.h0 > w.logicalSize.h0) {
p.logicalSize.h0 = w.logicalSize.h0
adjusted = true
}
if (p.logicalSize.w1 < w.logicalSize.w1) {
p.logicalSize.w1 = w.logicalSize.w1
adjusted = true
}
if (p.logicalSize.h1 < w.logicalSize.h1) {
p.logicalSize.h1 = w.logicalSize.h1
adjusted = true
}
} else {
// expand the parent logicalsize to include the widget realSize
if (p.logicalSize.w0 > w.realSize.w0) {
p.logicalSize.w0 = w.realSize.w0
adjusted = true
}
if (p.logicalSize.h0 > w.realSize.h0) {
p.logicalSize.h0 = w.realSize.h0
adjusted = true
}
if (p.logicalSize.w1 < w.realSize.w1) {
p.logicalSize.w1 = w.realSize.w1
adjusted = true
}
if (p.logicalSize.h1 < w.realSize.h1) {
p.logicalSize.h1 = w.realSize.h1
adjusted = true
}
}
if (! w.isFake) {
// adjust the widget realSize to the top left corner of the logicalsize
if (w.logicalSize.w0 > w.realSize.w0) {
w.realSize.w0 = w.logicalSize.w0
w.realSize.w1 = w.realSize.w0 + w.realWidth
adjusted = true
}
if (w.logicalSize.h0 > w.realSize.h0) {
w.realSize.h0 = w.logicalSize.h0
w.realSize.h1 = w.realSize.h0 + w.realHeight
adjusted = true
}
}
w.showWidgetPlacement(logNow, "setParentLogical() widget")
p.showWidgetPlacement(logNow, "setParentLogical() parent")
if (w.id == 0) || (p.id == 0) {
// stop resizing when you hit the root widget
return
}
// pass the logical resizing up
pP := w.parent
if (pP != nil) {
pP.setParentLogical()
}
}
*/

View File

@ -30,26 +30,6 @@ func (w *cuiWidget) setFake() {
w.showWidgetPlacement(logNow, "setFake()") w.showWidgetPlacement(logNow, "setFake()")
} }
func findPlace(w *cuiWidget) {
w.isFake = false
switch w.widgetType {
case toolkit.Root:
w.isFake = true
w.setFake()
case toolkit.Flag:
w.isFake = true
w.setFake()
case toolkit.Grid:
w.isFake = true
w.setFake()
case toolkit.Box:
w.isFake = true
w.setFake()
default:
// w.redoBox(true)
}
}
// find the start (w,h) for child a inside a box widget // find the start (w,h) for child a inside a box widget
func (w *cuiWidget) getBoxWH() { func (w *cuiWidget) getBoxWH() {
p := w.parent // the parent must be a box widget p := w.parent // the parent must be a box widget
@ -146,11 +126,6 @@ func (w *cuiWidget) redoBox(draw bool) {
w.nextH = p.nextH w.nextH = p.nextH
w.gridBounds() w.gridBounds()
case toolkit.Box: 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.nextW = p.nextW
w.nextH = p.nextH w.nextH = p.nextH
for _, child := range w.children { for _, child := range w.children {
@ -201,31 +176,20 @@ func (w *cuiWidget) setWH() {
w.gocuiSize.h0 = w.gocuiSize.startH w.gocuiSize.h0 = w.gocuiSize.startH
w.gocuiSize.w1 = w.gocuiSize.w0 + w.gocuiSize.width w.gocuiSize.w1 = w.gocuiSize.w0 + w.gocuiSize.width
w.gocuiSize.h1 = w.gocuiSize.h0 + w.gocuiSize.height w.gocuiSize.h1 = w.gocuiSize.h0 + w.gocuiSize.height
w.logicalSize.w0 = w.gocuiSize.w0
w.logicalSize.h0 = w.gocuiSize.h0
w.logicalSize.w1 = w.gocuiSize.w1
w.logicalSize.h1 = w.gocuiSize.h1
} }
func (w *cuiWidget) moveTo(leftW int, topH int) { func (w *cuiWidget) moveTo(leftW int, topH int) {
if (w.isFake) { if (w.isFake) {
// don't ever move these return
} else {
w.gocuiSize.w0 = leftW
w.gocuiSize.h0 = topH
} }
w.gocuiSize.w1 = w.gocuiSize.w0 + w.realWidth w.gocuiSize.startW = leftW
w.gocuiSize.h1 = w.gocuiSize.h0 + w.realHeight w.gocuiSize.startH = topH
w.logicalSize.w0 = w.gocuiSize.w0
w.logicalSize.h0 = w.gocuiSize.h0
w.logicalSize.w1 = w.gocuiSize.w1
w.logicalSize.h1 = w.gocuiSize.h1
w.setWH()
w.showWidgetPlacement(logNow, "moveTo()") w.showWidgetPlacement(logNow, "moveTo()")
} }
/*
func (w *cuiWidget) updateLogicalSizes() { func (w *cuiWidget) updateLogicalSizes() {
for _, child := range w.children { for _, child := range w.children {
// if (w.isReal) // if (w.isReal)
@ -244,21 +208,12 @@ func (w *cuiWidget) updateLogicalSizes() {
} }
} }
} }
*/
func (w *cuiWidget) gridBounds() { func (w *cuiWidget) gridBounds() {
w.showWidgetPlacement(logNow, "gridBounds:") w.showWidgetPlacement(logNow, "gridBounds:")
p := w.parent p := w.parent
/*
for a := 0; a < w.x; a++ {
for b := 0; b < w.y; b++ {
log(logNow, "gridBounds() (w,h)", a, b,
"logical(W,H)", w.widths[a], w.heights[b],
"p.next(W,H)", p.nextW, p.nextH)
}
log("\n")
}
*/
var wCount int = 0 var wCount int = 0
var hCount int = 0 var hCount int = 0
for _, child := range w.children { for _, child := range w.children {

View File

@ -20,44 +20,84 @@ func (w *cuiWidget) setStartWH() {
w.isFake = true w.isFake = true
w.setFake() w.setFake()
w.showWidgetPlacement(logNow, "StartWH:") w.showWidgetPlacement(logNow, "StartWH:")
w.drawView()
return return
case toolkit.Flag: case toolkit.Flag:
w.isFake = true w.isFake = true
w.setFake() w.setFake()
w.showWidgetPlacement(logNow, "StartWH:") w.showWidgetPlacement(logNow, "StartWH:")
w.drawView()
return return
case toolkit.Window: case toolkit.Window:
w.setTabWH() w.setTabWH()
w.showWidgetPlacement(logNow, "StartWH:") w.showWidgetPlacement(logNow, "StartWH:")
w.drawView()
return return
case toolkit.Tab: case toolkit.Tab:
w.setTabWH() w.setTabWH()
w.showWidgetPlacement(logNow, "StartWH:") w.showWidgetPlacement(logNow, "StartWH:")
w.drawView()
return return
case toolkit.Box: case toolkit.Box:
w.isFake = true w.isFake = true
w.setFake() w.setFake()
w.getBoxWH() w.startW = w.parent.startW
w.setWH() w.startH = w.parent.startH
w.showWidgetPlacement(logNow, "StartWH:") w.showWidgetPlacement(logNow, "StartWH:")
w.drawView()
return return
case toolkit.Grid: case toolkit.Grid:
w.isFake = true w.isFake = true
w.setFake() w.setFake()
w.getGridWH() w.startW = w.parent.startW
w.setWH() w.startH = w.parent.startH
w.showWidgetPlacement(logNow, "StartWH:") w.showWidgetPlacement(logNow, "StartWH:")
w.drawView()
return return
case toolkit.Group: case toolkit.Group:
w.getGroupWH() w.startW = w.parent.startW + 4
w.startH = w.parent.startH + 3
t := len(w.text)
w.gocuiSize.width = t + me.buttonPadding
w.gocuiSize.height = me.defaultHeight
w.gocuiSize.startW = w.startW
w.gocuiSize.startH = w.startH
w.setWH() w.setWH()
w.showWidgetPlacement(logNow, "StartWH:") w.showWidgetPlacement(logNow, "StartWH:")
w.drawView()
return return
default: default:
w.startW = w.parent.startW
w.startH = w.parent.startH
w.setWH() w.setWH()
} }
} }
/*
func (w *cuiWidget) setStartFromParent() {
p := w.parent
switch p.widgetType {
case toolkit.Box:
w.getBoxWH()
case toolkit.Group:
w.getGroupWH()
case toolkit.Grid:
w.getGridWH()
default:
w.gocuiSize.startW = p.startW
w.gocuiSize.startH = p.startH
}
w.gocuiSize.startW = w.startW
w.gocuiSize.startH = w.startH
w.startW = w.gocuiSize.startW
w.startH = w.gocuiSize.startH
w.showWidgetPlacement(logNow, "sSFP:")
}
*/
func Action(a *toolkit.Action) { func Action(a *toolkit.Action) {
log(logInfo, "Action() START", a.WidgetId, a.ActionType, a.WidgetType, a.Name) log(logInfo, "Action() START", a.WidgetId, a.ActionType, a.WidgetType, a.Name)
w := findWidget(a.WidgetId, me.rootNode) w := findWidget(a.WidgetId, me.rootNode)
@ -65,9 +105,6 @@ func Action(a *toolkit.Action) {
case toolkit.Add: case toolkit.Add:
w = setupWidget(a) w = setupWidget(a)
w.setStartWH() w.setStartWH()
// w.moveTo(w.startW, w.startH)
w.drawView()
// findPlace(w)
case toolkit.Show: case toolkit.Show:
if (a.B) { if (a.B) {
w.drawView() w.drawView()

View File

@ -107,7 +107,7 @@ type cuiWidget struct {
realHeight int realHeight int
gocuiSize rectType // the display size of this widget gocuiSize 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 // used to track the size of grids
widths map[int]int // how tall each row in the grid is widths map[int]int // how tall each row in the grid is

View File

@ -57,6 +57,9 @@ func (w *cuiWidget) setTabWH() {
w.gocuiSize.startW = me.rootNode.startW w.gocuiSize.startW = me.rootNode.startW
w.gocuiSize.startH = me.rootNode.startH w.gocuiSize.startH = me.rootNode.startH
w.startW = w.gocuiSize.startW + 2
w.startH = w.gocuiSize.startH + 3
for _, child := range me.rootNode.children { for _, child := range me.rootNode.children {
if (child.isFake) { if (child.isFake) {
continue continue
@ -69,51 +72,17 @@ func (w *cuiWidget) setTabWH() {
w.gocuiSize.startW += child.realWidth w.gocuiSize.startW += child.realWidth
} }
w.startW = me.rootNode.startW
w.startH = me.rootNode.startH + me.buttonPadding
w.setWH() w.setWH()
w.showWidgetPlacement(logNow, "setTabWH:") w.showWidgetPlacement(logNow, "setTabWH:")
} }
func (w *cuiWidget) redoTabs(draw bool) { func (w *cuiWidget) redoTabs(draw bool) {
if (w == nil) {
return
}
log(logVerbose, "redoTabs() START about to check for window and tab ", w.name)
w.text = w.name
t := len(w.text)
if ((w.widgetType == toolkit.Window) || (w.widgetType == toolkit.Tab)) { if ((w.widgetType == toolkit.Window) || (w.widgetType == toolkit.Tab)) {
log(logVerbose, "redoTabs() in Window and Tab", w.name)
w.realWidth = t + me.buttonPadding
w.realHeight = me.defaultHeight
w.gocuiSize.w0 = me.rootNode.logicalSize.w1
w.gocuiSize.w1 = w.gocuiSize.w0 + w.realWidth
w.gocuiSize.h0 = 0
w.gocuiSize.h1 = w.realHeight
// start logical sizes windows and in the top left corner
w.logicalSize.w0 = 2
w.logicalSize.w1 = 2
w.logicalSize.h0 = w.realHeight
w.logicalSize.h1 = w.realHeight
// start all windows and in the top left corner
w.nextW = w.logicalSize.w0
w.nextH = w.logicalSize.h0
me.rootNode.logicalSize.w1 = w.gocuiSize.w1
me.rootNode.logicalSize.h1 = w.gocuiSize.h1
w.deleteView() w.deleteView()
w.drawView() w.drawView()
w.showWidgetPlacement(logNow, "redoTabs()")
} }
log(logVerbose, "redoTabs() about to for loop children", w.name)
for _, child := range w.children { for _, child := range w.children {
log(logVerbose, "redoTabs() got to child", child.name)
child.redoTabs(draw) child.redoTabs(draw)
} }
} }