Skip to content

AbstractWidgetBuilder ​

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

Since1.8.4

Base builder for screen widgets, storing their position, size, label, state flags,
alpha, and z-index until build() creates and adds a widget to its screen.
Builders are obtained from their screen and setters return the builder for chaining.
Opening a screen clears elements added before its init callback, so build widgets inside the callback passed to IScreen.setOnInit.
Defaults are position and width zero, height 20, empty label, active and visible,
alpha 1.0, and z-index zero. Subclasses may constrain properties; for example,
button builders fix height at 20 and text-field builders use the screen font.

js
const screen = Hud.createScreen("a screen", true);  
screen.setOnInit(JavaWrapper.methodToJava(function (self) {
 // the shared half on its own: a label, a box and the flags
 self.buttonBuilder()
    .pos(10, 20)
    .size(100, 20)
    .message("a button")
    .visible(true)
    .active(true)
    .alpha(0.8)
    .zIndex(5)
    .build();  
}));  
Hud.openScreen(screen);

Type Parameters ​

  • B: the builder class itself, so a chain keeps its own type
  • T: the kind of game widget this builder makes
  • U: the kind of widget helper this builder hands back

Methods ​

active ​

active(boolean active): B extends AbstractWidgetBuilder<B, T extends AbstractWidget, U extends ClickableWidgetHelper<U, T extends AbstractWidget>>Since1.8.4#
Sets whether the built widget is active. Inactive widgets cannot be interacted with; this flag does not determine whether an active widget's action does anything.

Parameters:

  • active: whether the widget should be active or not
Returns: self for chaining.

alpha ​

alpha(double alpha): B extends AbstractWidgetBuilder<B, T extends AbstractWidget, U extends ClickableWidgetHelper<U, T extends AbstractWidget>>Since1.8.4#
Sets the widget's alpha, clamped to the range 0.0 (transparent) through 1.0 (opaque).

Parameters:

  • alpha: the alpha value of the widget
Returns: self for chaining.

build ​

build(): U extends ClickableWidgetHelper<U, T extends AbstractWidget>Since1.8.4#
Creates the widget with the builder's properties, applies its alpha, active and visible flags, and adds it to the screen associated with this builder. Each call creates and adds a new widget.
Returns: the build widget for the set properties.

getAlpha ​

getAlpha(): floatSince1.8.4#
Returns the alpha applied to the widget when built, from 0.0 (transparent) to 1.0 (opaque); the default is 1.0.
Returns: the alpha value of the widget.

getHeight ​

getHeight(): intSince1.8.4#
Returns the height configured on this builder, initially 20.
Returns: the height of the widget.

getMessage ​

getMessage(): TextHelperSince1.8.4#
Returns the configured label as a text helper. It is empty until a label is set.
Returns: the message of the widget or an empty text if none is set.

getParentHeight ​

getParentHeight(): intSince1.8.4#
Returns the height reported by the screen associated with this builder, used as the parent extent for alignment.
Returns: the height of the parent element

getParentWidth ​

getParentWidth(): intSince1.8.4#
Returns the width reported by the screen associated with this builder, used as the parent extent for alignment.
Returns: the width of the parent element

getScaledHeight ​

getScaledHeight(): intSince1.8.4#
Returns the builder's configured height, used for alignment even before the widget is built.
Returns: the scaled height of the element

getScaledLeft ​

getScaledLeft(): intSince1.8.4#
Returns the builder's current x coordinate for alignment.
Returns: the position of the scaled element's left side

getScaledTop ​

getScaledTop(): intSince1.8.4#
Returns the builder's current y coordinate for alignment.
Returns: the position of the scaled element's top side

getScaledWidth ​

getScaledWidth(): intSince1.8.4#
Returns the builder's configured width, used for alignment even before the widget is built.
Returns: the scaled width of the element

getWidth ​

getWidth(): intSince1.8.4#
Returns the width configured on this builder; it is not read from a built widget.
Returns: the width of the widget.

getX ​

getX(): intSince1.8.4#
Returns the builder's configured x coordinate, initially zero.
Returns: the x position of the widget.

getY ​

getY(): intSince1.8.4#
Returns the builder's configured y coordinate, initially zero.
Returns: the y position of the widget.

getZIndex ​

