Exported xspan/yspan in Grid to the Add() function parameter list.
This commit is contained in:
parent
986c75493d
commit
3bd1ec9334
15
grid.go
15
grid.go
|
@ -8,7 +8,7 @@ import (
|
||||||
|
|
||||||
// Grid is a Control that arranges other Controls in a grid.
|
// Grid is a Control that arranges other Controls in a grid.
|
||||||
// Grid is a very powerful container: it can position and size each Control in several ways and can (and must) have Controls added to it at any time, in any direction.
|
// Grid is a very powerful container: it can position and size each Control in several ways and can (and must) have Controls added to it at any time, in any direction.
|
||||||
// [TODO it can also have Controls spanning multiple rows and columns.]
|
// it can also have Controls spanning multiple rows and columns.
|
||||||
//
|
//
|
||||||
// Each Control in a Grid has associated "expansion" and "alignment" values in both the X and Y direction.
|
// Each Control in a Grid has associated "expansion" and "alignment" values in both the X and Y direction.
|
||||||
// Expansion determines whether all cells in the same row/column are given whatever space is left over after figuring out how big the rest of the Grid should be.
|
// Expansion determines whether all cells in the same row/column are given whatever space is left over after figuring out how big the rest of the Grid should be.
|
||||||
|
@ -24,7 +24,9 @@ type Grid interface {
|
||||||
// Otherwise, it is placed relative to nextTo.
|
// Otherwise, it is placed relative to nextTo.
|
||||||
// If nextTo is nil, it is placed next to the previously added Control.
|
// If nextTo is nil, it is placed next to the previously added Control.
|
||||||
// The effect of adding the same Control multiple times is undefined, as is the effect of adding a Control next to one not present in the Grid.
|
// The effect of adding the same Control multiple times is undefined, as is the effect of adding a Control next to one not present in the Grid.
|
||||||
Add(control Control, nextTo Control, side Side, xexpand bool, xalign Align, yexpand bool, yalign Align)
|
// The effect of overlapping spanning Controls is also undefined.
|
||||||
|
// Add panics if either xspan or yspan are zero or negative.
|
||||||
|
Add(control Control, nextTo Control, side Side, xexpand bool, xalign Align, yexpand bool, yalign Align, xspan int, yspan int)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Align represents the alignment of a Control in its cell of a Grid.
|
// Align represents the alignment of a Control in its cell of a Grid.
|
||||||
|
@ -112,15 +114,18 @@ func (g *grid) reorigin() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *grid) Add(control Control, nextTo Control, side Side, xexpand bool, xalign Align, yexpand bool, yalign Align) {
|
func (g *grid) Add(control Control, nextTo Control, side Side, xexpand bool, xalign Align, yexpand bool, yalign Align, xspan int, yspan int) {
|
||||||
|
if xspan <= 0 || yspan <= 0 {
|
||||||
|
panic(fmt.Errorf("invalid span %dx%d given to Grid.Add()", xspan, yspan))
|
||||||
|
}
|
||||||
cell := gridCell{
|
cell := gridCell{
|
||||||
control: control,
|
control: control,
|
||||||
xexpand: xexpand,
|
xexpand: xexpand,
|
||||||
xalign: xalign,
|
xalign: xalign,
|
||||||
yexpand: yexpand,
|
yexpand: yexpand,
|
||||||
yalign: yalign,
|
yalign: yalign,
|
||||||
xspan: 1,
|
xspan: xspan,
|
||||||
yspan: 1,
|
yspan: yspan,
|
||||||
}
|
}
|
||||||
if g.parent != nil {
|
if g.parent != nil {
|
||||||
control.setParent(g.parent)
|
control.setParent(g.parent)
|
||||||
|
|
|
@ -32,8 +32,8 @@ func newRepainter(times int) *repainter {
|
||||||
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 := NewGrid()
|
||||||
grid2.Add(r.area, nil, South, true, Fill, true, Fill)
|
grid2.Add(r.area, nil, South, true, Fill, true, Fill, 1, 1)
|
||||||
grid2.Add(NewButton("X"), nil, East, false, LeftTop, true, Center)
|
grid2.Add(NewButton("X"), nil, East, false, LeftTop, true, Center, 1, 1)
|
||||||
r.x = NewTextField()
|
r.x = NewTextField()
|
||||||
r.x.OnChanged(r.setx)
|
r.x.OnChanged(r.setx)
|
||||||
r.y = NewTextField()
|
r.y = NewTextField()
|
||||||
|
@ -47,12 +47,12 @@ func newRepainter(times int) *repainter {
|
||||||
r.all = NewButton("All")
|
r.all = NewButton("All")
|
||||||
r.all.OnClicked(r.doall)
|
r.all.OnClicked(r.doall)
|
||||||
grid := NewGrid()
|
grid := NewGrid()
|
||||||
grid.Add(r.x, nil, North, true, Fill, false, LeftTop)
|
grid.Add(r.x, nil, North, true, Fill, false, LeftTop, 1, 1)
|
||||||
grid.Add(r.y, r.x, East, true, Fill, false, LeftTop)
|
grid.Add(r.y, r.x, East, true, Fill, false, LeftTop, 1, 1)
|
||||||
grid.Add(r.repaint, nil, East, false, 0, false, LeftTop)
|
grid.Add(r.repaint, nil, East, false, 0, false, LeftTop, 1, 1)
|
||||||
grid.Add(r.width, r.x, South, true, Fill, false, LeftTop)
|
grid.Add(r.width, r.x, South, true, Fill, false, LeftTop, 1, 1)
|
||||||
grid.Add(r.height, nil, East, true, Fill, false, LeftTop)
|
grid.Add(r.height, nil, East, true, Fill, false, LeftTop, 1, 1)
|
||||||
grid.Add(r.all, nil, East, false, Center, false, LeftTop)
|
grid.Add(r.all, nil, East, false, Center, false, LeftTop, 1, 1)
|
||||||
r.stack = NewVerticalStack(grid2, grid)
|
r.stack = NewVerticalStack(grid2, grid)
|
||||||
r.stack.SetStretchy(0)
|
r.stack.SetStretchy(0)
|
||||||
return r
|
return r
|
||||||
|
|
Loading…
Reference in New Issue