Added right-alignment to Grid.

This commit is contained in:
Pietro Gagliardi 2014-09-01 00:56:33 -04:00
parent 2731cf3ae0
commit 91e35c1610
2 changed files with 31 additions and 31 deletions

50
grid.go
View File

@ -62,6 +62,8 @@ type gridCell struct {
// for allocate() and preferredSize()
gridx int
gridy int
xoff int
yoff int
width int
height int
visited bool
@ -244,31 +246,29 @@ func (g *grid) allocate(x int, y int, width int, height int, d *sizing) (allocat
// 4) handle alignment
for _, cell := range g.controls {
if cell.xexpand {
switch cell.xalign {
case LeftTop:
// do nothing; this is the default
case Center:
case RightBottom:
// TODO
case Fill:
cell.width = colwidths[cell.gridx]
default:
panic(fmt.Errorf("invalid xalign %d in Grid.allocate()", cell.xalign))
}
cell.xoff = 0
switch cell.xalign {
case LeftTop:
// do nothing; this is the default
case Center:
// TODO
case RightBottom:
cell.xoff = colwidths[cell.gridx] - cell.width
case Fill:
cell.width = colwidths[cell.gridx]
default:
panic(fmt.Errorf("invalid xalign %d in Grid.allocate()", cell.xalign))
}
if cell.yexpand {
switch cell.yalign {
case LeftTop:
// do nothing; this is the default
case Center:
case RightBottom:
// TODO
case Fill:
cell.height = rowheights[cell.gridy]
default:
panic(fmt.Errorf("invalid yalign %d in Grid.allocate()", cell.yalign))
}
switch cell.yalign {
case LeftTop:
// do nothing; this is the default
case Center:
case RightBottom:
// TODO
case Fill:
cell.height = rowheights[cell.gridy]
default:
panic(fmt.Errorf("invalid yalign %d in Grid.allocate()", cell.yalign))
}
}
@ -280,7 +280,7 @@ func (g *grid) allocate(x int, y int, width int, height int, d *sizing) (allocat
current = nil
for col, c := range xcol {
cell := g.controls[c]
as := c.allocate(x, y, cell.width, cell.height, d)
as := c.allocate(x + cell.xoff, y, cell.width, cell.height, d)
if current != nil { // connect first left to first right
current.neighbor = c
}

View File

@ -44,12 +44,12 @@ func newRepainter(times int) *repainter {
r.all = NewButton("All")
r.all.OnClicked(r.doall)
grid := NewGrid()
grid.Add(r.x, nil, North, true, Fill, false, 0)
grid.Add(r.y, r.x, East, true, Fill, false, 0)
grid.Add(r.repaint, nil, East, false, 0, false, 0)
grid.Add(r.width, r.x, South, true, Fill, false, 0)
grid.Add(r.height, nil, East, true, Fill, false, 0)
grid.Add(r.all, nil, East, false, 0, false, 0)
grid.Add(r.x, nil, North, true, Fill, false, LeftTop)
grid.Add(r.y, r.x, East, true, Fill, false, LeftTop)
grid.Add(r.repaint, nil, East, false, 0, 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.all, nil, East, false, RightBottom, false, LeftTop)
r.stack = NewVerticalStack(r.area, grid)
r.stack.SetStretchy(0)
return r