2024-02-05 01:08:12 -06:00
|
|
|
package main
|
|
|
|
|
2024-02-05 03:09:41 -06:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"github.com/awesome-gocui/gocui"
|
|
|
|
log "go.wit.com/log"
|
|
|
|
)
|
|
|
|
|
2024-02-05 01:08:12 -06:00
|
|
|
var toggle bool = true
|
|
|
|
|
|
|
|
func (w *guiWidget) DrawAt(offsetW, offsetH int) {
|
|
|
|
w.setColor(&colorActiveW)
|
|
|
|
w.placeWidgets(offsetW, offsetH) // compute the sizes & places for each widget
|
|
|
|
w.active = false
|
|
|
|
w.showWidgets()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *guiWidget) toggleTree() {
|
|
|
|
if toggle {
|
|
|
|
w.drawTree(toggle)
|
|
|
|
toggle = false
|
|
|
|
} else {
|
|
|
|
w.hideWidgets()
|
|
|
|
toggle = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// display the widgets in the binary tree
|
|
|
|
func (w *guiWidget) drawTree(draw bool) {
|
|
|
|
if w == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
w.showWidgetPlacement("drawTree()")
|
|
|
|
if draw {
|
|
|
|
// w.textResize()
|
2024-02-05 03:05:37 -06:00
|
|
|
w.Show()
|
2024-02-05 01:08:12 -06:00
|
|
|
} else {
|
2024-02-05 03:05:37 -06:00
|
|
|
w.Hide()
|
2024-02-05 01:08:12 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, child := range w.children {
|
|
|
|
child.drawTree(draw)
|
|
|
|
}
|
|
|
|
}
|
2024-02-05 03:09:41 -06:00
|
|
|
|
|
|
|
// display's the text of the widget in gocui
|
|
|
|
// deletes the old view if it exists and recreates it
|
2024-02-05 03:19:08 -06:00
|
|
|
func (w *guiWidget) drawView() {
|
2024-02-05 03:09:41 -06:00
|
|
|
var err error
|
2024-02-05 03:19:08 -06:00
|
|
|
log.Log(INFO, "drawView() START", w.WidgetType, w.String())
|
2024-02-05 03:09:41 -06:00
|
|
|
if me.baseGui == nil {
|
2024-02-05 03:19:08 -06:00
|
|
|
log.Log(ERROR, "drawView() ERROR: me.baseGui == nil", w)
|
2024-02-05 03:09:41 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if w.cuiName == "" {
|
2024-02-05 03:19:08 -06:00
|
|
|
log.Log(ERROR, "drawView() w.cuiName was not set for widget", w)
|
2024-02-05 03:09:41 -06:00
|
|
|
w.cuiName = strconv.Itoa(w.node.WidgetId) + " TK"
|
|
|
|
}
|
2024-02-05 03:19:08 -06:00
|
|
|
log.Log(INFO, "drawView() labelN =", w.labelN)
|
2024-02-05 03:09:41 -06:00
|
|
|
|
|
|
|
// this deletes the button from gocui
|
|
|
|
me.baseGui.DeleteView(w.cuiName)
|
|
|
|
w.v = nil
|
|
|
|
|
|
|
|
w.textResize()
|
|
|
|
a := w.gocuiSize.w0
|
|
|
|
b := w.gocuiSize.h0
|
|
|
|
c := w.gocuiSize.w1
|
|
|
|
d := w.gocuiSize.h1
|
|
|
|
|
|
|
|
w.v, err = me.baseGui.SetView(w.cuiName, a, b, c, d, 0)
|
|
|
|
if err == nil {
|
2024-02-05 03:19:08 -06:00
|
|
|
w.showWidgetPlacement("drawView()")
|
|
|
|
log.Log(ERROR, "drawView() internal plugin error err = nil")
|
2024-02-05 03:09:41 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if !errors.Is(err, gocui.ErrUnknownView) {
|
2024-02-05 03:19:08 -06:00
|
|
|
w.showWidgetPlacement("drawView()")
|
|
|
|
log.Log(ERROR, "drawView() internal plugin error error.IS()", err)
|
2024-02-05 03:09:41 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// this sets up the keybinding for the name of the window
|
|
|
|
// does this really need to be done? I think we probably already
|
|
|
|
// know everything about where all the widgets are so we could bypass
|
|
|
|
// the gocui package and just handle all the mouse events internally here (?)
|
|
|
|
// for now, the w.v.Name is a string "1", "2", "3", etc from the widgetId
|
|
|
|
|
|
|
|
// set the binding for this gocui view now that it has been created
|
|
|
|
// gocui handles overlaps of views so it will run on the view that is clicked on
|
|
|
|
me.baseGui.SetKeybinding(w.v.Name(), gocui.MouseLeft, gocui.ModNone, click)
|
|
|
|
|
|
|
|
// this actually sends the text to display to gocui
|
|
|
|
w.v.Wrap = true
|
|
|
|
w.v.Frame = w.frame
|
|
|
|
w.v.Clear()
|
|
|
|
fmt.Fprint(w.v, w.labelN)
|
|
|
|
|
|
|
|
// if you don't do this here, it will be black & white only
|
|
|
|
if w.color != nil {
|
|
|
|
w.v.FrameColor = w.color.frame
|
|
|
|
w.v.FgColor = w.color.fg
|
|
|
|
w.v.BgColor = w.color.bg
|
|
|
|
w.v.SelFgColor = w.color.selFg
|
|
|
|
w.v.SelBgColor = w.color.selBg
|
|
|
|
}
|
2024-02-05 03:19:08 -06:00
|
|
|
log.Log(INFO, "drawView() END")
|
2024-02-05 03:09:41 -06:00
|
|
|
}
|