summaryrefslogtreecommitdiff
path: root/grid.go
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-09-03 18:30:38 -0400
committerPietro Gagliardi <[email protected]>2014-09-03 18:30:38 -0400
commit3bd1ec9334856e4071cc4f1b3106efc1f44db30d (patch)
tree08f9efa6e0c735ea4b133814ebe9a5234b93ca72 /grid.go
parent986c75493d37e2031e837108c4461e8afac65221 (diff)
Exported xspan/yspan in Grid to the Add() function parameter list.
Diffstat (limited to 'grid.go')
-rw-r--r--grid.go15
1 files changed, 10 insertions, 5 deletions
diff --git a/grid.go b/grid.go
index 4de9304..a6bb02c 100644
--- a/grid.go
+++ b/grid.go
@@ -8,7 +8,7 @@ import (
// 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.
-// [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.
// 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.
// 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.
- 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.
@@ -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{
control: control,
xexpand: xexpand,
xalign: xalign,
yexpand: yexpand,
yalign: yalign,
- xspan: 1,
- yspan: 1,
+ xspan: xspan,
+ yspan: yspan,
}
if g.parent != nil {
control.setParent(g.parent)