Merge pull request #727 from dimonomid/dropdown-hor-alignment-fix

Fix the DropDown list when too close to the right screen edge
pull/294/merge
rivo 2 years ago committed by GitHub
commit 12a29444c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -396,12 +396,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…
Cancel
Save