trying to compute sizes

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-01-28 20:15:59 -06:00
parent 63b76b2912
commit 3029f04bd2
7 changed files with 199 additions and 66 deletions

View File

@ -102,16 +102,16 @@ func (w *guiWidget) doWidgetClick() {
case widget.Window:
log.Log(NOW, "doWidgetClick() START on window", w.String())
/*
if me.currentWindow == w.node {
return
}
if me.currentWindow != nil {
var curw *guiWidget
curw = me.currentWindow.TK.(*guiWidget)
curw.unsetCurrent()
curw.setColor(&colorWindow)
curw.hideWidgets()
}
if me.currentWindow == w.node {
return
}
if me.currentWindow != nil {
var curw *guiWidget
curw = me.currentWindow.TK.(*guiWidget)
curw.unsetCurrent()
curw.setColor(&colorWindow)
curw.hideWidgets()
}
*/
me.currentWindow = w.node
@ -128,43 +128,45 @@ func (w *guiWidget) doWidgetClick() {
w.hideWidgets()
}
/*
w.redoTabs(me.TabW, me.TabH)
for _, child := range w.children {
if child.currentTab == true {
log.Log(NOW, "FOUND CURRENT TAB", child.String())
child.setCurrentTab()
child.placeWidgets(me.RawW, me.RawH)
child.showWidgets()
return
w.redoTabs(me.TabW, me.TabH)
for _, child := range w.children {
if child.currentTab == true {
log.Log(NOW, "FOUND CURRENT TAB", child.String())
child.setCurrentTab()
child.placeWidgets(me.RawW, me.RawH)
child.showWidgets()
return
}
}
}
*/
/* FIXME: redo this
if ! n.hasTabs {
}
*/
case widget.Tab:
if w.IsCurrent() {
return // do nothing if you reclick on the already selected tab
}
// find the window and disable the active tab
p := w.parent
if p != nil {
p.hideWidgets()
p.redoTabs(me.TabW, me.TabH)
p.unsetCurrent()
for _, child := range w.children {
if child.WidgetType == widget.Tab {
child.setColor(&colorTab)
child.currentTab = false
/*
case widget.Tab:
if w.IsCurrent() {
return // do nothing if you reclick on the already selected tab
}
// find the window and disable the active tab
p := w.parent
if p != nil {
p.hideWidgets()
p.redoTabs(me.TabW, me.TabH)
p.unsetCurrent()
for _, child := range w.children {
if child.WidgetType == widget.Tab {
child.setColor(&colorTab)
child.currentTab = false
}
}
}
}
w.currentTab = true
w.setColor(&colorActiveT)
w.setCurrentTab()
w.placeWidgets(me.RawW, me.RawH)
w.showWidgets()
w.currentTab = true
w.setColor(&colorActiveT)
w.setCurrentTab()
w.placeWidgets(me.RawW, me.RawH)
w.showWidgets()
*/
case widget.Group:
// n.placeWidgets(p.tk.startH, newH)
w.dumpTree("click start")
@ -175,11 +177,11 @@ func (w *guiWidget) doWidgetClick() {
w.placeWidgets(startW, startH)
w.showWidgets()
/*
for _, child := range w.children {
log.Log(INFO, "START W,H", startW, startH)
child.placeWidgets(startW, startH)
child.showWidgets()
}
for _, child := range w.children {
log.Log(INFO, "START W,H", startW, startH)
child.placeWidgets(startW, startH)
child.showWidgets()
}
*/
} else {
w.active = true

View File

@ -31,8 +31,9 @@ func (w *guiWidget) showWidgetPlacement(s string) {
}
s1 = fmt.Sprintf("(wId,pId)=(%2d,%2d) ", w.node.WidgetId, pId)
if w.Visible() {
sizeW, sizeH := w.Size()
s1 += fmt.Sprintf("gocui=(%2d,%2d)(%2d,%2d,%2d,%2d)",
w.gocuiSize.Width(), w.gocuiSize.Height(),
sizeW, sizeH,
w.gocuiSize.w0, w.gocuiSize.h0, w.gocuiSize.w1, w.gocuiSize.h1)
} else {
s1 += fmt.Sprintf(" w.Visable() == false ")

View File

@ -55,6 +55,9 @@ func (tk *guiWidget) placeWidgets(startW int, startH int) (int, int) {
return 0, 0
}
tk.startW = startW
tk.startH = startH
switch tk.WidgetType {
case widget.Window:
newW := startW
@ -103,7 +106,7 @@ func (tk *guiWidget) placeWidgets(startW int, startH int) (int, int) {
return maxW, newH - startH
default:
tk.gocuiSetWH(startW, startH)
return tk.Width(), tk.Height()
return tk.gocuiSize.Width(), tk.gocuiSize.Height()
}
return 0, 0
}
@ -116,7 +119,7 @@ func (w *guiWidget) placeGrid(startW int, startH int) (int, int) {
// first compute the max sizes of the rows and columns
for _, child := range w.children {
childW, childH := child.placeWidgets(startW, startH)
childW, childH := child.placeWidgets(child.startW, child.startH)
// set the child's realWidth, and grid offset
if w.widths[child.AtW] < childW {
@ -131,7 +134,7 @@ func (w *guiWidget) placeGrid(startW int, startH int) (int, int) {
var maxW int = 0
var maxH int = 0
// find the width and height offset of the grid for AtW,AtH
for _, child := range w.children {
child.showWidgetPlacement("grid1:")

119
size.go Normal file
View File

@ -0,0 +1,119 @@
package main
import (
"go.wit.com/widget"
)
func (tk *guiWidget) Size() (int, int) {
if tk == nil {
return 0, 0
}
if me.treeRoot == nil {
return 0, 0
}
switch tk.WidgetType {
case widget.Window:
var maxH int = 0
var maxW int = 0
for _, child := range tk.children {
sizeW, sizeH := child.Size()
maxW += sizeW
if sizeH > maxH {
maxH = sizeH
}
}
return maxW, maxH
case widget.Grid:
return tk.sizeGrid()
case widget.Box:
return tk.sizeBox()
case widget.Group:
// move the group to the parent's next location
maxW := tk.gocuiSize.Width()
maxH := tk.gocuiSize.Height()
for _, child := range tk.children {
sizeW, sizeH := child.Size()
// increment straight down
maxH += sizeH
if sizeW > maxW {
maxW = sizeW
}
}
return maxW, maxH
}
if tk.isFake {
return 0, 0
}
return tk.gocuiSize.Width(), tk.gocuiSize.Height()
}
func (w *guiWidget) sizeGrid() (int, int) {
// first compute the max sizes of the rows and columns
for _, child := range w.children {
sizeW, sizeH := child.Size()
// set the child's realWidth, and grid offset
if w.widths[child.AtW] < sizeW {
w.widths[child.AtW] = sizeW
}
if w.heights[child.AtH] < sizeH {
w.heights[child.AtH] = sizeH
}
}
var maxW int = 0
var maxH int = 0
// find the width and height offset of the grid for AtW,AtH
for _, child := range w.children {
var totalW, totalH int
for i, w := range w.widths {
if i < child.AtW {
totalW += w
}
}
for i, h := range w.heights {
if i < child.AtH {
totalH += h
}
}
if totalW > maxW {
maxW = totalW
}
if totalH > maxH {
maxH = totalH
}
}
return maxW, maxH
}
func (tk *guiWidget) sizeBox() (int, int) {
if tk.WidgetType != widget.Box {
return 0, 0
}
var maxW int = 0
var maxH int = 0
for _, child := range tk.children {
sizeW, sizeH := child.Size()
if child.direction == widget.Horizontal {
maxW += sizeW
if sizeH > maxH {
maxH = sizeH
}
} else {
maxH += sizeH
if sizeW > maxW {
maxW = sizeW
}
}
}
return maxW, maxH
}

View File

@ -160,8 +160,8 @@ type guiWidget struct {
// sometimes this isn't visible like with a Box or Grid
gocuiSize rectType
boxSizeW int
boxSizeH int
startW int
startH int
isCurrent bool // is this the currently displayed Window or Tab?
isFake bool // widget types like 'box' are 'false'

29
tab.go
View File

@ -3,11 +3,11 @@ package main
import (
"strings"
"go.wit.com/log"
"go.wit.com/widget"
)
func (w *guiWidget) Width() int {
/*
func (w *guiWidget) RealWidth() int {
if w.frame {
return w.gocuiSize.w1 - w.gocuiSize.w0
}
@ -20,6 +20,7 @@ func (w *guiWidget) Height() int {
}
return w.gocuiSize.h1 - w.gocuiSize.h0 - 1
}
*/
func (tk *guiWidget) gocuiSetWH(sizeW, sizeH int) {
w := len(widget.GetString(tk.value))
@ -73,17 +74,20 @@ func redoWindows(nextW int, nextH int) {
win.deleteView()
win.showView()
sizeW := win.Width() + me.WindowPadW
sizeH := win.Height()
nextW += sizeW
log.Log(NOW, "redoWindows() start nextW,H =", nextW, nextH, "gocuiSize.W,H =", sizeW, sizeH, win.String())
/*
sizeW := win.Width() + me.WindowPadW
sizeH := win.Height()
nextW += sizeW
log.Log(NOW, "redoWindows() start nextW,H =", nextW, nextH, "gocuiSize.W,H =", sizeW, sizeH, win.String())
if win.hasTabs {
win.redoTabs(me.TabW, me.TabH)
}
if win.hasTabs {
win.redoTabs(me.TabW, me.TabH)
}
*/
}
}
/*
func (p *guiWidget) redoTabs(nextW int, nextH int) {
for _, w := range p.children {
if w.node.WidgetType != widget.Tab {
@ -106,7 +110,9 @@ func (p *guiWidget) redoTabs(nextW int, nextH int) {
nextW += sizeW
}
}
*/
/*
func (p *guiWidget) drawWindow(nextW int, nextH int) {
for _, w := range p.children {
w.frame = true
@ -120,9 +126,10 @@ func (p *guiWidget) drawWindow(nextW int, nextH int) {
w.showView()
sizeW := w.Width() + me.TabPadW
sizeH := w.Height()
sizeW := w.gocuiSize.Width() + me.TabPadW
sizeH := w.gocuiSize.Height()
log.Log(NOW, "redoTabs() start nextW,H =", nextW, nextH, "gocuiSize.W,H =", sizeW, sizeH, w.String())
nextW += sizeW
}
}
*/

11
view.go
View File

@ -48,7 +48,8 @@ func (w *guiWidget) textResize() bool {
}
func (w *guiWidget) hideView() {
w.SetVisible(false)
// w.SetVisible(false)
w.deleteView()
}
// display's the text of the widget in gocui
@ -67,7 +68,7 @@ func (w *guiWidget) showView() {
w.recreateView()
}
x0, y0, x1, y1, err := me.baseGui.ViewPosition(w.cuiName)
log.Log(INFO, "showView() w.v already defined for widget", w.String(), err)
log.Log(INFO, "showView() w.v already defined for widget", w.String(), x0, y0, x1, y1, err)
// n.smartGocuiSize()
changed := w.textResize()
@ -123,10 +124,10 @@ func (w *guiWidget) recreateView() {
w.v = nil
if w.String() == "CLOUDFLARE_EMAIL" {
w.showWidgetPlacement("n.String()="+w.String()+" n.tk.label="+w.labelN+" "+w.cuiName)
w.showWidgetPlacement("n.String()=" + w.String() + " n.tk.label=" + w.labelN + " " + w.cuiName)
// w.dumpWidget("jwc")
w.textResize()
w.showWidgetPlacement("n.String()="+w.String()+" n.tk.label="+w.labelN+" "+w.cuiName)
w.showWidgetPlacement("n.String()=" + w.String() + " n.tk.label=" + w.labelN + " " + w.cuiName)
}
a := w.gocuiSize.w0
@ -173,7 +174,7 @@ func (w *guiWidget) recreateView() {
w.v.SelBgColor = w.color.selBg
}
if w.String() == "CLOUDFLARE_EMAIL" {
w.showWidgetPlacement("w.String()="+w.String()+" w.label="+w.labelN+" "+w.cuiName)
w.showWidgetPlacement("w.String()=" + w.String() + " w.label=" + w.labelN + " " + w.cuiName)
w.dumpTree("cloudflare")
}
log.Log(ERROR, "recreateView() END")