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: case widget.Window:
log.Log(NOW, "doWidgetClick() START on window", w.String()) log.Log(NOW, "doWidgetClick() START on window", w.String())
/* /*
if me.currentWindow == w.node { if me.currentWindow == w.node {
return return
} }
if me.currentWindow != nil { if me.currentWindow != nil {
var curw *guiWidget var curw *guiWidget
curw = me.currentWindow.TK.(*guiWidget) curw = me.currentWindow.TK.(*guiWidget)
curw.unsetCurrent() curw.unsetCurrent()
curw.setColor(&colorWindow) curw.setColor(&colorWindow)
curw.hideWidgets() curw.hideWidgets()
} }
*/ */
me.currentWindow = w.node me.currentWindow = w.node
@ -128,43 +128,45 @@ func (w *guiWidget) doWidgetClick() {
w.hideWidgets() w.hideWidgets()
} }
/* /*
w.redoTabs(me.TabW, me.TabH) w.redoTabs(me.TabW, me.TabH)
for _, child := range w.children { for _, child := range w.children {
if child.currentTab == true { if child.currentTab == true {
log.Log(NOW, "FOUND CURRENT TAB", child.String()) log.Log(NOW, "FOUND CURRENT TAB", child.String())
child.setCurrentTab() child.setCurrentTab()
child.placeWidgets(me.RawW, me.RawH) child.placeWidgets(me.RawW, me.RawH)
child.showWidgets() child.showWidgets()
return return
}
} }
}
*/ */
/* FIXME: redo this /* FIXME: redo this
if ! n.hasTabs { if ! n.hasTabs {
} }
*/ */
case widget.Tab: /*
if w.IsCurrent() { case widget.Tab:
return // do nothing if you reclick on the already selected 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 // find the window and disable the active tab
if p != nil { p := w.parent
p.hideWidgets() if p != nil {
p.redoTabs(me.TabW, me.TabH) p.hideWidgets()
p.unsetCurrent() p.redoTabs(me.TabW, me.TabH)
for _, child := range w.children { p.unsetCurrent()
if child.WidgetType == widget.Tab { for _, child := range w.children {
child.setColor(&colorTab) if child.WidgetType == widget.Tab {
child.currentTab = false child.setColor(&colorTab)
child.currentTab = false
}
} }
} }
} w.currentTab = true
w.currentTab = true w.setColor(&colorActiveT)
w.setColor(&colorActiveT) w.setCurrentTab()
w.setCurrentTab() w.placeWidgets(me.RawW, me.RawH)
w.placeWidgets(me.RawW, me.RawH) w.showWidgets()
w.showWidgets() */
case widget.Group: case widget.Group:
// n.placeWidgets(p.tk.startH, newH) // n.placeWidgets(p.tk.startH, newH)
w.dumpTree("click start") w.dumpTree("click start")
@ -175,11 +177,11 @@ func (w *guiWidget) doWidgetClick() {
w.placeWidgets(startW, startH) w.placeWidgets(startW, startH)
w.showWidgets() w.showWidgets()
/* /*
for _, child := range w.children { for _, child := range w.children {
log.Log(INFO, "START W,H", startW, startH) log.Log(INFO, "START W,H", startW, startH)
child.placeWidgets(startW, startH) child.placeWidgets(startW, startH)
child.showWidgets() child.showWidgets()
} }
*/ */
} else { } else {
w.active = true 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) s1 = fmt.Sprintf("(wId,pId)=(%2d,%2d) ", w.node.WidgetId, pId)
if w.Visible() { if w.Visible() {
sizeW, sizeH := w.Size()
s1 += fmt.Sprintf("gocui=(%2d,%2d)(%2d,%2d,%2d,%2d)", 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) w.gocuiSize.w0, w.gocuiSize.h0, w.gocuiSize.w1, w.gocuiSize.h1)
} else { } else {
s1 += fmt.Sprintf(" w.Visable() == false ") 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 return 0, 0
} }
tk.startW = startW
tk.startH = startH
switch tk.WidgetType { switch tk.WidgetType {
case widget.Window: case widget.Window:
newW := startW newW := startW
@ -103,7 +106,7 @@ func (tk *guiWidget) placeWidgets(startW int, startH int) (int, int) {
return maxW, newH - startH return maxW, newH - startH
default: default:
tk.gocuiSetWH(startW, startH) tk.gocuiSetWH(startW, startH)
return tk.Width(), tk.Height() return tk.gocuiSize.Width(), tk.gocuiSize.Height()
} }
return 0, 0 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 // first compute the max sizes of the rows and columns
for _, child := range w.children { 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 // set the child's realWidth, and grid offset
if w.widths[child.AtW] < childW { 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 maxW int = 0
var maxH int = 0 var maxH int = 0
// find the width and height offset of the grid for AtW,AtH // find the width and height offset of the grid for AtW,AtH
for _, child := range w.children { for _, child := range w.children {
child.showWidgetPlacement("grid1:") 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 // sometimes this isn't visible like with a Box or Grid
gocuiSize rectType gocuiSize rectType
boxSizeW int startW int
boxSizeH int startH int
isCurrent bool // is this the currently displayed Window or Tab? isCurrent bool // is this the currently displayed Window or Tab?
isFake bool // widget types like 'box' are 'false' isFake bool // widget types like 'box' are 'false'

29
tab.go
View File

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

11
view.go
View File

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