mirror of
https://github.com/rivo/tview.git
synced 2024-11-15 06:12:46 +00:00
Added SetFocus() to Form which changes the focus to a specific form element. Resolves #286
This commit is contained in:
parent
29b0d3cfbf
commit
384f577a62
14
form.go
14
form.go
@ -154,6 +154,20 @@ func (f *Form) SetButtonTextColor(color tcell.Color) *Form {
|
||||
return f
|
||||
}
|
||||
|
||||
// SetFocus shifts the focus to the form element with the given index, counting
|
||||
// non-button items first and buttons last. Note that this index is only used
|
||||
// when the form itself receives focus.
|
||||
func (f *Form) SetFocus(index int) *Form {
|
||||
if index < 0 {
|
||||
f.focusedElement = 0
|
||||
} else if index >= len(f.items)+len(f.buttons) {
|
||||
f.focusedElement = len(f.items) + len(f.buttons)
|
||||
} else {
|
||||
f.focusedElement = index
|
||||
}
|
||||
return f
|
||||
}
|
||||
|
||||
// AddInputField adds an input field to the form. It has a label, an optional
|
||||
// initial value, a field width (a value of 0 extends it as far as possible),
|
||||
// an optional accept function to validate the item's value (set to nil to
|
||||
|
Loading…
Reference in New Issue
Block a user