andlabs: now attempt grid placement
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
d861dade77
commit
75954affce
29
grid.go
29
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
|
||||
}
|
||||
|
|
6
node.go
6
node.go
|
@ -12,6 +12,12 @@ func (n *Node) newNode(title string, t toolkit.WidgetType, custom func()) *Node
|
|||
newN.WidgetType = t
|
||||
newN.Custom = custom
|
||||
|
||||
if n.WidgetType == toolkit.Grid {
|
||||
n.gridIncrement()
|
||||
}
|
||||
newN.AtW = n.NextW
|
||||
newN.AtH = n.NextH
|
||||
|
||||
n.children = append(n.children, newN)
|
||||
newN.parent = n
|
||||
return newN
|
||||
|
|
|
@ -212,6 +212,9 @@ func newAction(n *Node, atype toolkit.ActionType) *toolkit.Action {
|
|||
a.Name = n.Name
|
||||
a.Text = n.Text
|
||||
a.WidgetId = n.id
|
||||
if (n.parent != nil) {
|
||||
a.ParentId = n.parent.id
|
||||
}
|
||||
a.WidgetType = n.WidgetType
|
||||
|
||||
return &a
|
||||
|
@ -233,7 +236,7 @@ func newaction(a *toolkit.Action, n *Node, where *Node) {
|
|||
if (where != nil) {
|
||||
a.ParentId = where.id
|
||||
if (where.WidgetType == toolkit.Grid) {
|
||||
placeGrid(a, n, where)
|
||||
n.gridIncrement()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
4
tab.go
4
tab.go
|
@ -22,8 +22,8 @@ func (n *Node) NewTab(text string) *Node {
|
|||
log(logError, "NewTab() parent =", n.parent)
|
||||
if (n.parent.WidgetType == toolkit.Root) {
|
||||
// also broken
|
||||
log(logError, "NewTab() TODO: make a window here", n)
|
||||
panic("NewTab did not get passed a window")
|
||||
log(logError, "NewTab() TODO: make or find a window here", n)
|
||||
panic("NewTab() did not get passed a window")
|
||||
}
|
||||
// go up the binary tree until we find a window widget to add a tab too
|
||||
return n.parent.NewTab(text)
|
||||
|
|
|
@ -38,6 +38,10 @@ type Action struct {
|
|||
X int
|
||||
Y int
|
||||
|
||||
// This is used for the widget's grid position
|
||||
W int
|
||||
H int
|
||||
|
||||
// Put space around elements to improve look & feel
|
||||
Margin bool
|
||||
|
||||
|
|
Loading…
Reference in New Issue