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