diff options
| author | Clement Benard <contact@clementbenard.com> | 2019-07-11 10:50:37 +0200 |
|---|---|---|
| committer | Clement Benard <contact@clementbenard.com> | 2019-07-11 10:50:37 +0200 |
| commit | 009f865bc5484e54f09d2173b2b3dbbf3838d391 (patch) | |
| tree | e4b5e27c856267d3f7efedb85f1bbd6197e7d704 /layout/split.go | |
| parent | 24286694a5ba80cc3f54a224b62ac11c773b4985 (diff) | |
| download | gui-009f865bc5484e54f09d2173b2b3dbbf3838d391.zip | |
Added SplitFunc type, documented everything exported
Diffstat (limited to 'layout/split.go')
| -rw-r--r-- | layout/split.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/layout/split.go b/layout/split.go new file mode 100644 index 0000000..4bf00a7 --- /dev/null +++ b/layout/split.go @@ -0,0 +1,19 @@ +package layout + +// 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 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. +// It is almost evenly because width may not be divisible by elements. +func EvenSplit(elements int, width int) []int { + ret := make([]int, 0, elements) + for elements > 0 { + v := width / elements + width -= v + elements -= 1 + ret = append(ret, v) + } + return ret +} |