From 827c460f42630207b15a32f816a08c00bfac0a3b Mon Sep 17 00:00:00 2001 From: Brian Buller Date: Mon, 22 Feb 2016 07:32:34 -0600 Subject: [PATCH] add function to set index --- termbox_menu.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/termbox_menu.go b/termbox_menu.go index dce341a..8f863ef 100644 --- a/termbox_menu.go +++ b/termbox_menu.go @@ -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