Mostly fixed Grid behavior.
This commit is contained in:
parent
fd0ef41965
commit
dbba883776
55
grid.go
55
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)
|
yexpand := make([]bool, g.ymax)
|
||||||
|
|
||||||
// 1) compute colwidths and rowheights before handling expansion
|
// 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 y := 0; y < len(gg); y++ {
|
||||||
for x := 0; x < len(gg[y]); x++ {
|
for x := 0; x < len(gg[y]); x++ {
|
||||||
i := 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
|
continue
|
||||||
}
|
}
|
||||||
w, h := g.controls[i].control.preferredSize(d)
|
w, h := g.controls[i].control.preferredSize(d)
|
||||||
// allot equal space in the presence of spanning to keep things sane
|
if g.controls[i].xspan == 1 {
|
||||||
if colwidths[x] < w / g.controls[i].xspan {
|
if colwidths[x] < w {
|
||||||
colwidths[x] = w / g.controls[i].xspan
|
colwidths[x] = w
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if g.controls[i].yspan == 1 {
|
||||||
|
if rowheights[y] < h {
|
||||||
|
rowheights[y] = h
|
||||||
}
|
}
|
||||||
if rowheights[y] < h / g.controls[i].yspan {
|
|
||||||
rowheights[y] = h / g.controls[i].yspan
|
|
||||||
}
|
}
|
||||||
// save these for step 6
|
// save these for step 6
|
||||||
g.controls[i].prefwidth = w
|
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
|
// 2) figure out which rows/columns expand but not span
|
||||||
// we only mark the first row/column of a spanning cell as expanding to prevent unexpected behavior
|
// we need to know which expanding rows/columns don't span before we can handle the ones that do
|
||||||
for i := range g.controls {
|
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
|
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
|
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
|
// 3) compute and assign expanded widths/heights
|
||||||
nxexpand := 0
|
nxexpand := 0
|
||||||
nyexpand := 0
|
nyexpand := 0
|
||||||
|
|
Loading…
Reference in New Issue