From f291602d9a6926ac1945ec60090d3fd4f4b0e81b Mon Sep 17 00:00:00 2001 From: Oliver <480930+rivo@users.noreply.github.com> Date: Thu, 19 Apr 2018 21:17:13 +0200 Subject: [PATCH] Added functions to retrieve and set a list item's texts. Resolves #102 --- list.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/list.go b/list.go index f4973fe..8d0e49c 100644 --- a/list.go +++ b/list.go @@ -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