package gui import ( "go.wit.com/log" "go.wit.com/widget" ) /* generic function to create a new node on the binary tree this is called each time you want a new widget and it initializes basic default values there isn't much to see here. */ func (parent *Node) newNode(s string, t widget.WidgetType) *Node { if parent == nil { log.Log(WARN, "newNode() ERROR got parent == nil") // this is an error internal to this gui package return parent } newN := rawNode(s, t) parent.Append(newN) return newN } // I've been using 'raw' in the code here and there // to indicate a widget that hasn't be placed in the binary tree // there is probably a more approriate name func rawNode(s string, t widget.WidgetType) *Node { var newN *Node newN = addNode() newN.progname = s newN.label = s newN.defaultS = s newN.newString = s newN.currentS = s newN.WidgetType = t newN.strings = make(map[string]int) // set these defaults newN.expand = false newN.pad = true newN.borderless = false // usually this is just used for Window widgets newN.enabled = true newN.changed = true newN.hidden = false // by default, always draw a widget return newN } /* raw create function for a new node struct and increments the counter */ func addNode() *Node { n := new(Node) n.id = me.counter log.Log(NODE, "addNode = widget setid =", n.id) me.counter += 1 return n } func (parent *Node) Append(n *Node) { if n.parent != nil { log.Log(WARN, "Widget already has a parent already assigned") return } // track the parent and this widget as a child parent.children = append(parent.children, n) n.parent = parent // if the parent is a grid, add it to the next cell if parent.WidgetType == widget.Grid { parent.gridIncrement() } n.AtW = parent.NextW n.AtH = parent.NextH // honor the visable settings of the parent n.visable = parent.visable } // returns the parent widget func (n *Node) Parent() *Node { if !n.Ready() { return n } return n.parent } func (n *Node) Delete(d *Node) { if !n.Ready() { return } for i, child := range n.children { log.Log(NODE, "\t", i, child.id, child.progname) if child.id == d.id { log.Log(NODE, "\t\t Deleting this") n.children = append(n.children[:i], n.children[i+1:]...) return } } log.Log(WARN, "did not find node to delete", d.id, d.progname) }