From bace1ac63045db09b772eac5c2929aaec0502a3a Mon Sep 17 00:00:00 2001 From: Andreas Bieber Date: Wed, 16 Sep 2020 20:03:14 +0200 Subject: [PATCH] feat(List): Add additional field for setting an optional reference (like in TreeView) --- list.go | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/list.go b/list.go index a695784..1e8c2c0 100644 --- a/list.go +++ b/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