From 14200b58af89cfe28e9a98e7e43224dbdc4f34b5 Mon Sep 17 00:00:00 2001 From: Dmitry Frank Date: Sun, 24 Apr 2022 11:25:17 +0300 Subject: [PATCH] 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. --- dropdown.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/dropdown.go b/dropdown.go index 9816279..96019dc 100644 --- a/dropdown.go +++ b/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 {