Skip to content

Text.Builder ​

com.jsmacrosce.jsmacros.client.api.classes.render.components.Text.Builder

Since1.8.4

Builds a text element for an overlay. Text can be supplied as a literal string,
a TextHelper retaining its styling, or a TextBuilder whose result is used. Defaults are position (0, 0), empty text, opaque white, scale 1, rotation 0, and no shadow; builder-created text rotates about its center by default.

js
const draw = Hud.createDraw2D();  
draw.textBuilder().text("hello").pos(10, 10).color(Color.rgb(0xFF, 0xFF, 0xFF)).buildAndAdd();  
draw.register();

Nested type declared in Text.

Constructors ​

new Text.Builder ​

new Text.Builder(IDraw2D<?> draw2D)#
Creates a text builder bound to the given overlay.

Parameters:

  • draw2D: the overlay the text will be added to

Methods ​

color ​

color(int color): Text.BuilderSince1.8.4#
Sets the text tint as a packed ARGB value. The builder stores the value as given; when built, a value with no alpha byte is made opaque.

Parameters:

  • color: the color of the text element
Returns: self for chaining.
color(int r, int g, int b): Text.BuilderSince1.8.4#
Sets an opaque tint from red, green, and blue components in the range 0–255.

Parameters:

  • r: the red component of the color
  • g: the green component of the color
  • b: the blue component of the color
Returns: self for chaining.
color(int r, int g, int b, int a): Text.BuilderSince1.8.4#
Sets the tint from red, green, blue, and alpha components, packed as ARGB.

Parameters:

  • r: the red component of the color
  • g: the green component of the color
  • b: the blue component of the color
  • a: the alpha component of the color
Returns: self for chaining.

createElement ​

createElement(): Text#
Creates a text element from this builder's settings and binds it to the originating overlay.
Returns: the new text element.

getColor ​

getColor(): intSince1.8.4#
Returns the builder's packed tint. The three-component color overload supplies alpha 255; a packed value without an alpha byte is fixed up when built.
Returns: the color of the text element.

getHeight ​

getHeight(): intSince1.8.4#
Returns the font's line height in unscaled units.
Returns: the height of the string.

getParentHeight ​

getParentHeight(): int#
Returns the height of the overlay this builder was created from.
Returns: the height of the parent

getParentWidth ​

getParentWidth(): int#
Returns the width of the overlay this builder was created from.
Returns: the width of the parent

getRotation ​

getRotation(): floatSince1.8.4#
Returns the builder's rotation in degrees before the created text wraps it; defaults to 0.
Returns: the rotation (clockwise) of the text element in degrees.

getScale ​

getScale(): doubleSince1.8.4#
Returns the scale configured for this builder; it defaults to 1.
Returns: the scale of the text element.

getScaledHeight ​

getScaledHeight(): int#
Returns the text height multiplied by scale and truncated to an integer.
Returns: the scaled height

getScaledLeft ​

getScaledLeft(): int#
Returns the text's x position, unchanged by scale.
Returns: the text's x position, unchanged by scale

getScaledTop ​

getScaledTop(): int#
Returns the text's y position, unchanged by scale.
Returns: the text's y position, unchanged by scale

getScaledWidth ​

getScaledWidth(): int#
Returns the text width multiplied by scale and truncated to an integer; alignment uses this width.
Returns: the scaled width

getText ​

getText(): TextHelperSince1.8.4#
Returns a helper for the builder's text. The helper wraps a copy, so changes to it do not affect this builder.
Returns: the content of the text element.

getWidth ​

getWidth(): intSince1.8.4#
Measures and returns the builder's text width in unscaled font units.
Returns: the width of the string.

getX ​

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

getY ​

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

getZIndex ​

getZIndex(): intSince1.8.4#
Returns the z-index configured for elements built by this builder; defaults to zero.
Returns: the z-index of the text element.

hasShadow ​

hasShadow(): booleanSince1.8.4#
Returns whether created text has the game's font shadow; defaults to false.
Returns: true if the text element has a shadow, false otherwise.

isRotatingCenter ​

isRotatingCenter(): booleanSince1.8.4#
Returns whether created text rotates about its center; defaults to true.
Returns: true if this text should be rotated around its center, false otherwise.

moveTo ​

moveTo(int x, int y): Text.Builder#
Moves the text to the given position without changing its size.

Parameters:

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

pos ​

pos(int x, int y): Text.BuilderSince1.8.4#
Sets both coordinates without changing the text.

Parameters:

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

rotateCenter ​

rotateCenter(boolean rotateCenter): Text.BuilderSince1.8.4#
Chooses whether rotation is about the text's center rather than its position.

Parameters:

  • rotateCenter: whether this text should be rotated around its center
Returns: self for chaining.

rotation ​

rotation(double rotation): Text.BuilderSince1.8.4#
Sets the rotation in degrees. The builder stores the angle as a float without wrapping it; the created text wraps it to a single turn.

Parameters:

  • rotation: the rotation (clockwise) of the text element in degrees
Returns: self for chaining.

scale ​

scale(double scale): Text.BuilderSince1.8.4#
Sets the text scale. The builder rejects zero and negative values; changing the scale does not remeasure the text.

Parameters:

  • scale: the scale of the text element
Returns: self for chaining.

shadow ​

shadow(boolean shadow): Text.BuilderSince1.8.4#
Chooses whether the game's font draws a drop shadow behind the glyphs.

Parameters:

  • shadow: whether the text should have a shadow or not
Returns: self for chaining.

text ​

text(TextHelper text): Text.BuilderSince1.8.4#
Sets the text from a helper, retaining its styling. A null value is ignored and leaves the current text unchanged.

Parameters:

  • text: the content of the text element
Returns: self for chaining.
text(TextBuilder text): Text.BuilderSince1.8.4#
Builds the supplied text builder immediately and uses its result. A null value is ignored and leaves the current text unchanged.

Parameters:

  • text: the content of the text element
Returns: self for chaining.
text(String text): Text.BuilderSince1.8.4#
Sets the text to a literal string. A null value is ignored and leaves the current text unchanged.

Parameters:

  • text: the content of the text element
Returns: self for chaining.

x ​

x(int x): Text.BuilderSince1.8.4#
Sets the x-coordinate without changing the y-coordinate.

Parameters:

  • x: the x position of the text element
Returns: self for chaining.

y ​

y(int y): Text.BuilderSince1.8.4#
Sets the y-coordinate without changing the x-coordinate.

Parameters:

  • y: the y position of the text element
Returns: self for chaining.

zIndex ​

zIndex(int zIndex): Text.Builder#
Sets the z-index used to order this text relative to other overlay elements.

Parameters:

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