// A SimpleGrid arranges Controls in a two-dimensional grid.
// The height of each row and the width of each column is the maximum preferred height and width (respectively) of all the controls in that row or column (respectively).
// Controls are aligned to the top left corner of each cell.
// All Controls in a SimpleGrid maintain their preferred sizes by default; if a Control is marked as being "filling", it will be sized to fill its cell.
// Even if a Control is marked as filling, its preferred size is used to calculate cell sizes.
// One Control can be marked as "stretchy": when the Window containing the SimpleGrid is resized, the cell containing that Control resizes to take any remaining space; its row and column are adjusted accordingly (so other filling controls in the same row and column will fill to the new height and width, respectively).
// A stretchy Control implicitly fills its cell.
// All cooridnates in a SimpleGrid are given in (row,column) form with (0,0) being the top-left cell.
typeSimpleGridinterface{
Control
// SetFilling marks the given Control of the SimpleGrid as filling its cell instead of staying at its preferred size.
// It panics if the given coordinate is invalid.
SetFilling(rowint,columnint)
// SetStretchy marks the given Control of the SimpleGrid as stretchy.
// Stretchy implies filling.
// Only one control can be stretchy per SimpleGrid; calling SetStretchy multiple times merely changes which control is stretchy (preserving the previous filling value).
// It panics if the given coordinate is invalid.
SetStretchy(rowint,columnint)
}
typesimpleGridstruct{
controls[][]Control
filling[][]bool
stretchyrow,stretchycolint
stretchyfillbool
widths,heights[][]int// caches to avoid reallocating each time
rowheights,colwidths[]int
container*container
}
// NewSimpleGrid creates a new SimpleGrid with the given Controls.
// NewSimpleGrid needs to know the number of Controls in a row (alternatively, the number of columns); it will determine the number in a column from the number of Controls given.
// NewSimpleGrid panics if not given a full grid of Controls.
panic(fmt.Errorf("incomplete simpleGrid given to NewSimpleGrid() (not enough controls to evenly divide %d controls into rows of %d controls each)",len(controls),nPerRow))