diff --git a/toolkit/gocui/click.go b/toolkit/gocui/click.go index 1ce25a4..6df3278 100644 --- a/toolkit/gocui/click.go +++ b/toolkit/gocui/click.go @@ -18,28 +18,17 @@ func (w *cuiWidget) doWidgetClick() { case toolkit.Flag: me.rootNode.redoColor(true) case toolkit.Window: - w.redoBox(true) + w.drawBox() w.toggleTree() case toolkit.Tab: - w.redoBox(true) + w.drawBox() w.toggleTree() case toolkit.Group: - w.redoBox(true) + w.drawBox() w.toggleTree() case toolkit.Grid: - // w.setParentLogical() - w.gridBounds() - // w.setParentLogical() - for _, child := range w.children { - child.showWidgetPlacement(logNow, "gridBounds:") - if (child.v == nil) { - child.drawView() - } else { - child.deleteView() - } - } - // w.toggleTree() - // w.redoBox(true) + w.drawGrid() + w.toggleTree() case toolkit.Box: // w.showWidgetPlacement(logNow, "drawTree()") if (w.horizontal) { @@ -47,7 +36,7 @@ func (w *cuiWidget) doWidgetClick() { } else { log("BOX IS VERTICAL", w.name) } - w.redoBox(true) + w.drawBox() w.toggleTree() default: } diff --git a/toolkit/gocui/common.go b/toolkit/gocui/common.go index 663994d..a999539 100644 --- a/toolkit/gocui/common.go +++ b/toolkit/gocui/common.go @@ -23,6 +23,8 @@ func setupWidget(a *toolkit.Action) *cuiWidget { t := len(w.text) w.realWidth = t + me.buttonPadding w.realHeight = me.defaultHeight + w.gocuiSize.width = t + me.buttonPadding + w.gocuiSize.height = me.defaultHeight w.widgetType = a.WidgetType w.id = a.WidgetId diff --git a/toolkit/gocui/place.go b/toolkit/gocui/place.go index dbee72f..56fc3ba 100644 --- a/toolkit/gocui/place.go +++ b/toolkit/gocui/place.go @@ -96,10 +96,10 @@ func (w *cuiWidget) getGridWH() { w.startH = p.startH w.nextW = p.startW w.nextH = p.startH - w.gridBounds() + w.drawGrid() } -func (w *cuiWidget) redoBox(draw bool) { +func (w *cuiWidget) drawBox() { if (w == nil) { return } @@ -114,60 +114,82 @@ func (w *cuiWidget) redoBox(draw bool) { switch w.widgetType { case toolkit.Window: + // draw only one thing for _, child := range w.children { - child.redoBox(draw) + child.drawBox() + return } case toolkit.Tab: + // draw only one thing for _, child := range w.children { - child.redoBox(draw) + child.drawBox() + return } case toolkit.Grid: - w.nextW = p.nextW - w.nextH = p.nextH - w.gridBounds() + w.startW = p.startW + w.startH = p.startH + w.getGridWH() + w.showWidgetPlacement(logNow, "drawBox:") case toolkit.Box: - w.nextW = p.nextW - w.nextH = p.nextH + w.startW = p.startW + w.startH = p.startH + var maxW int + var maxH int for _, child := range w.children { - child.redoBox(draw) + child.drawBox() if (w.horizontal) { - log("BOX IS HORIZONTAL", p.nextW, p.nextW, p.name) - log("BOX IS HORIZONTAL", w.nextW, w.nextH, w.name) log("BOX IS HORIZONTAL") // expand based on the child width - w.nextW = child.nextW + me.horizontalPadding - // reset height to parent - w.nextH = p.nextH + w.startW += child.realWidth } else { - log("BOX IS VERTICAL", p.nextW, p.nextW, p.name) - log("BOX IS VERTICAL", w.nextW, w.nextH, w.name) log("BOX IS VERTICAL") - // go straight down - w.nextW = p.nextW // expand based on the child height - w.nextH = child.nextH + w.startH += child.realHeight + } + if (maxW < child.realWidth) { + maxW = child.realWidth + } + if (maxH < child.realHeight) { + maxH = child.realHeight } } - w.showWidgetPlacement(logNow, "box:") + w.realWidth = maxW + w.realHeight = maxH + w.showWidgetPlacement(logNow, "drawBox:") case toolkit.Group: - w.moveTo(p.nextW, p.nextH) + w.startW = p.startW + w.startH = p.startH + w.gocuiSize.startW = w.startW + w.gocuiSize.startH = w.startH + w.realWidth = w.gocuiSize.width + w.realHeight = w.gocuiSize.height + w.setWH() - w.nextW = p.nextW + me.groupPadding - w.nextH = p.nextH + me.buttonPadding + w.startW = p.startW + 4 + w.startH = p.startH + 3 + var maxW int + var maxH int for _, child := range w.children { - child.redoBox(draw) + child.drawBox() // reset nextW to straight down - w.nextW = p.nextW + 4 - w.nextH = child.nextH + w.startH += child.realHeight + if (maxW < child.realWidth) { + maxW = child.realWidth + } + if (maxH < child.realHeight) { + maxH = child.realHeight + } } - // expand the height of the parent now that the group is done - // p.nextW = w.nextW - // p.nextH = w.nextH - w.showWidgetPlacement(logNow, "group:") + w.realWidth += maxW + w.realHeight += maxH + w.showWidgetPlacement(logNow, "drawBox:") default: - w.moveTo(p.nextW, p.nextH) - w.nextW = w.gocuiSize.w1 - w.nextH = w.gocuiSize.h1 + w.startW = p.startW + w.startH = p.startH + w.gocuiSize.startW = w.startW + w.gocuiSize.startH = w.startH + w.setWH() + w.showWidgetPlacement(logNow, "drawBox:") } } @@ -210,17 +232,16 @@ func (w *cuiWidget) updateLogicalSizes() { } */ -func (w *cuiWidget) gridBounds() { +func (w *cuiWidget) drawGrid() { w.showWidgetPlacement(logNow, "gridBounds:") - p := w.parent 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) + w.nextW = w.startW + wCount * 20 + w.nextH = w.startH + hCount * 2 + // child.drawBox() // set the child's realWidth, and grid offset child.parentH = hCount @@ -271,11 +292,12 @@ func (w *cuiWidget) gridBounds() { realW := w.nextW + totalW realH := w.nextH + totalH - - log(logInfo, "gridBounds()", child.id, "parent (W,H) =", child.parentW, child.parentH, + log(logNow, "gridBounds()", child.id, "parent (W,H) =", child.parentW, child.parentH, "total (W,H) =", totalW, totalH, "real (W,H) =", realW, realH) - child.moveTo(realW, realH) + w.startW = realW + w.startH = realH + child.drawBox() child.showWidgetPlacement(logInfo, "gridBounds:") log(logInfo) }