Skip to content

ClickableWidgetHelper ​

com.jsmacrosce.jsmacros.client.api.helper.screen.ClickableWidgetHelper

Since1.0.5

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.

js
// 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 returns
  • T: the wrapped Minecraft widget type

Constructors ​

new ClickableWidgetHelper ​

new ClickableWidgetHelper(T extends AbstractWidget btn)#
Wraps btn with z-index 0 and an empty tooltip list.

Parameters:

  • btn: the widget to wrap
new ClickableWidgetHelper(T extends AbstractWidget btn, int zIndex)#
Wraps btn with the supplied helper draw-ordering value and an empty tooltip list.

Parameters:

  • btn: the widget to wrap
  • zIndex: the helper's draw-ordering value

Fields ​

tooltips ​

tooltips: List<Component>#
Mutable tooltip components held by this helper; initially empty.

zIndex ​

zIndex: int#
The value used by this helper's screen for widget draw ordering.

Methods ​

addTooltip ​

addTooltip(Object tooltip): B extends ClickableWidgetHelper<B, T extends AbstractWidget>Since1.8.4#
appends a tooltip, preserving insertion order. TextBuilder and TextHelper values retain styling; other values are converted with toString() to plain text.

Parameters:

  • tooltip: the tooltip to add
Returns: self for chaining.

click ​

click(): B extends ClickableWidgetHelper<B, T extends AbstractWidget>Since1.3.1#
sends a left-button press and release at the widget's top-left coordinates. Off the client thread, waits for the queued input task to run; on the client thread it runs immediately.
Returns: self for chaining.
click(boolean await): B extends ClickableWidgetHelper<B, T extends AbstractWidget>Since1.3.1#
sends a left-button press and release at the widget's top-left coordinates. Off the client thread, queues the input task; 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.
Returns: self for chaining.

clickedOn ​

static clickedOn(IScreen screen): void#
Marks the next release to be skipped on a container screen. Other screen types are unchanged.
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 ​

getActive(): booleanSince1.0.5#
returns the widget's active flag. Inactive widgets reject mouse clicks; this flag does not indicate whether the button's action will succeed.
Returns: button clickable state.

getHeight ​

getHeight(): intSince1.8.4#
Returns the widget's height in pixels.
Returns: the height of the button in pixels.

getLabel ​

getLabel(): TextHelperSince1.2.3#
returns the button's label as a text wrapper, preserving its styling. Use getStringStripFormatting() on the result for plain text without formatting.
Returns: current button text.

Note: renamed fro getText in 1.3.1

getParentHeight ​

getParentHeight(): intSince1.0.5#
Returns the open screen's height for parent-relative alignment. Requires an open screen.
Returns: the height of the parent element

getParentWidth ​

getParentWidth(): intSince1.0.5#
Returns the open screen's width for parent-relative alignment. Requires an open screen.
Returns: the width of the parent element

getScaledHeight ​

getScaledHeight(): intSince1.0.5#
Returns the widget height used by alignment; this helper applies no scaling.
Returns: the scaled height of the widget

getScaledLeft ​

getScaledLeft(): intSince1.0.5#
Returns the widget's x coordinate; this helper applies no scaling.
Returns: the position of the scaled element's left side

getScaledTop ​

getScaledTop(): intSince1.0.5#
Returns the widget's top edge; this class has no scaling, so it is its y coordinate.
Returns: the top edge in screen-coordinate pixels

getScaledWidth ​

getScaledWidth(): intSince1.0.5#
Returns the widget width used by alignment; this helper applies no scaling.
Returns: the scaled width of the widget

getTooltips ​

getTooltips(): List<TextHelper>Since1.8.4#
Returns wrappers for the current tooltips in insertion order. The returned list is independent; modifying it does not change the widget.
Returns: a copy of the tooltips.

getWidth ​

getWidth(): intSince1.0.5#
Returns the widget's width in pixels.
Returns: the width of the button in pixels.

getX ​

getX(): intSince1.0.5#
Returns the widget's left edge in screen-coordinate pixels.
Returns: the x coordinate of the button.

getY ​

getY(): intSince1.0.5#
Returns the widget's top edge in screen-coordinate pixels.
Returns: the y coordinate of the button.

getZIndex ​

getZIndex(): intSince1.0.5#
Returns this helper's z-index, used by its screen for widget draw ordering.
Returns: the z-index of this widget

moveTo ​

moveTo(int x, int y): B extends ClickableWidgetHelper<B, T extends AbstractWidget>Since1.0.5#
Moves the widget to the given screen-coordinate pixel position without changing its size. This is equivalent to setPos(int, int) and supports the alignment methods.

Parameters:

  • x: the new x position
  • y: the new y position
Returns: self for chaining.

removeTooltip ​

removeTooltip(int index): booleanSince1.8.4#
Removes the tooltip at the zero-based index. An invalid index returns false; duplicate tooltips can be distinguished by their positions.

Parameters:

  • index: the index of the tooltip to remove
Returns: true if the tooltip was removed successfully, false otherwise.
removeTooltip(TextHelper tooltip): booleanSince1.8.4#
Removes the first tooltip whose underlying text component equals the supplied component. Returns false if no match exists.

Parameters:

  • tooltip: the tooltip to remove
Returns: true if the tooltip was removed successfully, false otherwise.

render ​

render(GuiGraphicsExtractor drawContext, int mouseX, int mouseY, float delta): voidSince1.0.5#
Renders the wrapped widget and requests tooltip rendering when the pointer is over it and its tooltip list is non-empty.

Parameters:

  • drawContext: the graphics the widget is drawn into
  • mouseX: the pointer's position on the x axis
  • mouseY: the pointer's position on the y axis
  • delta: how far through the current tick the drawing is

setActive ​

setActive(boolean t): B extends ClickableWidgetHelper<B, T extends AbstractWidget>Since1.0.5#
sets the widget's active flag, controlling whether it accepts mouse clicks.

Parameters:

  • t: whether the button should be clickable
Returns: self for chaining.

setLabel ​

setLabel(TextHelper helper): B extends ClickableWidgetHelper<B, T extends AbstractWidget>Since1.3.1#
Sets the label from the supplied text component, preserving its styling.

Parameters:

  • helper: the styled text to show on the button
Returns: self for chaining.

setPos ​

setPos(int x, int y): B extends ClickableWidgetHelper<B, T extends AbstractWidget>Since1.0.5#
Moves the widget to the given screen-coordinate pixel position without changing its size.

Parameters:

  • x: the new left edge
  • y: the new top edge
Returns: self for chaining.

setTooltip ​

setTooltip(Object... tooltips): B extends ClickableWidgetHelper<B, T extends AbstractWidget>Since1.8.4#
replaces the helper's tooltip list. TextBuilder and TextHelper values retain styling; other values are converted with toString() to plain text. The tooltip list is drawn while the widget is hovered.

Parameters:

  • tooltips: the tooltips to set
Returns: self for chaining.

setWidth ​

setWidth(int width): B extends ClickableWidgetHelper<B, T extends AbstractWidget>Since1.0.5#
sets the widget's width in pixels without changing its height.

Parameters:

  • width: the new width in pixels
Returns: self for chaining.

toString ​

toString(): String#
Returns a diagnostic string containing the widget message as plain text.
Returns: a diagnostic string containing the widget message