Refactor help menu

This commit is contained in:
Caleb Bassi 2019-07-15 16:06:37 -07:00
parent e1f3488c4c
commit 2cd92e147e

View File

@ -45,7 +45,11 @@ func NewHelpMenu() *HelpMenu {
}
func (self *HelpMenu) Resize(termWidth, termHeight int) {
textWidth := 53
var textWidth = 0
for _, line := range strings.Split(KEYBINDS, "\n") {
textWidth = maxInt(len(line), textWidth)
}
textWidth += 2
textHeight := 22
x := (termWidth - textWidth) / 2
y := (termHeight - textHeight) / 2
@ -65,3 +69,10 @@ func (self *HelpMenu) Draw(buf *ui.Buffer) {
}
}
}
func maxInt(a int, b int) int {
if a > b {
return a
}
return b
}