From 4fa1dd75b04aad0a85d171a1d333d799a61ba713 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 28 Jan 2024 21:15:15 -0600 Subject: [PATCH] sizes are getting better Signed-off-by: Jeff Carr --- args.go | 2 +- debug.go | 4 ++-- place.go | 31 +++++++++++-------------------- size.go | 3 +-- structs.go | 4 ++-- view.go | 36 ++++++++++++------------------------ widget.go | 11 ++++++++--- 7 files changed, 37 insertions(+), 54 deletions(-) diff --git a/args.go b/args.go index a170ef5..c7cd12d 100644 --- a/args.go +++ b/args.go @@ -23,7 +23,7 @@ func init() { short := "gocui" 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") SPEW = log.NewFlag("SPEW", false, full, short, "spew stuff") diff --git a/debug.go b/debug.go index f9a5b4c..48049fe 100644 --- a/debug.go +++ b/debug.go @@ -36,7 +36,7 @@ func (w *guiWidget) showWidgetPlacement(s string) { s1 += fmt.Sprintf("gocui=(%2d,%2d,%2d,%2d)", w.gocuiSize.w0, w.gocuiSize.h0, w.gocuiSize.w1, w.gocuiSize.h1) } else { - s1 += fmt.Sprintf(" w.Visable() == false ") + s1 += fmt.Sprintf(" ") } if w.node.Parent != nil { if w.node.Parent.WidgetType == widget.Grid { @@ -44,5 +44,5 @@ func (w *guiWidget) showWidgetPlacement(s 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) } diff --git a/place.go b/place.go index bd602f7..48d7b3a 100644 --- a/place.go +++ b/place.go @@ -8,43 +8,32 @@ import ( "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 { - return 0, 0 + return } tk.dumpTree("beforebox") newW := startW newH := startH - var maxW int = 0 - var maxH int = 0 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 { log.Log(NOW, "BOX IS HORIZONTAL", tk.String(), "newWH()", newW, newH, "child()", sizeW, sizeH, child.String()) // expand based on the child width newW += sizeW - maxW += sizeW - if sizeH > maxH { - maxH = sizeH - } } else { log.Log(NOW, "BOX IS VERTICAL ", tk.String(), "newWH()", newW, newH, "child()", sizeW, sizeH, child.String()) // expand based on the child height 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") - return maxW, maxH } 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 var maxH int = 0 for _, child := range tk.children { - sizeW, sizeH := child.placeWidgets(newW, newH) + child.placeWidgets(newW, newH) + sizeW, sizeH := child.Size() if sizeW < 20 { sizeW = 20 } @@ -79,7 +69,8 @@ func (tk *guiWidget) placeWidgets(startW int, startH int) (int, int) { case widget.Grid: return tk.placeGrid(startW, startH) case widget.Box: - return tk.placeBox(startW, startH) + tk.placeBox(startW, startH) + return 0, 0 case widget.Group: // move the group to the parent's next location tk.gocuiSetWH(startW, startH) diff --git a/size.go b/size.go index 20d4ed8..5eb0d15 100644 --- a/size.go +++ b/size.go @@ -48,7 +48,7 @@ func (tk *guiWidget) Size() (int, int) { if tk.isFake { return 0, 0 } - return tk.gocuiSize.Width(), tk.gocuiSize.Height() + return len(tk.String()), 3 } func (w *guiWidget) sizeGrid() (int, int) { @@ -116,4 +116,3 @@ func (tk *guiWidget) sizeBox() (int, int) { } return maxW, maxH } - diff --git a/structs.go b/structs.go index 0eb96e7..85ac890 100644 --- a/structs.go +++ b/structs.go @@ -145,8 +145,8 @@ type guiWidget struct { active bool -// AtW int -// AtH int + // AtW int + // AtH int direction widget.Orientation diff --git a/view.go b/view.go index 389a141..138e2df 100644 --- a/view.go +++ b/view.go @@ -4,6 +4,7 @@ import ( "bufio" "errors" "fmt" + "strconv" "strings" "github.com/awesome-gocui/gocui" @@ -55,34 +56,32 @@ func (w *guiWidget) hideView() { // 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 func (w *guiWidget) showView() { - var err error - if w.cuiName == "" { 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 w.v == nil { w.recreateView() } - 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) + x0, y0, x1, y1, _ := 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(), x0, y0, x1, y1, err) // n.smartGocuiSize() changed := w.textResize() - if changed { - log.Log(NOW, "showView() textResize() changed. Should recreateView here wId =", w.cuiName) - } else { - log.Log(NOW, "showView() Clear() and Fprint() here wId =", w.cuiName) + if !changed { + log.Log(INFO, "showView() Clear() and Fprint() here wId =", w.cuiName) w.v.Clear() fmt.Fprint(w.v, w.labelN) w.SetVisible(false) w.SetVisible(true) 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 // recreate it @@ -96,7 +95,7 @@ func (w *guiWidget) showView() { return } 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() return } @@ -113,7 +112,7 @@ func (w *guiWidget) showView() { // deletes the old view if it exists and recreates it func (w *guiWidget) recreateView() { 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 { log.Log(ERROR, "recreateView() ERROR: me.baseGui == nil", w) return @@ -123,13 +122,6 @@ func (w *guiWidget) recreateView() { me.baseGui.DeleteView(w.cuiName) 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 b := w.gocuiSize.h0 c := w.gocuiSize.w1 @@ -173,11 +165,7 @@ func (w *guiWidget) recreateView() { w.v.SelFgColor = w.color.selFg w.v.SelBgColor = w.color.selBg } - if w.String() == "CLOUDFLARE_EMAIL" { - w.showWidgetPlacement("w.String()=" + w.String() + " w.label=" + w.labelN + " " + w.cuiName) - w.dumpTree("cloudflare") - } - log.Log(ERROR, "recreateView() END") + log.Log(INFO, "recreateView() END") } func (w *guiWidget) hideWidgets() { diff --git a/widget.go b/widget.go index 9b3bc5f..f32238f 100644 --- a/widget.go +++ b/widget.go @@ -1,6 +1,8 @@ package main import ( + "strconv" + "go.wit.com/log" "go.wit.com/toolkits/tree" "go.wit.com/widget" @@ -11,17 +13,20 @@ func initWidget(n *tree.Node) *guiWidget { w = new(guiWidget) // Set(w, "default") - w.frame = true + w.node = n // 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.labelN = n.State.Label if w.labelN == "" { w.labelN = n.GetProgName() } + w.frame = true if n.WidgetType == widget.Root { log.Log(INFO, "setupWidget() FOUND ROOT w.id =", n.WidgetId)