forked from tslocum/cview
feat(List): Add additional field for setting an optional reference (like in TreeView)
This commit is contained in:
parent
d315a5c5b3
commit
bace1ac630
22
list.go
22
list.go
|
@ -10,11 +10,12 @@ import (
|
|||
|
||||
// ListItem represents an item in a List.
|
||||
type ListItem struct {
|
||||
enabled bool // Whether or not the list item is selectable.
|
||||
mainText string // The main text of the list item.
|
||||
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.
|
||||
selected func() // The optional function which is called when the item is selected.
|
||||
enabled bool // Whether or not the list item is selectable.
|
||||
mainText string // The main text of the list item.
|
||||
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.
|
||||
selected func() // The optional function which is called when the item is selected.
|
||||
reference interface{} // An optional reference object.
|
||||
}
|
||||
|
||||
// NewListItem returns a new item for the list.
|
||||
|
@ -64,6 +65,17 @@ func (l *ListItem) SetSelectedFunc(handler func()) *ListItem {
|
|||
return l
|
||||
}
|
||||
|
||||
// SetReference allows you to store a reference of any type in the item
|
||||
func (l *ListItem) SetReference(val interface{}) *ListItem {
|
||||
l.reference = val
|
||||
return l
|
||||
}
|
||||
|
||||
// GetReference returns the item's reference object.
|
||||
func (l *ListItem) GetReference() interface{} {
|
||||
return l.reference
|
||||
}
|
||||
|
||||
// List displays rows of items, each of which can be selected.
|
||||
type List struct {
|
||||
*Box
|
||||
|
|
Loading…
Reference in New Issue