gocui/widget.go

115 lines
2.1 KiB
Go

package main
import (
"strconv"
"go.wit.com/log"
"go.wit.com/toolkits/tree"
"go.wit.com/widget"
)
func initWidget(n *tree.Node) *guiWidget {
var w *guiWidget
w = new(guiWidget)
// Set(w, "default")
w.node = n
// set the name used by gocui to the id
// w.cuiName = string(n.WidgetId)
w.cuiName = strconv.Itoa(w.node.WidgetId) + " TK"
w.WidgetType = n.WidgetType
w.labelN = n.State.Label
if w.labelN == "" {
w.labelN = n.GetProgName()
}
w.frame = true
w.hidden = n.State.Hidden
w.enable = n.State.Enable
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
}
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)
return w
}
func setupCtrlDownWidget() {
a := new(widget.Action)
a.ProgName = "ctrlDown"
a.WidgetType = widget.Dialog
a.WidgetId = -1
a.ParentId = 0
// n := addNode(a)
n := me.myTree.AddNode(a)
me.ctrlDown = n
}
func (w *guiWidget) deleteView() {
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
}
func (w *guiWidget) IsCurrent() bool {
if w.node.WidgetType == widget.Tab {
return w.isCurrent
}
if w.node.WidgetType == widget.Window {
return w.isCurrent
}
if w.node.WidgetType == widget.Root {
return false
}
return w.parent.IsCurrent()
}
func (tk *guiWidget) String() string {
return tk.node.String()
}
func (tk *guiWidget) Visible() bool {
if tk == nil {
return false
}
if tk.v == nil {
return false
}
return tk.v.Visible
}
func (w *guiWidget) SetVisible(b bool) {
if w.v == nil {
return
}
w.v.Visible = b
}