Skip to content

Text ​

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

Since1.0.5

A positioned text element with colour, shadow, scale, and rotation.

Text may be plain or carry styling, hover text, and click actions through TextHelper. Its font-measured width is cached when created and refreshed by setText; assigning text directly does not refresh it.

Alignment uses scaled dimensions. A screen overlay can use this element's text interactions, while a plain overlay does not provide mouse input.

js
const draw = Hud.createDraw2D();  
const label = draw.addText("hello", 10, 10, Color.rgb(0xFF, 0xFF, 0xFF), true);  
draw.register();  
Chat.log(`${label.getWidth()} wide, ${label.getHeight()} tall, as the font measures it`);

Available in scripts as RenderElements.Text.

Nested types ​

Constructors ​

new Text ​

new Text(String text, int x, int y, int color, int zIndex, boolean shadow, double scale, float rotation)#
makes a text element from a literal string and measures its width with the game's font. The rotation is wrapped to a single turn. A string has no styling, hover text, or click action; use TextHelper for those.

Parameters:

  • text: what to draw
  • x: the x position
  • y: the y position
  • color: the colour, with the alpha in the top byte
  • zIndex: the z-index against the other elements on the overlay
  • shadow: whether to draw the game's drop shadow behind the glyphs
  • scale: the scale to apply
  • rotation: the rotation in degrees, folded into a single turn
new Text(TextHelper text, int x, int y, int color, int zIndex, boolean shadow, double scale, float rotation)#
makes a text element from a helper's text, preserving its styling, hover text, and click actions, and measures its width with the game's font. The rotation is wrapped to a single turn.

Parameters:

  • text: what to draw, with its styling
  • x: the x position
  • y: the y position
  • color: the colour, with the alpha in the top byte
  • zIndex: the z-index against the other elements on the overlay
  • shadow: whether to draw the game's drop shadow behind the glyphs
  • scale: the scale to apply
  • rotation: the rotation in degrees, folded into a single turn

Fields ​

color ​

color: int#
the packed tint, with alpha in the top byte. A value without alpha is made opaque unless it is pure black.

parent ​

parent: IDraw2D<?>#
the overlay this text belongs to, or null if unbound. Parent dimensions then come from the window.

rotateCenter ​

rotateCenter: boolean#
whether rotation is about the text's center. Directly constructed text defaults to false; builder-created text defaults to true.

rotation ​

rotation: float#
the rotation in degrees, folded by constructors and setRotation(double) into the range -180 to 180. The builder retains its unfurled value.

scale ​

scale: double#
the scale applied to this text and its dimensions. Builder-created text defaults to 1; constructors take the scale as an argument. Negative values are accepted by the element but not by its builder.

shadow ​

shadow: boolean#
whether the game's font draws a drop shadow behind the glyphs.

text ​

the text to draw. Assigning this field directly does not update the cached width; use setText to update both.

width ​

width: int#
the cached font-measured width, set on construction and refreshed by setText. Direct assignment to text leaves this value unchanged.

x ​

x: int#
the x coordinate where the text line starts.

y ​

y: int#
the y coordinate at the top of the text line.

zIndex ​

zIndex: int#
the order of this text among elements on its overlay; lower values draw first.

Methods ​

getColor ​

getColor(): intSince1.8.4#
Returns the packed tint, with alpha in the top byte; this is separate from colors carried by the text's styling.
Returns: the color of this text.

getHeight ​

getHeight(): intSince1.8.4#
Returns the font's unscaled line height, independent of this element's text.
Returns: the height of this text.

getParentHeight ​

getParentHeight(): int#
Returns the bound overlay's height, or the window's GUI-scaled height when unbound.
Returns: the height of the parent

getParentWidth ​

getParentWidth(): int#
Returns the bound overlay's width, or the window's GUI-scaled width when unbound.
Returns: the width of the parent

getRotation ​

getRotation(): floatSince1.8.4#
Returns this text's rotation in degrees, wrapped into the range -180 to 180 by its constructor and setter; the builder retains its unwrapped value.
Returns: the rotation of this text.

getScale ​

getScale(): doubleSince1.8.4#
Returns this text's scale.
Returns: the scale of this text.

getScaledHeight ​

getScaledHeight(): int#
Returns the font line height multiplied by the scale and truncated toward zero.
Returns: the scaled height of this element

getScaledLeft ​

getScaledLeft(): int#
Returns this text's x position; scaling does not change its left edge.
Returns: the position of the scaled element's left side

getScaledTop ​

