2024-01-18 00:08:37 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-01-28 21:15:15 -06:00
|
|
|
"strconv"
|
|
|
|
|
2024-02-02 14:49:17 -06:00
|
|
|
"github.com/awesome-gocui/gocui"
|
2024-01-18 00:08:37 -06:00
|
|
|
"go.wit.com/log"
|
2024-01-28 02:20:31 -06:00
|
|
|
"go.wit.com/toolkits/tree"
|
2024-01-18 04:10:08 -06:00
|
|
|
"go.wit.com/widget"
|
2024-01-18 00:08:37 -06:00
|
|
|
)
|
|
|
|
|
2024-01-28 02:20:31 -06:00
|
|
|
func initWidget(n *tree.Node) *guiWidget {
|
2024-01-18 00:08:37 -06:00
|
|
|
var w *guiWidget
|
|
|
|
w = new(guiWidget)
|
|
|
|
|
2024-01-28 21:15:15 -06:00
|
|
|
w.node = n
|
|
|
|
w.cuiName = strconv.Itoa(w.node.WidgetId) + " TK"
|
2024-01-28 02:20:31 -06:00
|
|
|
w.WidgetType = n.WidgetType
|
2024-01-28 03:33:08 -06:00
|
|
|
w.labelN = n.State.Label
|
|
|
|
if w.labelN == "" {
|
2024-02-02 14:49:17 -06:00
|
|
|
// remove this debugging hack once things are stable and fixed
|
2024-01-28 03:33:08 -06:00
|
|
|
w.labelN = n.GetProgName()
|
|
|
|
}
|
2024-01-28 21:15:15 -06:00
|
|
|
w.frame = true
|
2024-01-30 02:38:06 -06:00
|
|
|
w.hidden = n.State.Hidden
|
|
|
|
w.enable = n.State.Enable
|
2024-01-28 02:20:31 -06:00
|
|
|
|
2024-01-18 00:08:37 -06:00
|
|
|
if n.WidgetType == widget.Root {
|
|
|
|
log.Log(INFO, "setupWidget() FOUND ROOT w.id =", n.WidgetId)
|
|
|
|
}
|
|
|
|
|
|
|
|
if n.WidgetType == widget.Grid {
|
|
|
|
w.widths = make(map[int]int) // how tall each row in the grid is
|
|
|
|
w.heights = make(map[int]int) // how wide each column in the grid is
|
|
|
|
}
|
|
|
|
|
2024-01-28 02:44:59 -06:00
|
|
|
p := n.Parent
|
|
|
|
if p == nil {
|
|
|
|
log.Log(ERROR, "parent == nil", w.String(), n.WidgetId, w.WidgetType)
|
|
|
|
return w
|
|
|
|
}
|
|
|
|
if p.TK == nil {
|
|
|
|
log.Log(ERROR, "parent.TK == nil", w.String(), n.WidgetId, w.WidgetType)
|
|
|
|
return w
|
|
|
|
}
|
|
|
|
|
|
|
|
// set the parent and append to parent children
|
|
|
|
var ptk *guiWidget
|
|
|
|
ptk = p.TK.(*guiWidget)
|
|
|
|
w.parent = ptk
|
|
|
|
ptk.children = append(ptk.children, w)
|
2024-01-18 00:08:37 -06:00
|
|
|
return w
|
|
|
|
}
|
|
|
|
|
|
|
|
func setupCtrlDownWidget() {
|
|
|
|
a := new(widget.Action)
|
|
|
|
a.ProgName = "ctrlDown"
|
|
|
|
a.WidgetType = widget.Dialog
|
|
|
|
a.WidgetId = -1
|
|
|
|
a.ParentId = 0
|
2024-01-28 02:20:31 -06:00
|
|
|
// n := addNode(a)
|
|
|
|
n := me.myTree.AddNode(a)
|
2024-01-18 00:08:37 -06:00
|
|
|
|
|
|
|
me.ctrlDown = n
|
|
|
|
}
|
|
|
|
|
2024-01-28 02:20:31 -06:00
|
|
|
func (w *guiWidget) deleteView() {
|
2024-01-18 00:08:37 -06:00
|
|
|
// make sure the view isn't really there
|
2024-02-02 11:47:32 -06:00
|
|
|
log.Log(NOW, "deleteView()", w.cuiName, w.WidgetType, w.node.WidgetId)
|
2024-01-18 00:08:37 -06:00
|
|
|
me.baseGui.DeleteView(w.cuiName)
|
|
|
|
w.v = nil
|
|
|
|
}
|
|
|
|
|
2024-01-28 02:20:31 -06:00
|
|
|
func (w *guiWidget) IsCurrent() bool {
|
|
|
|
if w.node.WidgetType == widget.Tab {
|
2024-01-18 00:08:37 -06:00
|
|
|
return w.isCurrent
|
|
|
|
}
|
2024-01-28 02:20:31 -06:00
|
|
|
if w.node.WidgetType == widget.Window {
|
2024-02-05 02:22:58 -06:00
|
|
|
log.Log(NOW, "IsCurrent() found current window", w.cuiName, w.String())
|
|
|
|
log.Log(NOW, "IsCurrent() window w.isCurrent =", w.isCurrent)
|
2024-01-18 00:08:37 -06:00
|
|
|
return w.isCurrent
|
|
|
|
}
|
2024-01-28 02:20:31 -06:00
|
|
|
if w.node.WidgetType == widget.Root {
|
2024-01-18 00:08:37 -06:00
|
|
|
return false
|
|
|
|
}
|
2024-01-28 02:20:31 -06:00
|
|
|
return w.parent.IsCurrent()
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
|
|
|
|
2024-01-28 02:20:31 -06:00
|
|
|
func (tk *guiWidget) String() string {
|
2024-01-28 03:33:08 -06:00
|
|
|
return tk.node.String()
|
2024-01-28 02:20:31 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func (tk *guiWidget) Visible() bool {
|
|
|
|
if tk == nil {
|
2024-01-18 00:08:37 -06:00
|
|
|
return false
|
|
|
|
}
|
2024-01-28 02:20:31 -06:00
|
|
|
if tk.v == nil {
|
2024-01-18 00:08:37 -06:00
|
|
|
return false
|
|
|
|
}
|
2024-02-02 11:47:32 -06:00
|
|
|
tk.v.Visible = true
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2024-02-05 03:05:37 -06:00
|
|
|
func (w *guiWidget) Show() {
|
2024-02-05 02:22:58 -06:00
|
|
|
// always should the dropdown widget
|
2024-02-05 03:09:41 -06:00
|
|
|
if w == me.dropdownV {
|
2024-02-05 03:19:08 -06:00
|
|
|
me.dropdownV.drawView()
|
2024-02-05 02:22:58 -06:00
|
|
|
return
|
|
|
|
}
|
2024-02-05 03:05:37 -06:00
|
|
|
|
|
|
|
// don't display fake widgets
|
|
|
|
if w.isFake {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-02-05 02:22:58 -06:00
|
|
|
// if this isn't in the binary tree
|
|
|
|
// it's some internal widget so always display those
|
2024-02-05 03:05:37 -06:00
|
|
|
if w.node == nil {
|
2024-02-05 03:19:08 -06:00
|
|
|
w.drawView()
|
2024-02-05 03:05:37 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// always show window titles
|
|
|
|
if w.node.WidgetType != widget.Window {
|
2024-02-05 03:19:08 -06:00
|
|
|
w.drawView()
|
2024-02-05 02:22:58 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// if the widget is not in the current displayed windo
|
|
|
|
// then ignore it
|
2024-02-05 03:05:37 -06:00
|
|
|
log.Log(NOW, "Show() widget =", w.cuiName, w.String())
|
|
|
|
log.Log(NOW, "Show() w.IsCurrent() returned", w.IsCurrent())
|
2024-02-05 03:09:41 -06:00
|
|
|
if !w.IsCurrent() {
|
2024-02-05 03:05:37 -06:00
|
|
|
log.Log(NOW, "Show() NOT drawing", w.cuiName, w.String())
|
2024-02-05 02:22:58 -06:00
|
|
|
return
|
|
|
|
}
|
2024-02-05 03:05:37 -06:00
|
|
|
log.Log(NOW, "Show() drawing", w.cuiName, w.String())
|
2024-02-05 02:22:58 -06:00
|
|
|
|
|
|
|
// finally, check if the widget State is hidden or not
|
2024-02-05 03:05:37 -06:00
|
|
|
if w.node.State.Hidden {
|
2024-02-05 02:22:58 -06:00
|
|
|
// don't display hidden widgets
|
2024-02-05 03:05:37 -06:00
|
|
|
return
|
2024-02-05 01:08:12 -06:00
|
|
|
}
|
2024-02-05 03:05:37 -06:00
|
|
|
|
|
|
|
// okay, if you made it this far, then display the widget
|
2024-02-05 03:19:08 -06:00
|
|
|
w.drawView()
|
2024-02-02 11:47:32 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func (tk *guiWidget) Hide() {
|
|
|
|
tk.deleteView()
|
2024-01-28 02:20:31 -06:00
|
|
|
}
|
|
|
|
|
2024-02-02 11:47:32 -06:00
|
|
|
func (tk *guiWidget) SetVisible(b bool) {
|
|
|
|
if b {
|
|
|
|
tk.Show()
|
|
|
|
} else {
|
|
|
|
tk.Hide()
|
2024-01-28 02:20:31 -06:00
|
|
|
}
|
2024-02-02 14:49:17 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func (tk *guiWidget) findWidgetByName(name string) *guiWidget {
|
|
|
|
if tk.cuiName == name {
|
|
|
|
return tk
|
|
|
|
}
|
|
|
|
for _, child := range tk.children {
|
|
|
|
found := child.findWidgetByName(name)
|
|
|
|
if found != nil {
|
|
|
|
return found
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (tk *guiWidget) findWidgetByView(v *gocui.View) *guiWidget {
|
|
|
|
if tk.v == v {
|
|
|
|
return tk
|
|
|
|
}
|
|
|
|
if tk.cuiName == v.Name() {
|
|
|
|
log.Log(NOW, "findWidget() error. names are mismatched or out of sync", tk.cuiName)
|
|
|
|
log.Log(NOW, "findWidget() or maybe the view has been deleted")
|
|
|
|
// return tk
|
|
|
|
}
|
|
|
|
for _, child := range tk.children {
|
|
|
|
found := child.findWidgetByView(v)
|
|
|
|
if found != nil {
|
|
|
|
return found
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
2024-01-28 02:20:31 -06:00
|
|
|
}
|