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:
@@ -1,24 +1,54 @@
|
||||
package org.saturnclient.ui;
|
||||
|
||||
public class ElementContext {
|
||||
/**
|
||||
* Where a container's children are drawn: the screen position of their
|
||||
* (0, 0), and the part of the screen, top to bottom, where they can be seen.
|
||||
*/
|
||||
public record Frame(int x, int y, int visibleTop, int visibleBottom) {
|
||||
/** The whole screen, for top-level elements */
|
||||
public static final Frame SCREEN = new Frame(0, 0, Integer.MIN_VALUE, Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
public int mouseX, mouseY;
|
||||
/** The element's top-left corner on the screen, for placing popups next to it */
|
||||
public int originX, originY;
|
||||
/** The part of the screen, top to bottom, where the element can be seen */
|
||||
public int visibleTop, visibleBottom;
|
||||
public int elementWidth, elementHeight;
|
||||
public float elementScale;
|
||||
public long elapsed;
|
||||
|
||||
public ElementContext(long elapsed, int mouseX, int mouseY, int parentX, int parentY, Element e) {
|
||||
public ElementContext(long elapsed, int mouseX, int mouseY, Frame frame, Element e) {
|
||||
this.mouseX = mouseX - e.x;
|
||||
this.mouseY = mouseY - e.y;
|
||||
this.originX = parentX + e.x;
|
||||
this.originY = parentY + e.y;
|
||||
this.originX = frame.x() + e.x;
|
||||
this.originY = frame.y() + e.y;
|
||||
this.visibleTop = frame.visibleTop();
|
||||
this.visibleBottom = frame.visibleBottom();
|
||||
this.elementWidth = e.width;
|
||||
this.elementHeight = e.height;
|
||||
this.elementScale = e.scale;
|
||||
this.elapsed = elapsed;
|
||||
}
|
||||
|
||||
/**
|
||||
* The frame for this element's children, drawn {@code dx}, {@code dy} from
|
||||
* its corner and seen only between {@code clipTop} and {@code clipBottom}
|
||||
* (relative to its corner).
|
||||
*/
|
||||
public Frame childFrame(int dx, int dy, int clipTop, int clipBottom) {
|
||||
return new Frame(originX + dx, originY + dy,
|
||||
Math.max(visibleTop, originY + clipTop), Math.min(visibleBottom, originY + clipBottom));
|
||||
}
|
||||
|
||||
/**
|
||||
* The frame for children drawn at this element's corner and not clipped.
|
||||
*/
|
||||
public Frame childFrame() {
|
||||
return new Frame(originX, originY, visibleTop, visibleBottom);
|
||||
}
|
||||
|
||||
public boolean isHovering() {
|
||||
return Utils.isHovering(mouseX, mouseY, elementWidth, elementHeight, elementScale);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user