Added GetSelectedFunc and GetItremSelectedFunc to List. Resolves #1023, resolves #1024

This commit is contained in:
Oliver 2024-11-03 12:48:31 +01:00
parent ad9e2501de
commit f34fb2a4b3
1 changed files with 13 additions and 0 deletions

13
list.go
View File

@ -340,6 +340,12 @@ func (l *List) SetSelectedFunc(handler func(int, string, string, rune)) *List {
return l return l
} }
// GetSelectedFunc returns the function set with [List.SetSelectedFunc] or nil
// if no such function was set.
func (l *List) GetSelectedFunc() func(int, string, string, rune) {
return l.selected
}
// SetDoneFunc sets a function which is called when the user presses the Escape // SetDoneFunc sets a function which is called when the user presses the Escape
// key. // key.
func (l *List) SetDoneFunc(handler func()) *List { func (l *List) SetDoneFunc(handler func()) *List {
@ -419,6 +425,13 @@ func (l *List) GetItemCount() int {
return len(l.items) return len(l.items)
} }
// GetItemSelectedFunc returns the function which is called when the user
// selects the item with the given index, if such a function was set. If no
// function was set, nil is returned. Panics if the index is out of range.
func (l *List) GetItemSelectedFunc(index int) func() {
return l.items[index].Selected
}
// GetItemText returns an item's texts (main and secondary). Panics if the index // GetItemText returns an item's texts (main and secondary). Panics if the index
// is out of range. // is out of range.
func (l *List) GetItemText(index int) (main, secondary string) { func (l *List) GetItemText(index int) (main, secondary string) {