Open dropdowns within the visible part of their list

ElementContext carries the part of the screen where an element can be
seen, passed down in a Frame and narrowed by each Scroll to its own box.
A dropdown opens below only if its list fits in that part, otherwise above
if it fits there, or else on the side with more room, so one at the
bottom of a scrolled list no longer opens past the list's edge.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-09-27 18:05:26 +02:00
co-authored by claude
parent 6bfdfc40c9
commit 8b58fe919d
6 changed files with 58 additions and 27 deletions
@@ -21,8 +21,8 @@ public class Select extends Element {
private final SelectProperty prop;
/** Where this was last drawn on the screen, to open the list under it */
private int originX, originY;
/** The context this was last drawn with, to open the list next to it */
private ElementContext lastContext;
public Select(SelectProperty prop) {
this.prop = prop;
@@ -32,8 +32,7 @@ public class Select extends Element {
@Override
public void render(RenderScope renderScope, ElementContext ctx) {
originX = ctx.originX;
originY = ctx.originY;
lastContext = ctx;
boolean open = Popup.isOpenFor(this);
Field.drawBox(renderScope, width, height, ctx.isHovering(), open);
@@ -55,6 +54,6 @@ public class Select extends Element {
Popup.close();
});
Popup.openBelow(this, list, originX, originY);
Popup.openBelow(this, list, lastContext);
}
}