summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-09-03 12:10:03 -0400
committerPietro Gagliardi <[email protected]>2014-09-03 12:10:03 -0400
commit73a7fe6c1dfaaa34fdac21db50058bdcb8d4c055 (patch)
treef40c528865e36893902fde52d5ee260fe6cc87e5
parentb1bac2e61bfb57a00497c5651dc73d6e303afc9b (diff)
Restructured the Grid allocation algorithm to split position/size assignment and neighbor assignment. This will make xspan/yspan much easier.
-rw-r--r--grid.go37
1 files changed, 23 insertions, 14 deletions
diff --git a/grid.go b/grid.go
index 7aa6c6b..d2abdca 100644
--- a/grid.go
+++ b/grid.go
@@ -74,6 +74,7 @@ type gridCell struct {
width int
height int
visited bool
+ allocations []*allocation
}
// NewGrid creates a new Grid with no Controls.
@@ -281,30 +282,38 @@ func (g *grid) allocate(x int, y int, width int, height int, d *sizing) (allocat
}
}
- // 5) draw
+ // 5) position everything
+ for c, cell := range g.controls {
+ cx := x
+ cy := y
+ for i := 0; i < cell.gridx; i++ {
+ cx += colwidths[i] + d.xpadding
+ }
+ for i := 0; i < cell.gridy; i++ {
+ cy += rowheights[i] + d.ypadding
+ }
+ cell.allocations = c.allocate(cx + cell.xoff, cy + cell.yoff, cell.width, cell.height, d)
+ }
+
+ // 6) handle neighbors and build final allocation array
var current *allocation
- startx := x
- for row, xcol := range g.grid {
+ for _, xcol := range g.grid {
current = nil
- for col, c := range xcol {
- if c != nil { // treat empty cells like spaces
+ for _, c := range xcol {
+ if c != nil { // treat empty cells like spaces
cell := g.controls[c]
- as := c.allocate(x + cell.xoff, y + cell.yoff, cell.width, cell.height, d)
- if current != nil { // connect first left to first right
+ if current != nil { // connect first left to first right
current.neighbor = c
}
- if len(as) != 0 {
- current = as[0] // next left is first subwidget
+ if len(cell.allocations) != 0 {
+ current = cell.allocations[0] // next left is first subwidget
} else {
- current = nil // spaces don't have allocation data
+ current = nil // spaces don't have allocation data
}
- allocations = append(allocations, as...)
+ allocations = append(allocations, cell.allocations...)
}
- x += colwidths[col] + d.xpadding
}
- x = startx
- y += rowheights[row] + d.ypadding
}
return allocations