2022-10-19 13:23:22 -05:00
|
|
|
package gui
|
|
|
|
|
2024-01-03 18:15:54 -06:00
|
|
|
import (
|
|
|
|
"go.wit.com/log"
|
2024-01-05 13:18:44 -06:00
|
|
|
"go.wit.com/gui/widget"
|
2024-01-03 18:15:54 -06:00
|
|
|
)
|
2022-11-13 08:53:03 -06:00
|
|
|
|
2022-10-19 13:23:22 -05:00
|
|
|
/*
|
|
|
|
generic function to create a new node on the binary tree
|
|
|
|
*/
|
2024-01-05 13:18:44 -06:00
|
|
|
func (n *Node) newNode(title string, t widget.WidgetType) *Node {
|
2022-10-19 13:23:22 -05:00
|
|
|
var newN *Node
|
|
|
|
|
2023-03-01 11:35:36 -06:00
|
|
|
newN = addNode(title)
|
2023-03-29 23:03:04 -05:00
|
|
|
newN.WidgetType = t
|
2023-03-01 11:35:36 -06:00
|
|
|
|
2024-01-05 13:18:44 -06:00
|
|
|
if n.WidgetType == widget.Grid {
|
2023-05-09 18:34:09 -05:00
|
|
|
n.gridIncrement()
|
|
|
|
}
|
|
|
|
newN.AtW = n.NextW
|
|
|
|
newN.AtH = n.NextH
|
2024-01-06 13:53:15 -06:00
|
|
|
newN.hidden = n.hidden // by default, use the value from above
|
2023-05-09 18:34:09 -05:00
|
|
|
|
2023-04-28 10:30:27 -05:00
|
|
|
n.children = append(n.children, newN)
|
2022-10-19 13:23:22 -05:00
|
|
|
newN.parent = n
|
|
|
|
return newN
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
raw create function for a new node struct
|
|
|
|
*/
|
2023-03-01 11:35:36 -06:00
|
|
|
func addNode(title string) *Node {
|
2023-02-25 14:05:25 -06:00
|
|
|
n := new(Node)
|
2024-01-11 19:32:40 -06:00
|
|
|
n.label = title
|
2023-04-28 10:35:57 -05:00
|
|
|
n.id = me.counter
|
2024-01-03 18:15:54 -06:00
|
|
|
log.Log(NODE, "addNode = widget setid =", n.id)
|
2022-10-19 13:23:22 -05:00
|
|
|
|
2023-04-28 10:35:57 -05:00
|
|
|
me.counter += 1
|
2023-02-25 14:05:25 -06:00
|
|
|
return n
|
2022-10-19 13:23:22 -05:00
|
|
|
}
|
2023-03-12 08:47:16 -05:00
|
|
|
|
|
|
|
func (n *Node) Parent() *Node {
|
|
|
|
return n.parent
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *Node) Delete(d *Node) {
|
|
|
|
for i, child := range n.children {
|
2024-01-11 19:32:40 -06:00
|
|
|
log.Log(NODE, "\t", i, child.id, child.progname)
|
2023-03-12 08:47:16 -05:00
|
|
|
if (child.id == d.id) {
|
2024-01-03 18:15:54 -06:00
|
|
|
log.Log(NODE, "\t\t Deleting this")
|
2023-03-12 08:47:16 -05:00
|
|
|
n.children = append(n.children[:i], n.children[i+1:]...)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2024-01-11 19:32:40 -06:00
|
|
|
log.Warn("did not find node to delete", d.id, d.progname)
|
2023-03-12 08:47:16 -05:00
|
|
|
}
|