getScaledTop(): int#
Returns this text's y position; scaling does not change its top edge.
Returns: the position of the scaled element's top side

getScaledWidth ​

getScaledWidth(): int#
Returns the cached font-measured width multiplied by scale and truncated toward zero. Alignment uses this scaled width.
Returns: the scaled width of this element

getText ​

getText(): TextHelperSince1.2.7#
Returns a helper wrapping the displayed text without copying it; changes made through the helper affect this element's text.
Returns: a helper wrapping what is drawn

getWidth ​

getWidth(): intSince1.0.5#
Returns the cached, unscaled font-measured width. It is updated when the text is set, not when this getter is called; direct assignment to text leaves it unchanged.
Returns: the width of the text.

getX ​

getX(): intSince1.8.4#
returns the x position where the text line starts; scaling does not change it.
Returns: the x position of this element.

getY ​

getY(): intSince1.8.4#
returns the y position at the top of the text line; scaling does not change it.
Returns: the y position of this element.

getZIndex ​

getZIndex(): int#
Returns this text's ordering value among elements on its overlay; lower values draw first.
Returns: the z-index of this element

hasShadow ​

hasShadow(): booleanSince1.8.4#
Returns whether the game's font draws a drop shadow behind this text.
Returns: true if this text element is rendered with a shadow, false otherwise.

isRotatingCenter ​

isRotatingCenter(): booleanSince1.8.4#
Whether rotation is about the text's center rather than its positioned top-left corner.
Returns: true if this text should be rotated around its center, false otherwise.

moveTo ​

moveTo(int x, int y): Text#
Sets this text's position; the text is not remeasured or resized.

Parameters:

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

render ​

render(GuiGraphics drawContext, int mouseX, int mouseY, float delta): void#
Draws this text with its position, scale, rotation, tint, and shadow. The overlay or screen calls this method; the mouse coordinates and frame delta are unused.

Parameters:

  • drawContext: the graphics context to draw into
  • mouseX: the mouse x, not used by this element
  • mouseY: the mouse y, not used by this element
  • delta: the frame delta, not used by this element

setColor ​

setColor(int color): TextSince1.8.4#
Sets the packed tint for the text. A zero alpha byte is made opaque when the RGB value is nonzero; pure black remains transparent.

Parameters:

  • color: the new color for this text element
Returns: self for chaining.

setParent ​

setParent(IDraw2D<?> parent): Text#
Sets the overlay used for parent-relative dimensions. A null parent makes those dimensions come from the window; builders bind text to their originating overlay.

Parameters:

  • parent: the overlay this element is on, or null for the window
Returns: self for chaining.

setPos ​

setPos(int x, int y): TextSince1.0.5#
sets both position coordinates without changing the text.

Parameters:

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

setRotateCenter ​

setRotateCenter(boolean rotateCenter): TextSince1.8.4#
Sets whether rotation is about the text's center rather than its positioned top-left corner. Directly constructed text defaults to false; builder-created text defaults to true.

Parameters:

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

setRotation ​

setRotation(double rotation): TextSince1.0.5#
Sets this text's rotation in degrees, wrapping the stored value into the range -180 to 180.

Parameters:

  • rotation: the angle in degrees
Returns: self for chaining.

setScale ​

setScale(double scale): TextSince1.0.5#
Sets this text's scale without remeasuring its cached width. Zero is rejected; negative values are accepted, unlike in the builder.

Parameters:

  • scale: the scale to apply
Returns: self for chaining.

setShadow ​

setShadow(boolean shadow): TextSince1.8.4#
Sets whether the game's font draws a drop shadow behind the glyphs.

Parameters:

  • shadow: whether the text should be rendered with a shadow
Returns: self for chaining.

setText ​

setText(String text): TextSince1.0.5#
replaces the text with a literal string and updates its remembered font-measured width. Any existing styling, hover text, and click actions are discarded.

Parameters:

  • text: what to draw
Returns: self for chaining.
setText(TextHelper text): TextSince1.2.7#
Replaces the displayed text with the helper's text, preserving its styling and updating the cached font-measured width.

Parameters:

  • text: what to draw, with its styling
Returns: self for chaining.

setX ​

setX(int x): TextSince1.8.4#
sets the x position without changing the y position or text.

Parameters:

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

setY ​

setY(int y): TextSince1.8.4#
sets the y position without changing the x position or text.

Parameters:

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

setZIndex ​

setZIndex(int zIndex): TextSince1.8.4#
Sets this text's ordering value among elements on its overlay; lower values draw first, and equal values retain insertion order.

Parameters:

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