2024-01-18 00:08:37 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"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")
|
|
|
|
|
|
|
|
w.frame = true
|
|
|
|
|
|
|
|
// set the name used by gocui to the id
|
|
|
|
w.cuiName = string(n.WidgetId)
|
|
|
|
|
2024-01-28 02:20:31 -06:00
|
|
|
w.node = n
|
|
|
|
w.WidgetType = n.WidgetType
|
|
|
|
|
2024-01-18 00:08:37 -06:00
|
|
|
if n.WidgetType == widget.Root {
|
|
|
|
log.Log(INFO, "setupWidget() FOUND ROOT w.id =", n.WidgetId)
|
2024-01-28 02:20:31 -06:00
|
|
|
// me.treeRoot = n
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
/*
|
2024-01-18 00:08:37 -06:00
|
|
|
// searches the binary tree for a WidgetId
|
2024-01-28 02:20:31 -06:00
|
|
|
func findWidgetName(n *tree.Node, name string) *node {
|
2024-01-18 00:08:37 -06:00
|
|
|
if n == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if n.tk.cuiName == name {
|
|
|
|
return n
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, child := range n.children {
|
|
|
|
newN := child.findWidgetName(name)
|
|
|
|
if newN != nil {
|
|
|
|
return newN
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2024-01-28 02:20:31 -06:00
|
|
|
*/
|
2024-01-18 00:08:37 -06:00
|
|
|
|
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 {
|
|
|
|
return tk.progname
|
|
|
|
}
|
|
|
|
|
|
|
|
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 Visible(n *tree.Node) bool {
|
|
|
|
if n == nil {
|
2024-01-18 00:08:37 -06:00
|
|
|
return false
|
|
|
|
}
|
2024-01-28 02:20:31 -06:00
|
|
|
if n.TK == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
var w *guiWidget
|
|
|
|
w = n.TK.(*guiWidget)
|
|
|
|
return w.Visible()
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
|
|
|
|
2024-01-28 02:20:31 -06:00
|
|
|
func (w *guiWidget) SetVisible(b bool) {
|
|
|
|
if w.v == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
w.v.Visible = b
|
|
|
|
}
|
|
|
|
|
|
|
|
func SetVisible(n *tree.Node, b bool) {
|
2024-01-18 00:08:37 -06:00
|
|
|
if n == nil {
|
|
|
|
return
|
|
|
|
}
|
2024-01-28 02:20:31 -06:00
|
|
|
if n.TK == nil {
|
2024-01-18 00:08:37 -06:00
|
|
|
return
|
|
|
|
}
|
2024-01-28 02:20:31 -06:00
|
|
|
var w *guiWidget
|
|
|
|
w = n.TK.(*guiWidget)
|
|
|
|
if w.v == nil {
|
2024-01-18 00:08:37 -06:00
|
|
|
return
|
|
|
|
}
|
2024-01-28 02:20:31 -06:00
|
|
|
w.v.Visible = b
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
|
|
|
|
2024-01-28 02:20:31 -06:00
|
|
|
func addDropdown() *tree.Node {
|
|
|
|
n := new(tree.Node)
|
2024-01-18 00:08:37 -06:00
|
|
|
n.WidgetType = widget.Flag
|
|
|
|
n.WidgetId = -2
|
|
|
|
n.ParentId = 0
|
|
|
|
|
|
|
|
// store the internal toolkit information
|
2024-01-28 02:20:31 -06:00
|
|
|
tk := new(guiWidget)
|
|
|
|
tk.frame = true
|
|
|
|
tk.label = "DropBox text"
|
|
|
|
|
|
|
|
// copy the data from the action message
|
|
|
|
tk.progname = "DropBox"
|
2024-01-18 00:08:37 -06:00
|
|
|
|
|
|
|
// set the name used by gocui to the id
|
2024-01-28 02:20:31 -06:00
|
|
|
tk.cuiName = "-1 dropbox"
|
2024-01-18 00:08:37 -06:00
|
|
|
|
2024-01-28 02:20:31 -06:00
|
|
|
tk.color = &colorFlag
|
2024-01-18 00:08:37 -06:00
|
|
|
|
|
|
|
// add this new widget on the binary tree
|
2024-01-28 02:20:31 -06:00
|
|
|
tk.parent = me.treeRoot.TK.(*guiWidget)
|
|
|
|
if tk.parent != nil {
|
|
|
|
tk.parent.children = append(tk.parent.children, tk)
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
2024-01-28 02:20:31 -06:00
|
|
|
|
|
|
|
n.TK = tk
|
2024-01-18 00:08:37 -06:00
|
|
|
return n
|
|
|
|
}
|