summaryrefslogtreecommitdiff
path: root/grid.go
blob: c2daaa550ccbf0656d23cf1f08a81757158ced58 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package gui

import (
	"git.wit.org/wit/gui/toolkit"
)

// Grid numbering examples (H) or (W,H)
// -----------------------
// -- (1) -- (2) -- (3) -- (X)
// -----------------------
//
//    (Y)
// ---------
// -- (1) --
// -- (2) --
// ---------
//
//    (X,Y)
// -----------------------------
// -- (1,1) -- (2,1) -- (3,1) --
// -- (1,2) -- (2,2) -- (3,2) --
// -- (1,3) --       -- (3,3) --
// -----------------------------

func (n *Node) NewGrid(name string, w int, h int) *Node {
	newNode := n.newNode(name, toolkit.Grid, func() {
		log(debugChange, "click() NewGrid not defined =", name)
	})

	a := newAction(n, toolkit.Add)

	a.X = w
	a.Y = h
	newNode.X = w
	newNode.Y = h
	newNode.NextX = 1
	newNode.NextY = 1

	sendAction(a, newNode, n)

	return newNode
}

// increments where the next element in the grid should go
func placeGrid(a *toolkit.Action, n *Node, where *Node) {
	where.NextY += 1
	if (where.NextY > where.Y) {
		where.NextX += 1
		where.NextY = 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)
}