expose list item and give an id

pull/43/head
Tony Worm 7 years ago
parent 0bb2f41351
commit 9172dc2066

@ -6,14 +6,20 @@ import (
"github.com/gdamore/tcell" "github.com/gdamore/tcell"
) )
// listItem represents one item in a List. // ListItem represents one item in a List.
type listItem struct { type ListItem struct {
id string
MainText string // The main text of the list item. MainText string // The main text of the list item.
SecondaryText string // A secondary text to be shown underneath the main text. SecondaryText string // A secondary text to be shown underneath the main text.
Shortcut rune // The key to select the list item directly, 0 if there is no shortcut. Shortcut rune // The key to select the list item directly, 0 if there is no shortcut.
Selected func() // The optional function which is called when the item is selected. Selected func() // The optional function which is called when the item is selected.
} }
// Id returns the item's id
func (l *ListItem) Id() string {
return l.id
}
// List displays rows of items, each of which can be selected. // List displays rows of items, each of which can be selected.
// //
// See https://github.com/rivo/tview/wiki/List for an example. // See https://github.com/rivo/tview/wiki/List for an example.
@ -21,7 +27,7 @@ type List struct {
*Box *Box
// The items of the list. // The items of the list.
items []*listItem items []*ListItem
// The index of the currently selected item. // The index of the currently selected item.
currentItem int currentItem int
@ -154,7 +160,7 @@ func (l *List) SetDoneFunc(handler func()) *List {
// may provide nil if no such item is needed or if all events are handled // may provide nil if no such item is needed or if all events are handled
// through the selected callback set with SetSelectedFunc(). // through the selected callback set with SetSelectedFunc().
func (l *List) AddItem(mainText, secondaryText string, shortcut rune, selected func()) *List { func (l *List) AddItem(mainText, secondaryText string, shortcut rune, selected func()) *List {
l.items = append(l.items, &listItem{ l.items = append(l.items, &ListItem{
MainText: mainText, MainText: mainText,
SecondaryText: secondaryText, SecondaryText: secondaryText,
Shortcut: shortcut, Shortcut: shortcut,

Loading…
Cancel
Save