IScreen
com.jsmacrosce.jsmacros.client.api.classes.render.IScreen
A script-created screen combines IDraw2D drawing with interactive widgets and screen input callbacks. Create one with Hud.createScreen and open it with Hud.openScreen; call reloadScreen() to clear and rebuild its elements by rerunning its init callback.
The game initializes a screen when it opens and when it is reloaded. Initialization clears elements added outside the init callback, so build the screen's contents in setOnInit(MethodWrapper).
Each input callback setter replaces the previous callback of that kind. Mouse positions use the same screen coordinates as drawing elements.
const screen = Hud.createScreen("my screen", true);
screen.setOnInit(JavaWrapper.methodToJava(function (self) {
self.addText("something to read", 10, 40, Color.rgb(0xFF, 0xFF, 0xFF), true);
self.addButton(10, 20, 100, 20, "a button", JavaWrapper.methodToJava(function (button) {
Chat.log("clicked");
}));
}));
Hud.openScreen(screen);Methods
addButton
addButton(int x, int y, int width, int height, String text, MethodWrapper<ClickableWidgetHelper<?, ?>, IScreen, Object, ?> callback): ClickableWidgetHelper<?, ?>Since1.0.5#Parameters:
x: screen x, the button's left edgey: screen y, the button's top edgewidth: how wide the button isheight: how tall the button istext: the label on the buttoncallback: calls your method as a Consumer<ClickableWidgetHelper>
addButton(int x, int y, int width, int height, int zIndex, String text, MethodWrapper<ClickableWidgetHelper<?, ?>, IScreen, Object, ?> callback): ClickableWidgetHelper<?, ?>Since1.4.0#zIndex.Parameters:
x: screen x, the button's left edgey: screen y, the button's top edgewidth: how wide the button isheight: how tall the button iszIndex: the z-index of the button against this screen's other elementstext: the label on the buttoncallback: calls your method as a Consumer<ClickableWidgetHelper>
addCheckbox
addCheckbox(int x, int y, int width, int height, String text, boolean checked, boolean showMessage, MethodWrapper<CheckBoxWidgetHelper, IScreen, Object, ?> callback): CheckBoxWidgetHelperSince1.8.4#showMessage parameter is currently ignored.Parameters:
x: the x position of the checkboxy: the y position of the checkboxwidth: the width of the checkboxheight: the height of the checkboxtext: the text to display next to the checkboxchecked: whether the checkbox is checked or notshowMessage: ignored; does not change label visibilitycallback: called when the checkbox state changes
addCheckbox(int x, int y, int width, int height, String text, boolean checked, MethodWrapper<CheckBoxWidgetHelper, IScreen, Object, ?> callback): CheckBoxWidgetHelperSince1.8.4#const screen = Hud.createScreen("a screen", true);
screen.setOnInit(JavaWrapper.methodToJava(function (self) {
self.addCheckbox(10, 20, 20, 20, "enabled", false, JavaWrapper.methodToJava(function (box) {
Chat.log(`now ${box.isChecked()}`);
}));
}));
Hud.openScreen(screen);Parameters:
x: the x position of the checkboxy: the y position of the checkboxwidth: the width of the checkboxheight: the height of the checkboxtext: the text to display next to the checkboxchecked: the initial checked statecallback: calls your method as a Consumer<CheckBoxWidgetHelper>
addCheckbox(int x, int y, int width, int height, int zIndex, String text, boolean checked, MethodWrapper<CheckBoxWidgetHelper, IScreen, Object, ?> callback): CheckBoxWidgetHelperSince1.8.4#zIndex.Parameters:
x: the x position of the checkboxy: the y position of the checkboxwidth: the width of the checkboxheight: the height of the checkboxzIndex: the z-index of the checkboxtext: the text to display next to the checkboxchecked: whether the checkbox is checked or notcallback: calls your method as a Consumer<CheckBoxWidgetHelper>
addCheckbox(int x, int y, int width, int height, int zIndex, String text, boolean checked, boolean showMessage, MethodWrapper<CheckBoxWidgetHelper, IScreen, Object, ?> callback): CheckBoxWidgetHelperSince1.8.4#zIndex whose callback runs when its checked state changes. The showMessage parameter is currently ignored.Parameters:
x: the x position of the checkboxy: the y position of the checkboxwidth: the width of the checkboxheight: the height of the checkboxzIndex: the z-index of the checkboxtext: the text to display next to the checkboxchecked: whether the checkbox is checked or notshowMessage: ignored; does not change label visibilitycallback: called when the checked state changes
addCyclingButton
addCyclingButton(int x, int y, int width, int height, String[] values, String initial, MethodWrapper<CyclingButtonWidgetHelper<?>, IScreen, Object, ?> callback): CyclingButtonWidgetHelper<?>Since1.8.4#const screen = Hud.createScreen("a screen", true);
screen.setOnInit(JavaWrapper.methodToJava(function (self) {
self.addCyclingButton(10, 20, 100, 20, ["low", "medium", "high"], "low",
JavaWrapper.methodToJava(function (button) {
Chat.log(`now ${button.getValue()}`);
}));
}));
Hud.openScreen(screen);Parameters:
x: the x position of the cycling buttony: the y position of the cycling buttonwidth: the width of the cycling buttonheight: the height of the cycling buttonvalues: the values to cycle throughinitial: the initial value of the cycling buttoncallback: called when the value changes Consumer<CyclingButtonWidgetHelper>
addCyclingButton(int x, int y, int width, int height, int zIndex, String[] values, String initial, MethodWrapper<CyclingButtonWidgetHelper<?>, IScreen, Object, ?> callback): CyclingButtonWidgetHelper<?>Since1.8.4#zIndex.Parameters:
x: the x position of the cycling buttony: the y position of the cycling buttonwidth: the width of the cycling buttonheight: the height of the cycling buttonzIndex: the z-index of the cycling buttonvalues: the values to cycle throughinitial: the initial valuecallback: called when the value changes
addCyclingButton(int x, int y, int width, int height, int zIndex, String[] values, String[] alternatives, String initial, String prefix, MethodWrapper<CyclingButtonWidgetHelper<?>, IScreen, Object, ?> callback): CyclingButtonWidgetHelper<?>Since1.8.4#zIndex.Parameters:
x: the x position of the cycling buttony: the y position of the cycling buttonwidth: the width of the cycling buttonheight: the height of the cycling buttonzIndex: the z-index of the cycling buttonvalues: the values to cycle throughalternatives: the alternative values to cycle throughinitial: the initial value of the cycling buttonprefix: the prefix of the valuescallback: called when the value changes
addCyclingButton(int x, int y, int width, int height, int zIndex, String[] values, String[] alternatives, String initial, String prefix, MethodWrapper<?, ?, Boolean, ?> alternateToggle, MethodWrapper<CyclingButtonWidgetHelper<?>, IScreen, Object, ?> callback): CyclingButtonWidgetHelper<?>Since1.8.4#Parameters:
x: the x position of the cycling buttony: the y position of the cycling buttonwidth: the width of the cycling buttonheight: the height of the cycling buttonzIndex: the z-index of the cycling buttonvalues: the values to cycle throughalternatives: the alternative values to cycle throughinitial: the initial value of the cycling buttonprefix: the prefix of the valuesalternateToggle: selects which value list is activecallback: called when the value changes
addLockButton
addLockButton(int x, int y, MethodWrapper<LockButtonWidgetHelper, IScreen, Object, ?> callback): LockButtonWidgetHelperSince1.8.4#const screen = Hud.createScreen("a screen", true);
screen.setOnInit(JavaWrapper.methodToJava(function (self) {
self.addLockButton(10, 20, JavaWrapper.methodToJava(function (button) {
Chat.log(`locked: ${button.isLocked()}`);
}));
}));
Hud.openScreen(screen);Parameters:
x: the x position of the lock buttony: the y position of the lock buttoncallback: called when the button is clicked Consumer<LockButtonWidgetHelper>
addLockButton(int x, int y, int zIndex, MethodWrapper<LockButtonWidgetHelper, IScreen, Object, ?> callback): LockButtonWidgetHelperSince1.8.4#zIndex.Parameters:
x: the x position of the lock buttony: the y position of the lock buttonzIndex: the z-index of the lock buttoncallback: calls your method as a Consumer<LockButtonWidgetHelper>
addSlider
addSlider(int x, int y, int width, int height, String text, double value, int steps, MethodWrapper<SliderWidgetHelper, IScreen, Object, ?> callback): SliderWidgetHelperSince1.8.4#const screen = Hud.createScreen("a screen", true);
screen.setOnInit(JavaWrapper.methodToJava(function (self) {
self.addSlider(10, 20, 100, 20, "volume", 0.5, 10, JavaWrapper.methodToJava(function (slider) {
Chat.log(`now ${slider.getValue()}`);
}));
}));
Hud.openScreen(screen);Parameters:
x: the x position of the slidery: the y position of the sliderwidth: the width of the sliderheight: the height of the slidertext: the text to be displayed inside the slidervalue: the initial value on the 0-to-1 scalesteps: the number of steps the slider should havecallback: calls your method as a Consumer<SliderWidgetHelper>
addSlider(int x, int y, int width, int height, int zIndex, String text, double value, int steps, MethodWrapper<SliderWidgetHelper, IScreen, Object, ?> callback): SliderWidgetHelperSince1.8.4#zIndex.Parameters:
x: the x position of the slidery: the y position of the sliderwidth: the width of the sliderheight: the height of the sliderzIndex: the z-index of the slidertext: the text to be displayed inside the slidervalue: the initial value of the slidersteps: the number of steps the slider should havecallback: calls your method as a Consumer<SliderWidgetHelper>
addSlider(int x, int y, int width, int height, String text, double value, MethodWrapper<SliderWidgetHelper, IScreen, Object, ?> callback): SliderWidgetHelperSince1.8.4#Parameters:
x: the x position of the slidery: the y position of the sliderwidth: the width of the sliderheight: the height of the slidertext: the text to be displayed inside the slidervalue: the initial value of the slidercallback: calls your method as a Consumer<SliderWidgetHelper>
addSlider(int x, int y, int width, int height, int zIndex, String text, double value, MethodWrapper<SliderWidgetHelper, IScreen, Object, ?> callback): SliderWidgetHelperSince1.8.4#zIndex; its value ranges from 0 to 1.Parameters:
x: the x position of the slidery: the y position of the sliderwidth: the width of the sliderheight: the height of the sliderzIndex: the z-index of the slidertext: the text to be displayed inside the slidervalue: the initial value of the slidercallback: calls your method as a Consumer<SliderWidgetHelper>
addTextInput
addTextInput(int x, int y, int width, int height, String message, MethodWrapper<String, IScreen, Object, ?> onChange): TextFieldWidgetHelperSince1.0.5#Parameters:
x: the field's left edgey: the field's top edgewidth: the field widthheight: the field heightmessage: the placeholder textonChange: called with the changed text
addTextInput(int x, int y, int width, int height, int zIndex, String message, MethodWrapper<String, IScreen, Object, ?> onChange): TextFieldWidgetHelperSince1.0.5#const screen = Hud.createScreen("a screen", true);
screen.setOnInit(JavaWrapper.methodToJava(function (self) {
self.addTextInput(10, 20, 100, 20, 0, "type a name", JavaWrapper.methodToJava(function (text) {
Chat.log(`so far: ${text}`);
}));
}));
Hud.openScreen(screen);Parameters:
x: screen x, the field's left edgey: screen y, the field's top edgewidth: how wide the field isheight: how tall the field iszIndex: the z-index of the field against this screen's other elementsmessage: the placeholder shown while the field is emptyonChange: calls your method as a Consumer<String>
buttonBuilder
build() adds the button to this screen; button height is fixed at 20. const screen = Hud.createScreen("a screen", true);
screen.setOnInit(JavaWrapper.methodToJava(function (self) {
self.buttonBuilder()
.pos(10, 20)
.size(100, 20)
.message("press me")
.action(JavaWrapper.methodToJava(function (button) {
Chat.log("clicked");
}))
.build();
}));
Hud.openScreen(screen);checkBoxBuilder
build() adds the checkbox here; this overload starts unchecked. const screen = Hud.createScreen("a screen", true);
screen.setOnInit(JavaWrapper.methodToJava(function (self) {
self.checkBoxBuilder()
.pos(10, 20)
.size(20, 20)
.message("enabled")
.build();
}));
Hud.openScreen(screen);checked. const screen = Hud.createScreen("a screen", true);
screen.setOnInit(JavaWrapper.methodToJava(function (self) {
self.checkBoxBuilder(true)
.pos(10, 20)
.size(20, 20)
.message("on by default")
.build();
}));
Hud.openScreen(screen);Parameters:
checked: whether the checkbox should be checked by default
close
const screen = Hud.createScreen("a screen", true);
screen.setOnInit(JavaWrapper.methodToJava(function (self) {
self.addButton(10, 20, 100, 20, "close", JavaWrapper.methodToJava(function (button) {
self.close();
}));
}));
Hud.openScreen(screen);cyclicButtonBuilder
cyclicButtonBuilder(MethodWrapper<Object, ?, TextHelper, ?> valueToText): CyclingButtonWidgetHelper.CyclicButtonBuilder<?>Since1.8.4#const screen = Hud.createScreen("a screen", true);
screen.setOnInit(JavaWrapper.methodToJava(function (self) {
self.cyclicButtonBuilder(JavaWrapper.methodToJava(function (value) {
return Chat.createTextHelperFromString(String(value));
}))
.pos(10, 20)
.size(100, 20)
.values(["low", "medium", "high"])
.initially("low")
.build();
}));
Hud.openScreen(screen);Parameters:
valueToText: turns a value into the text shown on the button
getButtonWidgets
Button widgets among the screen's children. Script-added helpers are reused; other buttons receive new wrappers on each call.getOnClose
null if none was set. This is the callback itself; invoking it manually runs the callback but does not itself close the screen.null if there is nonegetScreenClassName
getTextFields
EditBox widgets among the screen's children. Script-added helpers are reused; other fields receive new wrappers on each call.getTitleText
isAltDown
isCtrlDown
isShiftDown
lockButtonBuilder
locked. The button has a fixed size.Parameters:
locked: whether the lock button should be locked by default
reloadScreen
const screen = Hud.createScreen("a screen", true);
screen.setOnInit(JavaWrapper.methodToJava(function (self) {
self.addText("rebuilt", 10, 10, Color.rgb(0xFF, 0xFF, 0xFF), true);
}));
Hud.openScreen(screen);
// the widgets are laid out again from scratch
screen.reloadScreen();setOnCharTyped
const screen = Hud.createScreen("a screen", true);
screen.setOnCharTyped(JavaWrapper.methodToJava(function (chr, modifiers) {
Chat.log(`typed ${chr}`);
}));
Hud.openScreen(screen);Parameters:
onCharTyped: calls your method as a BiConsumer<Character, Integer>
setOnClose
const screen = Hud.createScreen("a screen", true);
screen.setOnClose(JavaWrapper.methodToJava(function (closing) {
Chat.log(`closed ${closing.getTitleText()}`);
}));
Hud.openScreen(screen);Parameters:
setOnKeyPressed
KeyBind to refer to named keys. Codes are GLFW key codes on older targets and SDL physical key codes on Minecraft 26.3 and later. Modifier bits remain shift=1, control=2, alt=4, and super=8 on every target. This callback does not consume the key; game handling may still occur. const screen = Hud.createScreen("a screen", true);
screen.setOnKeyPressed(JavaWrapper.methodToJava(function (key, modifiers) {
Chat.log(`key ${key} with modifiers ${modifiers}`);
}));
Hud.openScreen(screen);Parameters:
onKeyPressed: calls your method as a BiConsumer<Integer, Integer>
setOnMouseDown
const screen = Hud.createScreen("a screen", true);
screen.setOnMouseDown(JavaWrapper.methodToJava(function (pos, button) {
Chat.log(`button ${button} at ${pos}`);
}));
Hud.openScreen(screen);Parameters:
onMouseDown: calls your method as a BiConsumer<Pos2D, Integer>
setOnMouseDrag
const screen = Hud.createScreen("a screen", true);
screen.setOnMouseDrag(JavaWrapper.methodToJava(function (from, button) {
Chat.log(`dragging with ${button}, now at ${from.getEnd()}`);
}));
Hud.openScreen(screen);Parameters:
onMouseDrag: calls your method as a BiConsumer<Vec2D, Integer>
setOnMouseUp
const screen = Hud.createScreen("a screen", true);
screen.setOnMouseUp(JavaWrapper.methodToJava(function (pos, button) {
Chat.log(`released ${button} at ${pos}`);
}));
Hud.openScreen(screen);Parameters:
onMouseUp: calls your method as a BiConsumer<Pos2D, Integer>
setOnScroll
const screen = Hud.createScreen("a screen", true);
screen.setOnScroll(JavaWrapper.methodToJava(function (pos, amount) {
Chat.log(`scrolled by ${amount.getX()} across and ${amount.getY()} up`);
}));
Hud.openScreen(screen);Parameters:
onScroll: calls your method as a BiConsumer<Pos2D, Pos2D>
sliderBuilder
initially is called, then converted to the widget's 0-to-1 value; set steps before initially when configuring both.