SelectorDropdownOverlay
com.jsmacrosce.wagyourgui.overlays.SelectorDropdownOverlay
A component-choice overlay with optional scrolling and a callback reporting the chosen zero-based index.
Keyboard confirmation can report -1 when nothing is selected. Construct it with a font, component collection and host; opening registers its controls.
js
function openChoices(parent, font, choices, onChoice) {
const Dropdown = Java.type("com.jsmacrosce.wagyourgui.overlays.SelectorDropdownOverlay");
const overlay = new Dropdown(10, 10, 160, 100, choices, font, parent,
JavaWrapper.methodToJava(onChoice));
parent.openOverlay(overlay);
return overlay;
}Constructors
new SelectorDropdownOverlay
new SelectorDropdownOverlay(int x, int y, int width, int height, Collection<Component> choices, Font textRenderer, IOverlayParent parent, Consumer<Integer> onChoice)#Retains the choices collection and caches row height and page count from the font, collection size and geometry. Does not initialize or open the overlay, register controls, or invoke the callback. Later collection changes do not refresh the cached metrics.
Parameters:
x: left edge in GUI coordinatesy: top edge in GUI coordinateswidth: overlay width in GUI unitsheight: overlay height in GUI units; values greater than four are needed for meaningful page calculationchoices: non-null collection of non-null native components, displayed in iteration ordertextRenderer: non-null font used to size and render choicesparent: non-null overlay hostonChoice: optional callback receiving the zero-based choice index, or -1 on keyboard confirmation without a selection; may be null
Methods
init
init(): void#Registers a scrollbar when the cached page count exceeds one, then buttons for the current choices in iteration order. A choice button invokes the optional callback before closing; if it throws, closing is not reached. Only the base local widget list is cleared. Reinitialization appends to the retained choice-button list without removing earlier host registrations or resetting selection; cached metrics and an old scroll reference are not reset. When scrolling is enabled, this pass finishes by laying out the retained choice buttons at offset zero.
keyPressed
keyPressed(int keyCode, int scanCode, int modifiers): boolean#Handles up/down selection and enter/tab confirmation; confirmation invokes the optional callback with the current selection, including -1, then closes. If the callback throws, closing and the return are not reached. Down is handled even when selection cannot change; up is not handled when nothing is selected. Other keys return false without superclass or child delegation. There is no local focus, activation or visibility check, and changing selection does not scroll it into view.
Parameters:
keyCode: native GLFW key codescanCode: unused scan codemodifiers: unused modifier flags
Returns: true for down, enter or tab, and for up when a selection exists; false otherwise
onClick
onClick(double mouseX, double mouseY, int button): void#Requests closing when the pointer is strictly outside the overlay bounds; points on the border do not close it. Does not forward the click to a child overlay or invoke the choice callback itself.
Parameters:
mouseX: pointer x-coordinate in GUI coordinatesmouseY: pointer y-coordinate in GUI coordinatesbutton: unused mouse-button value
onScroll
onScroll(double page): void#Positions all retained choice buttons for a page offset, hiding rows unless both edges lie strictly inside the overlay's inner bounds. Sets row width to overlay width minus ten. The offset is not clamped, and this does not change selection or invoke the choice callback.
Parameters:
page: page offset, not a fraction or percentage; displacement is page multiplied by overlay height in GUI units
render
render(GuiGraphics drawContext, int mouseX, int mouseY, float delta): void#Submits the overlay background, then delegates rendering of current tracked widgets and the direct child overlay. Does not check the stored container visibility flag or recalculate layout; widgets apply their own rendering behavior.
Parameters:
drawContext: non-null native graphics contextmouseX: pointer x-coordinate in GUI coordinatesmouseY: pointer y-coordinate in GUI coordinatesdelta: frame value forwarded to the superclass
setSelected
setSelected(int sel): void#Moves forced-hover highlighting from the old retained button to the clamped new selection, or clears it for -1. Hidden and previously retained buttons can be selected; this does not invoke the callback, close the overlay, change native focus, or scroll the selection into view.
Parameters:
sel: zero-based retained-button index, or -1 to clear; values are clamped to -1 through the retained list's last index