2024-01-18 00:08:37 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-01-28 21:15:15 -06:00
|
|
|
"strconv"
|
|
|
|
|
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)
|
|
|
|
// Set(w, "default")
|
|
|
|
|
2024-01-28 21:15:15 -06:00
|
|
|
w.node = n
|
2024-01-18 00:08:37 -06:00
|
|
|
|
|
|
|
// set the name used by gocui to the id
|
2024-01-28 21:15:15 -06:00
|
|
|
// w.cuiName = string(n.WidgetId)
|
|
|
|
|
|
|
|
w.cuiName = strconv.Itoa(w.node.WidgetId) + " TK"
|
2024-01-18 00:08:37 -06:00
|
|
|
|
2024-01-28 02:20:31 -06:00
|
|
|
w.WidgetType = n.WidgetType
|
2024-01-28 21:15:15 -06:00
|
|
|
|
2024-01-28 03:33:08 -06:00
|
|
|
w.labelN = n.State.Label
|
|
|
|
if w.labelN == "" {
|
|
|
|
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
|
|
|
if w.v != nil {
|
|
|
|
w.v.Visible = false
|
|
|
|
return
|
|
|
|
}
|
|
|
|
// make sure the view isn't really there
|
|
|
|
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-01-28 02:20:31 -06:00
|
|
|
return tk.v.Visible
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *guiWidget) SetVisible(b bool) {
|
|
|
|
if w.v == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
w.v.Visible = b
|
|
|
|
}
|