CheckBoxContainer
com.jsmacrosce.wagyourgui.containers.CheckBoxContainer
A checkbox-and-label container for WagYourGUI; construction registers its checkbox with the supplied parent,
while the host must arrange this container's label hook separately. Activation toggles the stored state,
calls the optional consumer with the new boolean, then updates the checkmark after a normal callback return.
If the callback throws, the state has changed but the checkmark update is not reached; without a callback both updates proceed.
The factory takes a caller-supplied IContainerParent, native Font, native Component label and JavaScript callback:
js
function makeCheckBox(parent, font, label, onChanged) {
const CheckBoxContainer = Java.type('com.jsmacrosce.wagyourgui.containers.CheckBoxContainer');
return new CheckBoxContainer(10, 10, 140, 14, font, false, label, parent, JavaWrapper.methodToJava(onChanged));
}Constructors
new CheckBoxContainer
new CheckBoxContainer(int x, int y, int width, int height, Font textRenderer, boolean defaultState, Component message, IContainerParent parent, Consumer<Boolean> setState)#Stores the checkbox configuration and immediately initializes and registers its button with
parent; no callback is invoked during construction.Parameters:
x: left coordinate in the GUIy: top coordinate in the GUIwidth: total container width, including the label regionheight: checkbox side length and label offsettextRenderer: non-null font used for the checkbox and labeldefaultState: initial checked statemessage: non-null native component used as the labelparent: non-null widget host that registers the checkboxsetState: optional consumer called with the new checked state on button activation
Fields
message
Methods
init
init(): void#Clears local button tracking and registers a new checkbox at the stored position with the stored height as its side length. Retains the current checked state, replaces the checkbox reference and does not invoke the state consumer. Prior parent registrations are not removed; the constructor already calls this method.
render
render(GuiGraphics drawContext, int mouseX, int mouseY, float delta): void#Submits only the current label when this container is visible, using word wrapping at
(x + height, y + 2) with width width - height - 2 from the stored container geometry. Does not submit the checkbox or forward the hook to children; the parent handles the separately registered checkbox. Mouse and frame parameters are unused.Parameters:
drawContext: graphics context receiving the labelmouseX: unused GUI mouse coordinatemouseY: unused GUI mouse coordinatedelta: unused frame value
setPos
setPos(int x, int y, int width, int height): void#Moves and resizes only the checkbox to
(x + 1, y + 1, height - 2, height - 2). Stored container geometry and label placement are unchanged, and width is unused. Reinitialization uses the stored container geometry again.Parameters:
x: supplied outer left coordinatey: supplied outer top coordinatewidth: unusedheight: supplied outer height, determining the inset checkbox side