From f34fb2a4b346fb681959b3c47ae1e083a4e322e1 Mon Sep 17 00:00:00 2001 From: Oliver <480930+rivo@users.noreply.github.com> Date: Sun, 3 Nov 2024 12:48:31 +0100 Subject: [PATCH] Added GetSelectedFunc and GetItremSelectedFunc to List. Resolves #1023, resolves #1024 --- list.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/list.go b/list.go index 0b96a3a..9d0edb2 100644 --- a/list.go +++ b/list.go @@ -340,6 +340,12 @@ func (l *List) SetSelectedFunc(handler func(int, string, string, rune)) *List { return l } +// GetSelectedFunc returns the function set with [List.SetSelectedFunc] or nil +// if no such function was set. +func (l *List) GetSelectedFunc() func(int, string, string, rune) { + return l.selected +} + // SetDoneFunc sets a function which is called when the user presses the Escape // key. func (l *List) SetDoneFunc(handler func()) *List { @@ -419,6 +425,13 @@ func (l *List) GetItemCount() int { return len(l.items) } +// GetItemSelectedFunc returns the function which is called when the user +// selects the item with the given index, if such a function was set. If no +// function was set, nil is returned. Panics if the index is out of range. +func (l *List) GetItemSelectedFunc(index int) func() { + return l.items[index].Selected +} + // 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) {