summaryrefslogtreecommitdiff
path: root/grid.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2023-05-09 18:34:09 -0500
committerJeff Carr <[email protected]>2023-05-09 18:34:09 -0500
commitb392c40969e105b00efa262042d647303d6fbc2c (patch)
tree95e25e5e288c096df69c36e2293af5ebc17a1d78 /grid.go
parent706bcef867ff2a26ab62a1e3d668ac441575df62 (diff)
andlabs: now attempt grid placement
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'grid.go')
-rw-r--r--grid.go29
1 files changed, 17 insertions, 12 deletions
diff --git a/grid.go b/grid.go
index b773b8b..67a2924 100644
--- a/grid.go
+++ b/grid.go
@@ -42,23 +42,28 @@ func (n *Node) NewGrid(name string, w int, h int) *Node {
}
// true if the grid already have a child at W,H
-func (n *Node) gridCollision(w int, h int) bool {
+func (n *Node) gridCollision() bool {
for _, child := range n.children {
- if ((child.AtW == w) && (child.AtH == h)) {
+ if ((child.AtW == n.NextW) && (child.AtH == n.NextH)) {
return true
}
}
return false
}
-// increments NextW & NextH
-func (n *Node) gridIncrement(w int, h int) bool {
- for _, child := range n.children {
- if ((child.AtW == w) && (child.AtH == h)) {
- return true
- }
+// keeps incrementing NextW & NextH until there is not a widget
+func (n *Node) gridIncrement() {
+ if ! n.gridCollision() {
+ return
}
- return false
+
+ n.NextH += 1
+ if (n.NextH > n.Y) {
+ n.NextW += 1
+ n.NextH = 1
+ }
+
+ n.gridIncrement()
}
func (n *Node) At(w int, h int) *Node {
@@ -69,9 +74,9 @@ func (n *Node) At(w int, h int) *Node {
n.NextW = w
n.NextH = h
- // TODO: check for a collision here
- if n.gridCollision(w,h) {
- // TODO: find free next w,h
+ n.gridIncrement()
+ if (n.NextW != w) || (n.NextH != h) {
+ log(logError, "At() (W,H)", w, h, " was moved to avoid a collision (W,H) =", n.NextW, n.NextH)
}
return n
}