start correctly handling grid placement
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
579d75d856
commit
d861dade77
|
@ -164,7 +164,7 @@ This goroutine can be used like a watchdog timer
|
|||
|
||||
This struct can be used with the go-arg package
|
||||
|
||||
### type [Node](/structs.go#L55)
|
||||
### type [Node](/structs.go#L57)
|
||||
|
||||
`type Node struct { ... }`
|
||||
|
||||
|
|
13
common.go
13
common.go
|
@ -67,15 +67,10 @@ func (n *Node) SetText(text string) *Node{
|
|||
return n
|
||||
}
|
||||
|
||||
func (n *Node) SetNext(x int, y int) {
|
||||
n.NextX = x
|
||||
n.NextY = y
|
||||
log(debugError, "SetNext() x,y =", n.NextX, n.NextY)
|
||||
log(debugError, "SetNext() x,y =", n.NextX, n.NextY)
|
||||
log(debugError, "SetNext() x,y =", n.NextX, n.NextY)
|
||||
log(debugError, "SetNext() x,y =", n.NextX, n.NextY)
|
||||
log(debugError, "SetNext() x,y =", n.NextX, n.NextY)
|
||||
log(debugError, "SetNext() x,y =", n.NextX, n.NextY)
|
||||
func (n *Node) SetNext(w int, h int) {
|
||||
n.NextW = w
|
||||
n.NextH = h
|
||||
log(debugNow, "SetNext() w,h =", n.NextW, n.NextH)
|
||||
}
|
||||
|
||||
func (n *Node) Set(val any) {
|
||||
|
|
2
debug.go
2
debug.go
|
@ -103,7 +103,7 @@ func (n *Node) Dump() {
|
|||
Indent(b, "id = ", n.id)
|
||||
Indent(b, "Name = ", n.Name)
|
||||
Indent(b, "(X,Y) = ", n.X, n.Y)
|
||||
Indent(b, "Next (X,Y) = ", n.NextX, n.NextY)
|
||||
Indent(b, "Next (W,H) = ", n.NextW, n.NextH)
|
||||
|
||||
if (n.parent == nil) {
|
||||
Indent(b, "parent = nil")
|
||||
|
|
|
@ -250,7 +250,7 @@ func (n *Node) debugAddWidgetButton() {
|
|||
newB := activeLabelNewB.B
|
||||
|
||||
if (newY == -1) {
|
||||
name = name + " (" + strconv.Itoa(activeWidget.NextX) + "," + strconv.Itoa(activeWidget.NextY) + ")"
|
||||
name = name + " (" + strconv.Itoa(activeWidget.NextW) + "," + strconv.Itoa(activeWidget.NextH) + ")"
|
||||
} else {
|
||||
activeWidget.SetNext(newX, newY)
|
||||
name = name + " (" + strconv.Itoa(newX) + "," + strconv.Itoa(newY) + ")"
|
||||
|
@ -259,9 +259,9 @@ func (n *Node) debugAddWidgetButton() {
|
|||
log("New Type =", activeLabelNewType.S)
|
||||
log("New X =", newX)
|
||||
log("New Y =", newY)
|
||||
log("activeWidget.NextX =", activeWidget.NextX)
|
||||
log("activeWidget.NextY =", activeWidget.NextY)
|
||||
log(debugNow, "Add() size (X,Y)", activeWidget.X, activeWidget.Y, "put next thing at (X,Y) =", activeWidget.NextX, activeWidget.NextY)
|
||||
log("activeWidget.NextW =", activeWidget.NextW)
|
||||
log("activeWidget.NextH =", activeWidget.NextH)
|
||||
log(debugNow, "Add() size (X,Y)", activeWidget.X, activeWidget.Y, "put next thing at (W,H) =", activeWidget.NextW, activeWidget.NextH)
|
||||
activeWidget.Dump()
|
||||
|
||||
// activeWidget.X = newX
|
||||
|
|
57
grid.go
57
grid.go
|
@ -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
|
||||
func placeGrid(a *toolkit.Action, n *Node, where *Node) {
|
||||
where.NextY += 1
|
||||
if (where.NextY > where.Y) {
|
||||
where.NextX += 1
|
||||
where.NextY = 1
|
||||
// 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
|
||||
}
|
||||
|
||||
a.X = where.NextX
|
||||
a.Y = where.NextY
|
||||
log(logNow, "placeGrid() (X,Y)", where.X, where.Y, " next(X,Y) =", where.NextX, where.NextY)
|
||||
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.NextH += 1
|
||||
if (where.NextH > where.Y) {
|
||||
where.NextW += 1
|
||||
where.NextH = 1
|
||||
}
|
||||
|
||||
a.X = where.NextW
|
||||
a.Y = where.NextH
|
||||
log(logNow, "placeGrid() (X,Y)", where.X, where.Y, " next(X,Y) =", where.NextW, where.NextH)
|
||||
}
|
||||
|
|
12
structs.go
12
structs.go
|
@ -31,6 +31,8 @@ type GuiArgs struct {
|
|||
}
|
||||
|
||||
type guiConfig struct {
|
||||
initOnce sync.Once
|
||||
|
||||
// This is the master node. The Binary Tree starts here
|
||||
rootNode *Node
|
||||
|
||||
|
@ -54,7 +56,6 @@ type guiConfig struct {
|
|||
// simply the name and the size of whatever GUI element exists
|
||||
type Node struct {
|
||||
id int
|
||||
initOnce sync.Once
|
||||
|
||||
WidgetType toolkit.WidgetType
|
||||
|
||||
|
@ -69,9 +70,12 @@ type Node struct {
|
|||
X int
|
||||
Y int
|
||||
|
||||
// used for grids and tables
|
||||
NextX int
|
||||
NextY int
|
||||
// the position of the widget in a grid
|
||||
AtW int
|
||||
AtH int
|
||||
// where the next widget should be put in a grid
|
||||
NextW int
|
||||
NextH int
|
||||
|
||||
// used for values
|
||||
I int
|
||||
|
|
Loading…
Reference in New Issue