diff options
| author | Jeff Carr <[email protected]> | 2023-04-03 10:26:47 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2023-04-03 10:26:47 -0500 |
| commit | 4b6207743b90968d6b822032a4355e43b6ce6da9 (patch) | |
| tree | 2cb9f13d5e95f14e165f8e41e8484320b7454177 /toolkit/gocui/view.go | |
| parent | 0320ebe4bb49ea80761d77af80fa208157ffdb89 (diff) | |
gocui: working towards correct layout
make a gocui widget binary tree
more debugging cleanups
sample button app displays in gocui
geometry logic closer to correct
improvements in gocui layout
continued attempts to clean up tabs
dump binary tree
moving towards proper chan callback()
deprecate Widget.Name
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'toolkit/gocui/view.go')
| -rw-r--r-- | toolkit/gocui/view.go | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/toolkit/gocui/view.go b/toolkit/gocui/view.go new file mode 100644 index 0000000..d1d4b51 --- /dev/null +++ b/toolkit/gocui/view.go @@ -0,0 +1,86 @@ +package main + +import ( + "fmt" + "errors" + "strconv" + "bufio" + "strings" + + "github.com/awesome-gocui/gocui" +// "git.wit.org/wit/gui/toolkit" +) + +func splitLines(s string) []string { + var lines []string + sc := bufio.NewScanner(strings.NewReader(s)) + for sc.Scan() { + lines = append(lines, sc.Text()) + } + return lines +} + +func (w *cuiWidget) textResize() { + var width, height int + + for i, s := range splitLines(w.text) { + log(logNow, "textResize() len =", len(s), i, s) + if (width < len(s)) { + width = len(s) + } + height = i + } + w.realWidth = width + 3 + w.realHeight = me.defaultHeight + height + w.realSize.w1 = w.realSize.w0 + w.realWidth + w.realSize.h1 = w.realSize.h0 + w.realHeight + w.showWidgetPlacement(logNow, "textResize()") +} + +func (w *cuiWidget) drawView() { + var err error + if (w.cuiName == "") { + log(logError, "drawView() w.cuiName was not set for widget", w) + w.cuiName = strconv.Itoa(w.id) + } + + if (w.v != nil) { + log(logInfo, "drawView() w.v already defined for widget", w) + v, _ := me.baseGui.View(w.cuiName) + if (v == nil) { + log(logError, "drawView() ERROR view does not really exist", w) + w.v = nil + } else { + return + } + } + + v, _ := me.baseGui.View(w.cuiName) + if (v != nil) { + log(logError, "drawView() already defined for name", w.cuiName) + w.v = v + return + } + + a := w.realSize.w0 + b := w.realSize.h0 + c := w.realSize.w1 + d := w.realSize.h1 + + w.v, err = me.baseGui.SetView(w.cuiName, a, b, c, d, 0) + if err == nil { + log(logError, "drawView() internal plugin error err = nil") + return + } + if !errors.Is(err, gocui.ErrUnknownView) { + log(logError, "drawView() internal plugin error error.IS()", err) + return + } + + me.baseGui.SetKeybinding(w.v.Name(), gocui.MouseLeft, gocui.ModNone, click) + + w.v.Wrap = true + fmt.Fprintln(w.v, " " + w.text) + + // w.SetDefaultWidgetColor() +} |
