Browse Source

List (and therefore also DropDown) will scroll if currently selected item is not on screen anymore. Fixes #71

merge-requests/1/merge
Oliver 4 years ago
parent
commit
7e4958256f
  1. 8
      dropdown.go
  2. 16
      list.go

8
dropdown.go

@ -254,8 +254,14 @@ func (d *DropDown) Draw(screen tcell.Screen) { @@ -254,8 +254,14 @@ func (d *DropDown) Draw(screen tcell.Screen) {
lwidth := maxWidth
lheight := len(d.options)
_, sheight := screen.Size()
if ly+lheight >= sheight && ly-lheight-1 >= 0 {
if ly+lheight >= sheight && ly-2 > lheight-ly {
ly = y - lheight
if ly < 0 {
ly = 0
}
}
if ly+lheight >= sheight {
lheight = sheight - ly
}
d.list.SetRect(lx, ly, lwidth, lheight)
d.list.Draw(screen)

16
list.go

@ -193,8 +193,24 @@ func (l *List) Draw(screen tcell.Screen) { @@ -193,8 +193,24 @@ func (l *List) Draw(screen tcell.Screen) {
}
}
// We want to keep the current selection in view. What is our offset?
var offset int
if l.showSecondaryText {
if l.currentItem >= height/2 {
offset = l.currentItem + 1 - (height / 2)
}
} else {
if l.currentItem >= height {
offset = l.currentItem + 1 - height
}
}
// Draw the list items.
for index, item := range l.items {
if index < offset {
continue
}
if y >= bottomLimit {
break
}

Loading…
Cancel
Save