mirror of
https://github.com/br0xen/termbox-util.git
synced 2024-11-29 16:13:14 +00:00
add function to set index
This commit is contained in:
parent
c3e595e205
commit
827c460f42
@ -148,6 +148,16 @@ func (i *Menu) GetSelectedIndex() int {
|
|||||||
return -1
|
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)
|
// SetSelectedOption sets the current selected option to v (if it's valid)
|
||||||
func (i *Menu) SetSelectedOption(v *MenuOption) {
|
func (i *Menu) SetSelectedOption(v *MenuOption) {
|
||||||
for idx := range i.options {
|
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
|
// DrawOptions draws the menu options at x, y
|
||||||
|
Loading…
Reference in New Issue
Block a user