Added GetFocusedItemIndex() to Form. Resolves #293

This commit is contained in:
Oliver 2019-12-31 11:06:47 +01:00 committed by Trevor Slocum
parent 6bbae595a9
commit 2941d561fb
1 changed files with 13 additions and 0 deletions

13
form.go
View File

@ -342,6 +342,19 @@ func (f *Form) GetFormItemIndex(label string) int {
return -1
}
// GetFocusedItemIndex returns the indices of the form element or button which
// currently has focus. If they don't, -1 is returned resepectively.
func (f *Form) GetFocusedItemIndex() (formItem, button int) {
index := f.focusIndex()
if index < 0 {
return -1, -1
}
if index < len(f.items) {
return index, -1
}
return -1, index - len(f.items)
}
// SetCancelFunc sets a handler which is called when the user hits the Escape
// key.
func (f *Form) SetCancelFunc(callback func()) *Form {