fix possible index-out-of-range issue in palette

This commit is contained in:
sqshq 2019-04-15 22:12:39 -04:00
parent 6f8f5f080c
commit 09c16065f5
1 changed files with 5 additions and 4 deletions

View File

@ -67,9 +67,10 @@ func GetPalette(theme Theme) Palette {
} }
func GetGradientColor(gradient []ui.Color, cur int, max int) ui.Color { func GetGradientColor(gradient []ui.Color, cur int, max int) ui.Color {
if cur > max {
cur = max
}
ratio := float64(len(gradient)) / float64(max) ratio := float64(len(gradient)) / float64(max)
return gradient[int(ratio*float64(cur))] index := int(ratio * float64(cur))
if index > len(gradient)-1 {
index = len(gradient) - 1
}
return gradient[index]
} }