summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-09-03 20:55:28 -0400
committerPietro Gagliardi <[email protected]>2014-09-03 20:55:28 -0400
commitdbba883776660cc9c535f97ddccbaa9e2752a333 (patch)
tree76452efba4c2d6a2597dcd707bb79975db66bbcb
parentfd0ef41965bbf478899cc02a2adc30132c4f5521 (diff)
Mostly fixed Grid behavior.
-rw-r--r--grid.go55
1 files changed, 46 insertions, 9 deletions
diff --git a/grid.go b/grid.go
index a6bb02c..ca6f2f6 100644
--- a/grid.go
+++ b/grid.go
@@ -201,6 +201,7 @@ func (g *grid) allocate(x int, y int, width int, height int, d *sizing) (allocat
yexpand := make([]bool, g.ymax)
// 1) compute colwidths and rowheights before handling expansion
+ // we only count non-spanning controls to avoid weirdness
for y := 0; y < len(gg); y++ {
for x := 0; x < len(gg[y]); x++ {
i := gg[y][x]
@@ -208,12 +209,15 @@ func (g *grid) allocate(x int, y int, width int, height int, d *sizing) (allocat
continue
}
w, h := g.controls[i].control.preferredSize(d)
- // allot equal space in the presence of spanning to keep things sane
- if colwidths[x] < w / g.controls[i].xspan {
- colwidths[x] = w / g.controls[i].xspan
+ if g.controls[i].xspan == 1 {
+ if colwidths[x] < w {
+ colwidths[x] = w
+ }
}
- if rowheights[y] < h / g.controls[i].yspan {
- rowheights[y] = h / g.controls[i].yspan
+ if g.controls[i].yspan == 1 {
+ if rowheights[y] < h {
+ rowheights[y] = h
+ }
}
// save these for step 6
g.controls[i].prefwidth = w
@@ -221,17 +225,50 @@ func (g *grid) allocate(x int, y int, width int, height int, d *sizing) (allocat
}
}
- // 2) figure out which columns expand
- // we only mark the first row/column of a spanning cell as expanding to prevent unexpected behavior
+ // 2) figure out which rows/columns expand but not span
+ // we need to know which expanding rows/columns don't span before we can handle the ones that do
for i := range g.controls {
- if g.controls[i].xexpand {
+ if g.controls[i].xexpand && g.controls[i].xspan == 1 {
xexpand[g.controls[i].x] = true
}
- if g.controls[i].yexpand {
+ if g.controls[i].yexpand && g.controls[i].yspan == 1 {
yexpand[g.controls[i].y] = true
}
}
+ // 2) figure out which rows/columns expand that do span
+ // the way we handle this is simple: if none of the spanned rows/columns expand, make all rows/columns expand
+ for i := range g.controls {
+ if g.controls[i].xexpand && g.controls[i].xspan != 1 {
+ do := true
+ for x := g.controls[i].x; x < g.controls[i].x + g.controls[i].xspan; x++ {
+ if xexpand[x] {
+ do = false
+ break
+ }
+ }
+ if do {
+ for x := g.controls[i].x; x < g.controls[i].x + g.controls[i].xspan; x++ {
+ xexpand[x] = true
+ }
+ }
+ }
+ if g.controls[i].yexpand && g.controls[i].yspan != 1 {
+ do := true
+ for y := g.controls[i].y; y < g.controls[i].y + g.controls[i].yspan; y++ {
+ if yexpand[y] {
+ do = false
+ break
+ }
+ }
+ if do {
+ for y := g.controls[i].y; y < g.controls[i].y + g.controls[i].yspan; y++ {
+ yexpand[y] = true
+ }
+ }
+ }
+ }
+
// 3) compute and assign expanded widths/heights
nxexpand := 0
nyexpand := 0