mirror of https://github.com/rivo/tview.git
List (and therefore also DropDown) will scroll if currently selected item is not on screen anymore. Fixes #71
This commit is contained in:
parent
45acc0d895
commit
7e4958256f
|
@ -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
16
list.go
|
@ -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…
Reference in New Issue