getZIndex(): intSince1.8.4#
Returns this builder's z-index, initially zero.
Returns: the z-index of the widget.

height ​

height(int height): B extends AbstractWidgetBuilder<B, T extends AbstractWidget, U extends ClickableWidgetHelper<U, T extends AbstractWidget>>Since1.8.4#
Sets the configured height; subclasses with fixed heights may override this setter.

Parameters:

  • height: the height of the widget
Returns: self for chaining.

isActive ​

isActive(): booleanSince1.8.4#
Returns whether this builder's widget is active; the default is true.
Returns: true if the widget is active, false otherwise.

isVisible ​

isVisible(): booleanSince1.8.4#
Returns whether the builder is set to create a visible widget; the default is true. The built widget has no corresponding visibility reader.
Returns: true if the widget is visible, false otherwise.

message ​

message(String message): B extends AbstractWidgetBuilder<B, T extends AbstractWidget, U extends ClickableWidgetHelper<U, T extends AbstractWidget>>Since1.8.4#
Sets the label from a literal string. Passing null leaves the label unchanged.

Parameters:

  • message: the message of the widget
Returns: self for chaining.
message(TextHelper message): B extends AbstractWidgetBuilder<B, T extends AbstractWidget, U extends ClickableWidgetHelper<U, T extends AbstractWidget>>Since1.8.4#
Sets the label from a text helper, preserving its component styling. Passing null leaves the label unchanged.

Parameters:

  • message: the message of the widget
Returns: self for chaining.

moveTo ​

moveTo(int x, int y): B extends AbstractWidgetBuilder<B, T extends AbstractWidget, U extends ClickableWidgetHelper<U, T extends AbstractWidget>>Since1.8.4#
Sets the builder's position, equivalent to pos(int, int). Alignment methods use this operation; it does not resize the eventual widget.

Parameters:

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

pos ​

pos(int x, int y): B extends AbstractWidgetBuilder<B, T extends AbstractWidget, U extends ClickableWidgetHelper<U, T extends AbstractWidget>>Since1.8.4#
Sets both configured coordinates.

Parameters:

  • x: the x position of the widget
  • y: the y position of the widget
Returns: self for chaining.

size ​

size(int width, int height): B extends AbstractWidgetBuilder<B, T extends AbstractWidget, U extends ClickableWidgetHelper<U, T extends AbstractWidget>>Since1.8.4#
Sets both configured dimensions. Subclasses may override this to constrain a dimension.

Parameters:

  • width: the width of the widget
  • height: the height of the widget
Returns: self for chaining.

visible ​

visible(boolean visible): B extends AbstractWidgetBuilder<B, T extends AbstractWidget, U extends ClickableWidgetHelper<U, T extends AbstractWidget>>Since1.8.4#
Sets whether the created widget is visible; unlike active, this controls drawing. The value is applied during build() and has no built-widget setter.

Parameters:

  • visible: whether the widget should be visible or not
Returns: self for chaining.

width ​

width(int width): B extends AbstractWidgetBuilder<B, T extends AbstractWidget, U extends ClickableWidgetHelper<U, T extends AbstractWidget>>Since1.8.4#
Sets the configured width. Subclasses may constrain other dimensions independently.

Parameters:

  • width: the width of the widget
Returns: self for chaining.

x ​

x(int x): B extends AbstractWidgetBuilder<B, T extends AbstractWidget, U extends ClickableWidgetHelper<U, T extends AbstractWidget>>Since1.8.4#
Sets the widget's configured x coordinate; this builder does not constrain it to the screen.

Parameters:

  • x: the x position of the widget
Returns: self for chaining.

y ​

y(int y): B extends AbstractWidgetBuilder<B, T extends AbstractWidget, U extends ClickableWidgetHelper<U, T extends AbstractWidget>>Since1.8.4#
Sets the builder's y coordinate; this builder does not constrain it to the screen.

Parameters:

  • y: the y position of the widget
Returns: self for chaining.

zIndex ​

zIndex(int zIndex): B extends AbstractWidgetBuilder<B, T extends AbstractWidget, U extends ClickableWidgetHelper<U, T extends AbstractWidget>>Since1.8.4#
Sets the z-index used when creating the widget.

Parameters:

  • zIndex: the z-index of the widget
Returns: self for chaining.