diff options
| author | Jeff Carr <[email protected]> | 2024-02-19 14:41:32 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-02-19 14:41:32 -0600 |
| commit | 10eb3685d71a8b4f74a6b3430ef54d56d9aa625d (patch) | |
| tree | a76b5908c74863be81d0178ae6efeb26dd90f0f6 /node.go | |
| parent | 337a55eaac4ffc516c26286b04b039533adb157d (diff) | |
try out a "Mirror" concept for widgets
Diffstat (limited to 'node.go')
| -rw-r--r-- | node.go | 48 |
1 files changed, 33 insertions, 15 deletions
@@ -13,12 +13,21 @@ and it initializes basic default values there isn't much to see here. */ -func (n *Node) newNode(s string, t widget.WidgetType) *Node { - if n == nil { +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 n + 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() @@ -37,19 +46,7 @@ func (n *Node) newNode(s string, t widget.WidgetType) *Node { newN.borderless = false // usually this is just used for Window widgets newN.enabled = true newN.changed = true - - if n.WidgetType == widget.Grid { - n.gridIncrement() - } - newN.AtW = n.NextW - newN.AtH = n.NextH - - // honor the visable settings of the parent - newN.visable = n.visable newN.hidden = false // by default, always draw a widget - - n.children = append(n.children, newN) - newN.parent = n return newN } @@ -65,6 +62,27 @@ func addNode() *Node { 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 |
