gocui/treeDraw.go

151 lines
3.2 KiB
Go
Raw Normal View History

2025-02-01 11:42:31 -06:00
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0
package main
import (
"errors"
"fmt"
"strconv"
"github.com/awesome-gocui/gocui"
log "go.wit.com/log"
2025-02-04 09:40:51 -06:00
"go.wit.com/widget"
)
2025-02-04 09:40:51 -06:00
// display's the text of the widget in gocui
// deletes the old view if it exists and recreates it
func (tk *guiWidget) drawView() {
var err error
log.Log(INFO, "drawView() START", tk.node.WidgetType, tk.String())
if me.baseGui == nil {
log.Log(ERROR, "drawView() ERROR: me.baseGui == nil", tk)
return
}
if tk.cuiName == "" {
log.Log(ERROR, "drawView() tk.cuiName was not set for widget", tk)
tk.cuiName = strconv.Itoa(tk.node.WidgetId) + " TK"
}
log.Log(INFO, "drawView() labelN =", tk.labelN)
// this deletes the button from gocui
me.baseGui.DeleteView(tk.cuiName)
tk.v = nil
2025-02-04 11:33:10 -06:00
a := tk.gocuiSize.w0
b := tk.gocuiSize.h0
c := tk.gocuiSize.w1
d := tk.gocuiSize.h1
2025-02-06 15:19:39 -06:00
// this is all terrible. This sets the title. kinda
2025-02-04 09:40:51 -06:00
if tk.node.WidgetType == widget.Window {
2025-02-06 15:19:39 -06:00
tk.textResize()
tk.full.w0 = tk.force.w0
tk.full.h0 = tk.force.h0
// for windows, make it the full size
a = tk.full.w0
b = tk.full.h0
c = tk.full.w0 + tk.gocuiSize.Width()
d = tk.full.h0 + tk.gocuiSize.Height()
2025-02-04 09:40:51 -06:00
} else {
if tk.internal {
// do nothing
} else {
tk.textResize() // resize gocui frame to the widget text
}
2025-02-04 11:33:10 -06:00
a = tk.gocuiSize.w0
b = tk.gocuiSize.h0
c = tk.gocuiSize.w1
d = tk.gocuiSize.h1
2025-02-04 09:40:51 -06:00
}
tk.v, err = me.baseGui.SetView(tk.cuiName, a, b, c, d, 0)
if err == nil {
tk.dumpWidget("drawView() err")
log.Log(ERROR, "drawView() internal plugin error err = nil")
return
}
if !errors.Is(err, gocui.ErrUnknownView) {
tk.dumpWidget("drawView() err")
log.Log(ERROR, "drawView() internal plugin error error.IS()", err)
return
}
// this actually sends the text to display to gocui
tk.v.Wrap = true
tk.v.Frame = tk.frame
tk.v.Clear()
fmt.Fprint(tk.v, tk.labelN)
// if you don't do this here, it will be black & white only
if tk.color != nil {
tk.v.FrameColor = tk.color.frame
tk.v.FgColor = tk.color.fg
tk.v.BgColor = tk.color.bg
tk.v.SelFgColor = tk.color.selFg
tk.v.SelBgColor = tk.color.selBg
}
log.Log(INFO, "drawView() END")
}
func (w *guiWidget) DrawAt(offsetW, offsetH int) {
w.setColor(&colorActiveW)
w.placeWidgets(offsetW, offsetH) // compute the sizes & places for each widget
2025-02-05 11:58:27 -06:00
// w.dumpWidget(fmt.Sprintf("DrawAt(%d,%d)", offsetW, offsetH))
}
2025-02-03 15:47:50 -06:00
func (w *guiWidget) simpleDrawAt(offsetW, offsetH int) {
w.setColor(&colorActiveW)
w.dumpWidget("simpleDrawAt()")
}
2025-02-07 00:35:08 -06:00
/*
2025-02-04 09:40:51 -06:00
var toggle bool = true
func (w *guiWidget) toggleTree() {
if toggle {
w.drawTree(toggle)
toggle = false
} else {
w.hideWidgets()
toggle = true
}
}
2025-02-07 00:35:08 -06:00
*/
// display the widgets in the binary tree
func (w *guiWidget) drawTree(draw bool) {
if w == nil {
return
}
w.dumpWidget("in drawTree()")
if draw {
// w.textResize()
w.Show()
} else {
w.Hide()
}
for _, child := range w.children {
child.drawTree(draw)
}
}
2025-02-04 13:31:48 -06:00
func (w *guiWidget) Show() {
if w.isFake {
2025-02-07 00:08:44 -06:00
// don't display fake widgets
2025-02-04 13:31:48 -06:00
return
}
2025-02-06 19:34:26 -06:00
if w.Hidden() {
2025-02-07 00:08:44 -06:00
// recursively checks if the parent is hidden
// never show hidden widgets
2025-02-04 13:31:48 -06:00
return
}
w.drawView()
}