diff options
| author | Jeff Carr <[email protected]> | 2023-05-09 17:48:21 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2023-05-09 17:48:21 -0500 |
| commit | 706bcef867ff2a26ab62a1e3d668ac441575df62 (patch) | |
| tree | f9655cbf3596de25d7f857a38e983634f2474a4b /grid.go | |
| parent | e45e4212da86283e2f9592f11c08d798dfd39860 (diff) | |
start correctly handling grid placement
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'grid.go')
| -rw-r--r-- | grid.go | 55 |
1 files changed, 45 insertions, 10 deletions
@@ -33,23 +33,58 @@ func (n *Node) NewGrid(name string, w int, h int) *Node { a.Y = h newNode.X = w newNode.Y = h - newNode.NextX = 1 - newNode.NextY = 1 + newNode.NextW = 1 + newNode.NextH = 1 sendAction(a, newNode, n) return newNode } -// increments where the next element in the grid should go +// true if the grid already have a child at W,H +func (n *Node) gridCollision(w int, h int) bool { + for _, child := range n.children { + if ((child.AtW == w) && (child.AtH == h)) { + 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 + } + } + return false +} + +func (n *Node) At(w int, h int) *Node { + if (n == nil) { + return n + } + + n.NextW = w + n.NextH = h + + // TODO: check for a collision here + if n.gridCollision(w,h) { + // TODO: find free next w,h + } + return n +} + +// finds the next place on the grid to place the new node 'n' func placeGrid(a *toolkit.Action, n *Node, where *Node) { - where.NextY += 1 - if (where.NextY > where.Y) { - where.NextX += 1 - where.NextY = 1 + where.NextH += 1 + if (where.NextH > where.Y) { + where.NextW += 1 + where.NextH = 1 } - a.X = where.NextX - a.Y = where.NextY - log(logNow, "placeGrid() (X,Y)", where.X, where.Y, " next(X,Y) =", where.NextX, where.NextY) + a.X = where.NextW + a.Y = where.NextH + log(logNow, "placeGrid() (X,Y)", where.X, where.Y, " next(X,Y) =", where.NextW, where.NextH) } |
