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-02-02 11:47:32 -06:00
|
|
|
/*
|
|
|
|
if w.v != nil {
|
|
|
|
w.v.Visible = false
|
|
|
|
return
|
|
|
|
}
|
|
|
|
*/
|
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-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
|
|
|
|
}
|
|
|
|
|
|
|
|
func (tk *guiWidget) Show() {
|
|
|
|
tk.showView()
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|