Text.Builder
com.jsmacrosce.jsmacros.client.api.classes.render.components.Text.Builder
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
Methods
color
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.
Sets an opaque tint from red, green, and blue components in the range 0–255.
Parameters:
r: the red component of the colorg: the green component of the colorb: the blue component of the color
Returns: self for chaining.
Sets the tint from red, green, blue, and alpha components, packed as ARGB.
Parameters:
r: the red component of the colorg: the green component of the colorb: the blue component of the colora: the alpha component of the color
Returns: self for chaining.
createElement
getColor
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
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
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
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
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
Measures and returns the builder's text width in unscaled font units.
Returns: the width of the string.
getX
Returns the builder's x-coordinate, initially zero.
Returns: the x position of the text element.
getY
Returns the builder's y-coordinate, initially zero.
Returns: the y position of the text element.
getZIndex
Returns the z-index configured for elements built by this builder; defaults to zero.
Returns: the z-index of the text element.
hasShadow
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
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 positiony: the new y position
Returns: self for chaining.
pos
Sets both coordinates without changing the text.
Parameters:
x: the x position of the text elementy: the y position of the text element
Returns: self for chaining.
rotateCenter
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
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
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
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
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.
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.
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
Sets the x-coordinate without changing the y-coordinate.
Parameters:
x: the x position of the text element
Returns: self for chaining.
y
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.