Implemented vertical alignment in Grid.

This commit is contained in:
Pietro Gagliardi 2014-09-01 10:11:41 -04:00
parent dcb505fd01
commit 83b1957fd7
2 changed files with 8 additions and 3 deletions

View File

@ -259,12 +259,14 @@ func (g *grid) allocate(x int, y int, width int, height int, d *sizing) (allocat
default: default:
panic(fmt.Errorf("invalid xalign %d in Grid.allocate()", cell.xalign)) panic(fmt.Errorf("invalid xalign %d in Grid.allocate()", cell.xalign))
} }
cell.yoff = 0
switch cell.yalign { switch cell.yalign {
case LeftTop: case LeftTop:
// do nothing; this is the default // do nothing; this is the default
case Center: case Center:
cell.yoff = (rowheights[cell.gridy] - cell.height) / 2
case RightBottom: case RightBottom:
// TODO cell.yoff = rowheights[cell.gridy] - cell.height
case Fill: case Fill:
cell.height = rowheights[cell.gridy] cell.height = rowheights[cell.gridy]
default: default:
@ -280,7 +282,7 @@ func (g *grid) allocate(x int, y int, width int, height int, d *sizing) (allocat
current = nil current = nil
for col, c := range xcol { for col, c := range xcol {
cell := g.controls[c] cell := g.controls[c]
as := c.allocate(x + cell.xoff, y, cell.width, cell.height, d) 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 current.neighbor = c
} }

View File

@ -31,6 +31,9 @@ func newRepainter(times int) *repainter {
r.img = tileImage(times) r.img = tileImage(times)
r.area = NewArea(r.img.Rect.Dx(), r.img.Rect.Dy(), r) r.area = NewArea(r.img.Rect.Dx(), r.img.Rect.Dy(), r)
r.area.OnTextFieldDismissed(r.tfdone) r.area.OnTextFieldDismissed(r.tfdone)
grid2 := NewGrid()
grid2.Add(r.area, nil, South, true, Fill, true, Fill)
grid2.Add(NewButton("X"), nil, East, false, LeftTop, true, Center)
r.x = NewTextField() r.x = NewTextField()
r.x.OnChanged(r.setx) r.x.OnChanged(r.setx)
r.y = NewTextField() r.y = NewTextField()
@ -50,7 +53,7 @@ func newRepainter(times int) *repainter {
grid.Add(r.width, r.x, South, true, Fill, false, LeftTop) grid.Add(r.width, r.x, South, true, Fill, false, LeftTop)
grid.Add(r.height, nil, East, true, Fill, false, LeftTop) grid.Add(r.height, nil, East, true, Fill, false, LeftTop)
grid.Add(r.all, nil, East, false, Center, false, LeftTop) grid.Add(r.all, nil, East, false, Center, false, LeftTop)
r.stack = NewVerticalStack(r.area, grid) r.stack = NewVerticalStack(grid2, grid)
r.stack.SetStretchy(0) r.stack.SetStretchy(0)
return r return r
} }