Added functions to retrieve and set a list item's texts. Resolves #102

This commit is contained in:
Oliver 2018-04-19 21:17:13 +02:00
parent 8d257feeb9
commit f291602d9a
1 changed files with 20 additions and 0 deletions

20
list.go
View File

@ -173,6 +173,26 @@ func (l *List) AddItem(mainText, secondaryText string, shortcut rune, selected f
return l
}
// GetItemCount returns the number of items in the list.
func (l *List) GetItemCount() int {
return len(l.items)
}
// GetItemText returns an item's texts (main and secondary). Panics if the index
// is out of range.
func (l *List) GetItemText(index int) (main, secondary string) {
return l.items[index].MainText, l.items[index].SecondaryText
}
// SetItemText sets an item's main and secondary text. Panics if the index is
// out of range.
func (l *List) SetItemText(index int, main, secondary string) *List {
item := l.items[index]
item.MainText = main
item.SecondaryText = secondary
return l
}
// Clear removes all items from the list.
func (l *List) Clear() *List {
l.items = nil