Added right-alignment to Grid.
This commit is contained in:
parent
2731cf3ae0
commit
91e35c1610
12
grid.go
12
grid.go
|
@ -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,20 +246,19 @@ 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 {
|
||||
cell.xoff = 0
|
||||
switch cell.xalign {
|
||||
case LeftTop:
|
||||
// do nothing; this is the default
|
||||
case Center:
|
||||
case RightBottom:
|
||||
// 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
|
||||
|
@ -270,7 +271,6 @@ func (g *grid) allocate(x int, y int, width int, height int, d *sizing) (allocat
|
|||
panic(fmt.Errorf("invalid yalign %d in Grid.allocate()", cell.yalign))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 5) draw
|
||||
var current *allocation
|
||||
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue