2022-10-19 13:23:22 -05:00
|
|
|
package gui
|
|
|
|
|
2023-03-01 11:35:36 -06:00
|
|
|
import "git.wit.org/wit/gui/toolkit"
|
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
|
|
|
|
*/
|
2023-03-01 11:35:36 -06:00
|
|
|
func (n *Node) New(title string, t toolkit.WidgetType, custom func()) *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
|
|
|
newN.widget.Type = t
|
2023-03-23 12:35:12 -05:00
|
|
|
// newN.widget.Action = "New"
|
2023-03-01 11:35:36 -06:00
|
|
|
newN.Custom = custom
|
|
|
|
|
|
|
|
// TODO: This should not be defined for each widget. This has to be stupid
|
|
|
|
// or wait a second, is this where I send something to a channel?
|
|
|
|
newN.widget.Custom = func() {
|
2023-03-12 08:47:16 -05:00
|
|
|
log(debugChange, "Trying to find Window Close. widget.Type =", newN.widget.Type)
|
|
|
|
if (newN.widget.Type == toolkit.Window) {
|
|
|
|
log(debugChange, "Need to delete newN here")
|
|
|
|
n.Delete(newN)
|
|
|
|
}
|
2023-03-01 11:35:36 -06:00
|
|
|
if (newN.Custom == nil) {
|
|
|
|
log(debugChange, "newT.Custom() == nil. Not doing anything. SEND SOMETHING TO THE CHANNEL")
|
|
|
|
return
|
|
|
|
}
|
2023-04-03 10:26:47 -05:00
|
|
|
log(debugChange, "newT.Custom() START SEND SOMETHING TO THE CHANNEL node =", newN.Name)
|
2023-03-01 11:35:36 -06:00
|
|
|
// send something to the channel here????
|
|
|
|
newN.Custom()
|
2023-04-03 10:26:47 -05:00
|
|
|
log(debugChange, "newT.Custom() END SEND SOMETHING TO THE CHANNEL node =", newN.Name)
|
2023-03-01 11:35:36 -06:00
|
|
|
}
|
2022-10-19 13:23:22 -05:00
|
|
|
|
|
|
|
n.Append(newN)
|
|
|
|
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)
|
2022-10-19 13:23:22 -05:00
|
|
|
n.Name = title
|
2023-03-30 08:51:33 -05:00
|
|
|
n.Text = title
|
2022-11-06 12:59:24 -06:00
|
|
|
n.id = Config.counter
|
2023-03-29 23:03:04 -05:00
|
|
|
n.widget.Id = n.id
|
2023-03-12 08:47:16 -05:00
|
|
|
log(debugNode, "addNode = widget setid =", n.id)
|
2022-10-19 13:23:22 -05:00
|
|
|
|
2023-03-12 08:47:16 -05:00
|
|
|
Config.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
|
|
|
|
}
|
|
|
|
|
2023-03-29 23:03:04 -05:00
|
|
|
/*
|
2023-03-12 08:47:16 -05:00
|
|
|
func (n *Node) Window() *Node {
|
|
|
|
return n.parent
|
|
|
|
}
|
2023-03-29 23:03:04 -05:00
|
|
|
*/
|
2023-03-12 08:47:16 -05:00
|
|
|
|
|
|
|
func (n *Node) Append(child *Node) {
|
|
|
|
n.children = append(n.children, child)
|
|
|
|
if (debugNode) {
|
|
|
|
log(debugNode, "child node:")
|
2023-03-23 12:35:12 -05:00
|
|
|
child.Dump(debugDump)
|
2023-03-12 08:47:16 -05:00
|
|
|
log(debugNode, "parent node:")
|
2023-03-23 12:35:12 -05:00
|
|
|
n.Dump(debugDump)
|
2023-03-12 08:47:16 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *Node) Delete(d *Node) {
|
|
|
|
for i, child := range n.children {
|
|
|
|
log(debugNode, "\t", i, child.id, child.Width, child.Height, child.Name)
|
|
|
|
if (child.id == d.id) {
|
|
|
|
log(debugNode, "\t\t Deleting this")
|
|
|
|
n.children = append(n.children[:i], n.children[i+1:]...)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log(debugError, "did not find node to delete", d.id, d.Width, d.Height, d.Name)
|
|
|
|
}
|