mirror of https://github.com/rivo/tview.git
Merge pull request #727 from dimonomid/dropdown-hor-alignment-fix
Fix the DropDown list when too close to the right screen edge
This commit is contained in:
commit
12a29444c8
12
dropdown.go
12
dropdown.go
|
@ -396,12 +396,20 @@ func (d *DropDown) Draw(screen tcell.Screen) {
|
||||||
|
|
||||||
// Draw options list.
|
// Draw options list.
|
||||||
if d.HasFocus() && d.open {
|
if d.HasFocus() && d.open {
|
||||||
// We prefer to drop down but if there is no space, maybe drop up?
|
|
||||||
lx := x
|
lx := x
|
||||||
ly := y + 1
|
ly := y + 1
|
||||||
lwidth := maxWidth
|
lwidth := maxWidth
|
||||||
lheight := len(d.options)
|
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 {
|
if ly+lheight >= sheight && ly-2 > lheight-ly {
|
||||||
ly = y - lheight
|
ly = y - lheight
|
||||||
if ly < 0 {
|
if ly < 0 {
|
||||||
|
|
Loading…
Reference in New Issue