ClickableWidgetHelper
com.jsmacrosce.jsmacros.client.api.helper.screen.ClickableWidgetHelper
Wraps a game widget so scripts can inspect and control it; other widget helpers extend this base. Use the Widgets types, such as Widgets.Button and Widgets.Slider, to identify a specific widget helper.
Each helper refers to its wrapped widget, so changes through a helper affect that widget. Screens may return new helpers for the same widget on separate queries.
Tooltips and zIndex are held by the helper for JsMacros' rendering; the wrapped widget state comes from the game.
A script builds its own widgets with a builder rather than by hand: IScreen.buttonBuilder() and its siblings hand back a builder whose build() puts the widget on the screen and gives the helper to go on with. Because opening a screen clears earlier elements, build widgets inside IScreen.setOnInit.
// a button on a screen of the script's own
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 (btn) {
// the callback is given the button, so it can change the button
btn.setLabel("pressed");
btn.setActive(false);
}))
.build();
// and the same button widget, wrapped as the screen hands it over
for (const widget of self.getButtonWidgets()) {
if (!(widget instanceof Widgets.Button)) continue;
Chat.log(`button ${widget.getLabel()} at ${widget.getX()}, ${widget.getY()}`);
}
}));
Hud.openScreen(screen);Available in scripts as Widgets.Clickable.
Type Parameters
B: the concrete helper type, used for fluent method returnsT: the wrapped Minecraft widget type
Constructors
new ClickableWidgetHelper
new ClickableWidgetHelper(T extends AbstractWidget btn)#btn with z-index 0 and an empty tooltip list.Parameters:
btn: the widget to wrap
new ClickableWidgetHelper(T extends AbstractWidget btn, int zIndex)#btn with the supplied helper draw-ordering value and an empty tooltip list.Parameters:
btn: the widget to wrapzIndex: the helper's draw-ordering value
Fields
tooltips
zIndex
zIndex: int#Methods
addTooltip
toString() to plain text.Parameters:
tooltip: the tooltip to add
click
await controls whether this call waits for that task. On the client thread, the input runs immediately and the flag has no effect.Parameters:
await: should wait for button to finish clicking.
clickedOn
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 (btn) {
Widgets.Clickable.clickedOn(self);
}))
.build();
}));
Hud.openScreen(screen);Parameters:
screen: the screen the widget belongs to
getActive
getHeight
getLabel
getStringStripFormatting() on the result for plain text without formatting.getParentHeight
getParentWidth
getScaledHeight
getScaledLeft
x coordinate; this helper applies no scaling.getScaledTop
y coordinate.getScaledWidth
getTooltips
getWidth
getX
x coordinate of the button.getY
y coordinate of the button.getZIndex
moveTo
Parameters:
x: the new x positiony: the new y position
removeTooltip
false; duplicate tooltips can be distinguished by their positions.Parameters:
index: the index of the tooltip to remove
true if the tooltip was removed successfully, false otherwise.false if no match exists.Parameters:
tooltip: the tooltip to remove
true if the tooltip was removed successfully, false otherwise.render
Parameters:
drawContext: the graphics the widget is drawn intomouseX: the pointer's position on the x axismouseY: the pointer's position on the y axisdelta: how far through the current tick the drawing is
setActive
Parameters:
t: whether the button should be clickable
setLabel
setLabel(TextHelper helper): B extends ClickableWidgetHelper<B, T extends AbstractWidget>Since1.3.1#Parameters:
helper: the styled text to show on the button
setPos
Parameters:
x: the new left edgey: the new top edge
setTooltip
setTooltip(Object... tooltips): B extends ClickableWidgetHelper<B, T extends AbstractWidget>Since1.8.4#toString() to plain text. The tooltip list is drawn while the widget is hovered.Parameters:
tooltips: the tooltips to set
setWidth
Parameters:
width: the new width in pixels