1
0
mirror of https://github.com/br0xen/termbox-util.git synced 2024-11-22 13:33:15 +00:00

add function to set index

This commit is contained in:
Brian Buller 2016-02-22 07:32:34 -06:00
parent c3e595e205
commit 827c460f42

View File

@ -148,6 +148,16 @@ func (i *Menu) GetSelectedIndex() int {
return -1
}
// SetSelectedIndex sets the selection to setIdx
func (i *Menu) SetSelectedIndex(idx int) {
if idx < 0 {
idx = 0
} else if idx >= len(i.options) {
idx = len(i.options) - 1
}
i.SetSelectedOption(&i.options[idx])
}
// SetSelectedOption sets the current selected option to v (if it's valid)
func (i *Menu) SetSelectedOption(v *MenuOption) {
for idx := range i.options {
@ -339,7 +349,6 @@ func (i *Menu) Draw() {
}
}
}
i.DrawOptions(optionStartX, optionStartY, optionHeight, optionWidth)
}
// DrawOptions draws the menu options at x, y