aboutsummaryrefslogtreecommitdiffstats
path: root/layout/split.go
diff options
context:
space:
mode:
authorClement Benard <contact@clementbenard.com>2019-08-07 16:02:33 +0200
committerClement Benard <contact@clementbenard.com>2019-08-07 16:02:33 +0200
commit8d183ef96a57e3a2f42c0cb4ec0ab4c256e0d47e (patch)
tree4fa644f93ceeb5c102c5c1dcf85105890c0cf25b /layout/split.go
parent8b70878ccc7fe324f3647e56503a37f3780f9d41 (diff)
downloadgui-8d183ef96a57e3a2f42c0cb4ec0ab4c256e0d47e.zip
Made the layout package actually usable
Diffstat (limited to 'layout/split.go')
-rw-r--r--layout/split.go6
1 files changed, 4 insertions, 2 deletions
diff --git a/layout/split.go b/layout/split.go
index fb6d36e..db04225 100644
--- a/layout/split.go
+++ b/layout/split.go
@@ -7,18 +7,20 @@ import "fmt"
// The sum of all elements of the returned slice must be eqal to the space.
type SplitFunc func(elements int, space int) []int
+var _ SplitFunc = EvenSplit
+
// 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)
+ ret := make([]int, elements)
for elements > 0 {
v := width / elements
width -= v
elements -= 1
- ret = append(ret, v)
+ ret[elements] = v
}
return ret
}