summaryrefslogtreecommitdiff
path: root/grid.go
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-06-25 11:58:13 -0400
committerPietro Gagliardi <[email protected]>2014-06-25 11:58:13 -0400
commit39f0c352fbeeb4119aedeee1a5974f4d411339c8 (patch)
tree4d9362dd1313c5b3dd5cd1e417e8a332b057cf83 /grid.go
parent55c636b1e3823ec73a9b10d78a03528a54e63bb1 (diff)
Added the necessary work to make new regular Labels work on the other platforms.
Diffstat (limited to 'grid.go')
-rw-r--r--grid.go19
1 files changed, 13 insertions, 6 deletions
diff --git a/grid.go b/grid.go
index ca2d5b9..087b333 100644
--- a/grid.go
+++ b/grid.go
@@ -21,7 +21,7 @@ type Grid struct {
controls [][]Control
filling [][]bool
stretchyrow, stretchycol int
- widths, heights [][]int // caches to avoid reallocating each time
+ widths, heights, yoff [][]int // caches to avoid reallocating each time
rowheights, colwidths []int
}
@@ -42,12 +42,14 @@ func NewGrid(nPerRow int, controls ...Control) *Grid {
cf := make([][]bool, nRows)
cw := make([][]int, nRows)
ch := make([][]int, nRows)
+ cyoff := make([][]int, nRows)
i := 0
for row := 0; row < nRows; row++ {
cc[row] = make([]Control, nPerRow)
cf[row] = make([]bool, nPerRow)
cw[row] = make([]int, nPerRow)
ch[row] = make([]int, nPerRow)
+ cyoff[row] = make([]int, nPerRow)
for x := 0; x < nPerRow; x++ {
cc[row][x] = controls[i]
i++
@@ -60,6 +62,7 @@ func NewGrid(nPerRow int, controls ...Control) *Grid {
stretchycol: -1,
widths: cw,
heights: ch,
+ yoff: cyoff,
rowheights: make([]int, nRows),
colwidths: make([]int, nPerRow),
}
@@ -142,11 +145,12 @@ func (g *Grid) setRect(x int, y int, width int, height int, rr *[]resizerequest)
// 2) get preferred sizes; compute row/column sizes
for row, xcol := range g.controls {
for col, c := range xcol {
- w, h := c.preferredSize()
+ w, h, yoff := c.preferredSize()
g.widths[row][col] = w
g.heights[row][col] = h
g.rowheights[row] = max(g.rowheights[row], h)
g.colwidths[col] = max(g.colwidths[col], w)
+ g.yoff[row][col] = yoff
}
}
// 3) handle the stretchy control
@@ -174,7 +178,7 @@ func (g *Grid) setRect(x int, y int, width int, height int, rr *[]resizerequest)
w = g.colwidths[col]
h = g.rowheights[row]
}
- c.setRect(x, y, w, h, rr)
+ c.setRect(x, y + g.yoff[row][col], w, h - g.yoff[row][col], rr)
x += g.colwidths[col]
}
x = startx
@@ -184,7 +188,7 @@ func (g *Grid) setRect(x int, y int, width int, height int, rr *[]resizerequest)
}
// filling and stretchy are ignored for preferred size calculation
-func (g *Grid) preferredSize() (width int, height int) {
+func (g *Grid) preferredSize() (width int, height int, yoff int) {
max := func(a int, b int) int {
if a > b {
return a
@@ -202,7 +206,8 @@ func (g *Grid) preferredSize() (width int, height int) {
// 2) get preferred sizes; compute row/column sizes
for row, xcol := range g.controls {
for col, c := range xcol {
- w, h := c.preferredSize()
+ // ignore yoff for preferred size calculations
+ w, h, _ := c.preferredSize()
g.widths[row][col] = w
g.heights[row][col] = h
g.rowheights[row] = max(g.rowheights[row], h)
@@ -216,5 +221,7 @@ func (g *Grid) preferredSize() (width int, height int) {
for _, h := range g.rowheights {
height += h
}
- return width, height
+
+ // yoff is always zero for grids
+ return width, height, 0
}