trying to compute sizes
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
63b76b2912
commit
3029f04bd2
2
click.go
2
click.go
|
@ -143,6 +143,7 @@ func (w *guiWidget) doWidgetClick() {
|
|||
if ! n.hasTabs {
|
||||
}
|
||||
*/
|
||||
/*
|
||||
case widget.Tab:
|
||||
if w.IsCurrent() {
|
||||
return // do nothing if you reclick on the already selected tab
|
||||
|
@ -165,6 +166,7 @@ func (w *guiWidget) doWidgetClick() {
|
|||
w.setCurrentTab()
|
||||
w.placeWidgets(me.RawW, me.RawH)
|
||||
w.showWidgets()
|
||||
*/
|
||||
case widget.Group:
|
||||
// n.placeWidgets(p.tk.startH, newH)
|
||||
w.dumpTree("click start")
|
||||
|
|
3
debug.go
3
debug.go
|
@ -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 ")
|
||||
|
|
7
place.go
7
place.go
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
@ -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'
|
||||
|
|
15
tab.go
15
tab.go
|
@ -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,6 +74,7 @@ func redoWindows(nextW int, nextH int) {
|
|||
win.deleteView()
|
||||
win.showView()
|
||||
|
||||
/*
|
||||
sizeW := win.Width() + me.WindowPadW
|
||||
sizeH := win.Height()
|
||||
nextW += sizeW
|
||||
|
@ -81,9 +83,11 @@ func redoWindows(nextW int, nextH int) {
|
|||
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
11
view.go
|
@ -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")
|
||||
|
|
Loading…
Reference in New Issue