@@ -49,9 +49,13 @@ func NewList(items ...Item) *List {
4949 return l
5050}
5151
52+// RenderCallback defines a function that can modify an item before it is
53+// rendered.
54+type RenderCallback func(idx, selectedIdx int, item Item) Item
55+
5256// RegisterRenderCallback registers a callback to be called when rendering
5357// items. This can be used to modify items before they are rendered.
54−func (l *List) RegisterRenderCallback(cb func(idx, selectedIdx int, item Item) Item) {
58+func (l *List) RegisterRenderCallback(cb RenderCallback) {
5559 l.renderCallbacks = append(l.renderCallbacks, cb)
5660}
5761
@@ -66,6 +70,11 @@ func (l *List) SetGap(gap int) {
6670 l.gap = gap
6771}
6872
73+// Gap returns the gap between items.
74+func (l *List) Gap() int {
75+ return l.gap
76+}
77+
6978// SetReverse shows the list in reverse order.
7079func (l *List) SetReverse(reverse bool) {
7180 l.reverse = reverse
@@ -101,10 +110,6 @@ func (l *List) getItem(idx int) renderedItem {
101110 }
102111 }
103112
104− if focusable, isFocusable := item.(Focusable); isFocusable {
105− focusable.SetFocused(l.focused && idx == l.selectedIdx)
106− }
107−
108113 rendered := item.Render(l.width)
109114 rendered = strings.TrimRight(rendered, "\n")
110115 height := countLines(rendered)
@@ -348,6 +353,11 @@ func (l *List) RemoveItem(idx int) {
348353 }
349354}
350355
356+// Focused returns whether the list is focused.
357+func (l *List) Focused() bool {
358+ return l.focused
359+}
360+
351361// Focus sets the focus state of the list.
352362func (l *List) Focus() {
353363 l.focused = true