mirror of https://github.com/rivo/tview.git
Fix the DropDown list when too close to the right screen edge
There was a bug: DropDown always aligns the left edge of selection list and the main widget, but when the widget is too close to the right screen edge, the list ends up being drawn only partially. Fixes #726.
This commit is contained in:
parent
9994674d60
commit
14200b58af
12
dropdown.go
12
dropdown.go
|
@ -395,12 +395,20 @@ func (d *DropDown) Draw(screen tcell.Screen) {
|
|||
|
||||
// Draw options list.
|
||||
if d.HasFocus() && d.open {
|
||||
// We prefer to drop down but if there is no space, maybe drop up?
|
||||
lx := x
|
||||
ly := y + 1
|
||||
lwidth := maxWidth
|
||||
lheight := len(d.options)
|
||||
_, sheight := screen.Size()
|
||||
swidth, sheight := screen.Size()
|
||||
// We prefer to align the left sides of the list and the main widget, but
|
||||
// if there is no space to the right, then shift the list to the left.
|
||||
if lx+lwidth >= swidth {
|
||||
lx = swidth - lwidth
|
||||
if lx < 0 {
|
||||
lx = 0
|
||||
}
|
||||
}
|
||||
// We prefer to drop down but if there is no space, maybe drop up?
|
||||
if ly+lheight >= sheight && ly-2 > lheight-ly {
|
||||
ly = y - lheight
|
||||
if ly < 0 {
|
||||
|
|
Loading…
Reference in New Issue