ListContainer
com.jsmacrosce.wagyourgui.containers.ListContainer
A five-column list of selectable component buttons registered with a supplied widget host.
Call init() after construction to register the scrollbar and buttons; arrange any popup-hook invocation separately.
Buttons report their captured zero-based item index to the callback without closing the container. The factory takes a caller-supplied IOverlayParent, native Font, java.util.List of native Component choices and JavaScript callback:
js
function makeList(parent, font, choices, onSelected) {
const ListContainer = Java.type('com.jsmacrosce.wagyourgui.containers.ListContainer');
const list = new ListContainer(10, 10, 300, 120, font, choices, parent, JavaWrapper.methodToJava(onSelected));
list.init();
return list;
}Constructors
new ListContainer
new ListContainer(int x, int y, int width, int height, Font textRenderer, List<Component> list, IOverlayParent parent, Consumer<Integer> onSelect)#Stores the list, geometry, rendering font, widget host, and selection callback; call
init() separately to register widgets. The supplied component list is retained by reference; changes are read on a later init(), not applied to existing rows automatically.Parameters:
x: left GUI coordinatey: top GUI coordinatewidth: container width in GUI unitsheight: container height in GUI unitstextRenderer: non-null font used to render item labelslist: non-null native list of non-null component labels to create rows fromparent: non-null widget host that receives registered widgetsonSelect: non-null callback used when an item is selected
Fields
onSelect
Consumer invoked with the zero-based item index after the stored selection and hover flags are updated, including when reselecting the same item. Keep it non-null before selection. Reassignment affects future calls; callback failure does not roll back the updated selection or highlights.
Methods
addItem
Creates and registers a button at the next zero-based item index, in a five-column grid with 12-unit row heights. Uses the current stored scroll origin, even before
init; clicking selects the captured index. This does not modify the constructor's input list, update the scrollbar range, filter visibility or select the item.Parameters:
name: non-null native component label for the button
extractRenderState
extractRenderState(GuiGraphicsExtractor drawContext, int mouseX, int mouseY, float delta): void#Submits full-label popups for tracked buttons whose stored
hovering flag is set and whose label does not fit. It does not submit the buttons or a background, or forward the hook to the widget host or children. Neither the inherited visibility flag nor button visibility or active state is checked here; forceHover alone is not the popup predicate.Parameters:
drawContext: graphics receiving the popupmouseX: GUI x-coordinate used to position the popupmouseY: GUI y-coordinate used to position the popupdelta: unused frame value
init
init(): void#Clears local widget tracking, resets the row origin to
y + 13 and registers a scrollbar configured for two pages, then appends buttons for the retained input list. The retained rows and selected index are not cleared, and earlier parent widget registrations are not removed, so repeated calls append duplicate rows rather than refresh them. The scrollbar range is not adjusted to item count, and new rows are not initially visibility-filtered.onScrollbar
onScrollbar(double page): void#Repositions every retained row in five columns with 12-unit row heights from the origin
y + 13 - (int) (page * (height - 27)). Visibility checks each row's top against the inclusive interval from y + 13 to y + height - 27, not whether its full bounds fit. This does not recompute the scrollbar range or change the selected index.Parameters:
page: unclamped offset in units ofheight - 27GUI coordinates, not a normalized percentage
setSelected
setSelected(int index): void#Selects the indexed row, updates its highlight, and invokes
onSelect even when it was already selected. The index is not validated before state changes; an invalid index may fail after clearing the old highlight and storing the new index. The callback is not null-checked and runs after the selection and highlight updates; callback failure does not roll them back. This does not close the container or scroll to the item.Parameters:
index: valid zero-based index into the retained item list;-1is not a deselection operation