diff options
| author | Clement Benard <contact@clementbenard.com> | 2019-07-12 17:23:28 +0200 |
|---|---|---|
| committer | Clement Benard <contact@clementbenard.com> | 2019-07-12 17:23:28 +0200 |
| commit | 0cc6367a881ab7dba48ace7b111e0eb1151c10bb (patch) | |
| tree | eabadd10783b857271f12797f1a505efec85630c /layout/split.go | |
| parent | 009f865bc5484e54f09d2173b2b3dbbf3838d391 (diff) | |
| download | gui-0cc6367a881ab7dba48ace7b111e0eb1151c10bb.zip | |
Better separation between Layout and Mux
Diffstat (limited to 'layout/split.go')
| -rw-r--r-- | layout/split.go | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/layout/split.go b/layout/split.go index 4bf00a7..fb6d36e 100644 --- a/layout/split.go +++ b/layout/split.go @@ -1,13 +1,18 @@ package layout +import "fmt" + // SplitFunc represents a way to split a space among a number of elements. -// The space of the returned slice must be equal to the number of elements. +// The length of the returned slice must be equal to the number of elements. // The sum of all elements of the returned slice must be eqal to the space. type SplitFunc func(elements int, space int) []int -// EvenSplit implements SplitFunc to split a space (almost) evenly among the elements. +// EvenSplit is a SplitFunc used to split a space (almost) evenly among the elements. // It is almost evenly because width may not be divisible by elements. func EvenSplit(elements int, width int) []int { + if elements <= 0 { + panic(fmt.Errorf("EvenSplit: elements must be greater than 0")) + } ret := make([]int, 0, elements) for elements > 0 { v := width / elements |