sizes are getting better

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-01-28 21:15:15 -06:00
parent 1d7b9613a6
commit 4fa1dd75b0
7 changed files with 37 additions and 54 deletions

View File

@ -23,7 +23,7 @@ func init() {
short := "gocui" short := "gocui"
NOW = log.NewFlag("NOW", true, full, short, "temp debugging stuff") NOW = log.NewFlag("NOW", true, full, short, "temp debugging stuff")
INFO = log.NewFlag("INFO", true, full, short, "normal debugging stuff") INFO = log.NewFlag("INFO", false, full, short, "normal debugging stuff")
WARN = log.NewFlag("WARN", true, full, short, "bad things") WARN = log.NewFlag("WARN", true, full, short, "bad things")
SPEW = log.NewFlag("SPEW", false, full, short, "spew stuff") SPEW = log.NewFlag("SPEW", false, full, short, "spew stuff")

View File

@ -36,7 +36,7 @@ func (w *guiWidget) showWidgetPlacement(s string) {
s1 += fmt.Sprintf("gocui=(%2d,%2d,%2d,%2d)", s1 += fmt.Sprintf("gocui=(%2d,%2d,%2d,%2d)",
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(" ")
} }
if w.node.Parent != nil { if w.node.Parent != nil {
if w.node.Parent.WidgetType == widget.Grid { if w.node.Parent.WidgetType == widget.Grid {
@ -44,5 +44,5 @@ func (w *guiWidget) showWidgetPlacement(s string) {
} }
} }
tmp := "." + w.String() + "." tmp := "." + w.String() + "."
log.Log(INFO, s1, s, w.node.WidgetType, ",", tmp, "jcarr") // , "text=", w.text) log.Log(NOW, s1, s, w.node.WidgetType, ",", tmp, "jcarr") // , "text=", w.text)
} }

View File

@ -8,43 +8,32 @@ import (
"go.wit.com/widget" "go.wit.com/widget"
) )
func (tk *guiWidget) placeBox(startW int, startH int) (int, int) { func (tk *guiWidget) placeBox(startW int, startH int) {
if tk.WidgetType != widget.Box { if tk.WidgetType != widget.Box {
return 0, 0 return
} }
tk.dumpTree("beforebox") tk.dumpTree("beforebox")
newW := startW newW := startW
newH := startH newH := startH
var maxW int = 0
var maxH int = 0
for _, child := range tk.children { for _, child := range tk.children {
sizeW, sizeH := child.placeWidgets(newW, newH) sizeW, sizeH := child.Size()
log.Log(NOW, "BOX START size(W,H) =", sizeW, sizeH, "new(W,H) =", newW, newH)
child.placeWidgets(newW, newH)
sizeW, sizeH = child.Size()
if child.direction == widget.Horizontal { if child.direction == widget.Horizontal {
log.Log(NOW, "BOX IS HORIZONTAL", tk.String(), "newWH()", newW, newH, "child()", sizeW, sizeH, child.String()) log.Log(NOW, "BOX IS HORIZONTAL", tk.String(), "newWH()", newW, newH, "child()", sizeW, sizeH, child.String())
// expand based on the child width // expand based on the child width
newW += sizeW newW += sizeW
maxW += sizeW
if sizeH > maxH {
maxH = sizeH
}
} else { } else {
log.Log(NOW, "BOX IS VERTICAL ", tk.String(), "newWH()", newW, newH, "child()", sizeW, sizeH, child.String()) log.Log(NOW, "BOX IS VERTICAL ", tk.String(), "newWH()", newW, newH, "child()", sizeW, sizeH, child.String())
// expand based on the child height // expand based on the child height
newH += sizeH newH += sizeH
maxH += sizeH
if sizeW > maxW {
maxW = sizeW
} }
log.Log(NOW, "BOX END size(W,H) =", sizeW, sizeH, "new(W,H) =", newW, newH)
} }
}
// just compute this every time?
// newR := n.realGocuiSize()
tk.dumpTree("afterbox") tk.dumpTree("afterbox")
return maxW, maxH
} }
func (tk *guiWidget) placeWidgets(startW int, startH int) (int, int) { func (tk *guiWidget) placeWidgets(startW int, startH int) (int, int) {
@ -64,7 +53,8 @@ func (tk *guiWidget) placeWidgets(startW int, startH int) (int, int) {
newH := startH newH := startH
var maxH int = 0 var maxH int = 0
for _, child := range tk.children { for _, child := range tk.children {
sizeW, sizeH := child.placeWidgets(newW, newH) child.placeWidgets(newW, newH)
sizeW, sizeH := child.Size()
if sizeW < 20 { if sizeW < 20 {
sizeW = 20 sizeW = 20
} }
@ -79,7 +69,8 @@ func (tk *guiWidget) placeWidgets(startW int, startH int) (int, int) {
case widget.Grid: case widget.Grid:
return tk.placeGrid(startW, startH) return tk.placeGrid(startW, startH)
case widget.Box: case widget.Box:
return tk.placeBox(startW, startH) tk.placeBox(startW, startH)
return 0, 0
case widget.Group: case widget.Group:
// move the group to the parent's next location // move the group to the parent's next location
tk.gocuiSetWH(startW, startH) tk.gocuiSetWH(startW, startH)

View File

@ -48,7 +48,7 @@ func (tk *guiWidget) Size() (int, int) {
if tk.isFake { if tk.isFake {
return 0, 0 return 0, 0
} }
return tk.gocuiSize.Width(), tk.gocuiSize.Height() return len(tk.String()), 3
} }
func (w *guiWidget) sizeGrid() (int, int) { func (w *guiWidget) sizeGrid() (int, int) {
@ -116,4 +116,3 @@ func (tk *guiWidget) sizeBox() (int, int) {
} }
return maxW, maxH return maxW, maxH
} }

View File

@ -145,8 +145,8 @@ type guiWidget struct {
active bool active bool
// AtW int // AtW int
// AtH int // AtH int
direction widget.Orientation direction widget.Orientation

36
view.go
View File

@ -4,6 +4,7 @@ import (
"bufio" "bufio"
"errors" "errors"
"fmt" "fmt"
"strconv"
"strings" "strings"
"github.com/awesome-gocui/gocui" "github.com/awesome-gocui/gocui"
@ -55,34 +56,32 @@ func (w *guiWidget) hideView() {
// display's the text of the widget in gocui // display's the text of the widget in gocui
// will create a new gocui view if there isn't one or if it has been moved // will create a new gocui view if there isn't one or if it has been moved
func (w *guiWidget) showView() { func (w *guiWidget) showView() {
var err error
if w.cuiName == "" { if w.cuiName == "" {
log.Log(ERROR, "showView() w.cuiName was not set for widget", w) log.Log(ERROR, "showView() w.cuiName was not set for widget", w)
w.cuiName = string(w.node.WidgetId) w.cuiName = strconv.Itoa(w.node.WidgetId) + " TK"
} }
log.Log(ERROR, "showView() labelN =", w.labelN) log.Log(INFO, "showView() labelN =", w.labelN)
// if the gocui element doesn't exist, create it // if the gocui element doesn't exist, create it
if w.v == nil { if w.v == nil {
w.recreateView() w.recreateView()
} }
x0, y0, x1, y1, err := me.baseGui.ViewPosition(w.cuiName) x0, y0, x1, y1, _ := me.baseGui.ViewPosition(w.cuiName)
log.Log(INFO, "showView() w.v already defined for widget", w.String(), x0, y0, x1, y1, err) // x0, y0, x1, y1, err := me.baseGui.ViewPosition(w.cuiName)
// 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()
if changed { if !changed {
log.Log(NOW, "showView() textResize() changed. Should recreateView here wId =", w.cuiName) log.Log(INFO, "showView() Clear() and Fprint() here wId =", w.cuiName)
} else {
log.Log(NOW, "showView() Clear() and Fprint() here wId =", w.cuiName)
w.v.Clear() w.v.Clear()
fmt.Fprint(w.v, w.labelN) fmt.Fprint(w.v, w.labelN)
w.SetVisible(false) w.SetVisible(false)
w.SetVisible(true) w.SetVisible(true)
return return
} }
log.Log(INFO, "showView() textResize() changed. Should recreateView here wId =", w.cuiName)
// if the gocui element has changed where it is supposed to be on the screen // if the gocui element has changed where it is supposed to be on the screen
// recreate it // recreate it
@ -96,7 +95,7 @@ func (w *guiWidget) showView() {
return return
} }
if x1 != w.gocuiSize.w1 { if x1 != w.gocuiSize.w1 {
log.Log(ERROR, "showView() too wide", w.cuiName, "w,w", w.gocuiSize.w1, x1) log.Log(INFO, "showView() too wide", w.cuiName, "w,w", w.gocuiSize.w1, x1)
w.recreateView() w.recreateView()
return return
} }
@ -113,7 +112,7 @@ func (w *guiWidget) showView() {
// deletes the old view if it exists and recreates it // deletes the old view if it exists and recreates it
func (w *guiWidget) recreateView() { func (w *guiWidget) recreateView() {
var err error var err error
log.Log(ERROR, "recreateView() START", w.WidgetType, w.String()) log.Log(INFO, "recreateView() START", w.WidgetType, w.String())
if me.baseGui == nil { if me.baseGui == nil {
log.Log(ERROR, "recreateView() ERROR: me.baseGui == nil", w) log.Log(ERROR, "recreateView() ERROR: me.baseGui == nil", w)
return return
@ -123,13 +122,6 @@ func (w *guiWidget) recreateView() {
me.baseGui.DeleteView(w.cuiName) me.baseGui.DeleteView(w.cuiName)
w.v = nil w.v = nil
if w.String() == "CLOUDFLARE_EMAIL" {
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)
}
a := w.gocuiSize.w0 a := w.gocuiSize.w0
b := w.gocuiSize.h0 b := w.gocuiSize.h0
c := w.gocuiSize.w1 c := w.gocuiSize.w1
@ -173,11 +165,7 @@ func (w *guiWidget) recreateView() {
w.v.SelFgColor = w.color.selFg w.v.SelFgColor = w.color.selFg
w.v.SelBgColor = w.color.selBg w.v.SelBgColor = w.color.selBg
} }
if w.String() == "CLOUDFLARE_EMAIL" { log.Log(INFO, "recreateView() END")
w.showWidgetPlacement("w.String()=" + w.String() + " w.label=" + w.labelN + " " + w.cuiName)
w.dumpTree("cloudflare")
}
log.Log(ERROR, "recreateView() END")
} }
func (w *guiWidget) hideWidgets() { func (w *guiWidget) hideWidgets() {

View File

@ -1,6 +1,8 @@
package main package main
import ( import (
"strconv"
"go.wit.com/log" "go.wit.com/log"
"go.wit.com/toolkits/tree" "go.wit.com/toolkits/tree"
"go.wit.com/widget" "go.wit.com/widget"
@ -11,17 +13,20 @@ func initWidget(n *tree.Node) *guiWidget {
w = new(guiWidget) w = new(guiWidget)
// Set(w, "default") // Set(w, "default")
w.frame = true w.node = n
// set the name used by gocui to the id // set the name used by gocui to the id
w.cuiName = string(n.WidgetId) // w.cuiName = string(n.WidgetId)
w.cuiName = strconv.Itoa(w.node.WidgetId) + " TK"
w.node = n
w.WidgetType = n.WidgetType w.WidgetType = n.WidgetType
w.labelN = n.State.Label w.labelN = n.State.Label
if w.labelN == "" { if w.labelN == "" {
w.labelN = n.GetProgName() w.labelN = n.GetProgName()
} }
w.frame = true
if n.WidgetType == widget.Root { if n.WidgetType == widget.Root {
log.Log(INFO, "setupWidget() FOUND ROOT w.id =", n.WidgetId) log.Log(INFO, "setupWidget() FOUND ROOT w.id =", n.WidgetId)