|
|
|
@ -194,6 +194,10 @@ type List struct {
|
|
|
|
|
// The height of the list the last time it was drawn.
|
|
|
|
|
height int
|
|
|
|
|
|
|
|
|
|
// If true, will render each ListItem without blank lines in between. This flag
|
|
|
|
|
// is ignored if `showSecondaryText` is true.
|
|
|
|
|
compact bool
|
|
|
|
|
|
|
|
|
|
sync.RWMutex
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -209,6 +213,7 @@ func NewList() *List {
|
|
|
|
|
selectedTextColor: Styles.PrimitiveBackgroundColor,
|
|
|
|
|
scrollBarColor: Styles.ScrollBarColor,
|
|
|
|
|
selectedBackgroundColor: Styles.PrimaryTextColor,
|
|
|
|
|
compact: false,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
l.ContextMenu = NewContextMenu(l)
|
|
|
|
@ -519,6 +524,15 @@ func (l *List) SetDoneFunc(handler func()) {
|
|
|
|
|
l.done = handler
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetCompactList sets the flag that determines whether a blank line is drawn between
|
|
|
|
|
// each ListItem. This flag will be ignored if `showSecondaryText` is true.
|
|
|
|
|
func (l *List) SetCompactList(compact bool) {
|
|
|
|
|
l.Lock()
|
|
|
|
|
defer l.Unlock()
|
|
|
|
|
|
|
|
|
|
l.compact = compact
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// AddItem calls InsertItem() with an index of -1.
|
|
|
|
|
func (l *List) AddItem(item *ListItem) {
|
|
|
|
|
l.InsertItem(-1, item)
|
|
|
|
@ -799,7 +813,11 @@ func (l *List) updateOffset() {
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if l.currentItem-l.itemOffset >= h {
|
|
|
|
|
l.itemOffset = l.currentItem + 1 - h
|
|
|
|
|
if l.compact {
|
|
|
|
|
l.itemOffset = l.currentItem - h
|
|
|
|
|
} else {
|
|
|
|
|
l.itemOffset = l.currentItem + 1 - h
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -978,7 +996,10 @@ func (l *List) Draw(screen tcell.Screen) {
|
|
|
|
|
|
|
|
|
|
RenderScrollBar(screen, l.scrollBarVisibility, scrollBarX, y, scrollBarHeight, len(l.items), scrollBarCursor, index-l.itemOffset, l.hasFocus, l.scrollBarColor)
|
|
|
|
|
|
|
|
|
|
y++
|
|
|
|
|
// Compact List
|
|
|
|
|
if !l.compact {
|
|
|
|
|
y++
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if y >= bottomLimit {
|
|
|
|
|
break
|
|
|
|
|