shithub: choc

Download patch

ref: 98ecb00e9d480d6391417883e6f1f035fd2014b7
parent: 76a7eebc335c6f57da589ee66971b850f0ec4c50
author: Simon Howard <fraggle@gmail.com>
date: Tue Sep 20 18:06:12 EDT 2011

Don't allow dropdown widget pop-up window to be placed outside the
boundaries of the screen.

Subversion-branch: /branches/v2-branch
Subversion-revision: 2391

--- a/textscreen/txt_dropdown.c
+++ b/textscreen/txt_dropdown.c
@@ -49,14 +49,29 @@
 
 static int SelectorWindowY(txt_dropdown_list_t *list)
 {
+    int result;
+
     if (ValidSelection(list))
     {
-        return list->widget.y - 1 - *list->variable;
+        result = list->widget.y - 1 - *list->variable;
     }
     else
     {
-        return list->widget.y - 1 - (list->num_values / 2);
+        result = list->widget.y - 1 - (list->num_values / 2);
     }
+
+    // Keep dropdown inside the screen.
+
+    if (result < 1)
+    {
+        result = 1;
+    }
+    else if (result + list->num_values > (TXT_SCREEN_H - 3))
+    {
+        result = TXT_SCREEN_H - list->num_values - 3;
+    }
+
+    return result;
 }
 
 // Called when a button in the selector window is pressed