Text
com.jsmacrosce.jsmacros.client.api.classes.render.components.Text
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 drawx: the x positiony: the y positioncolor: the colour, with the alpha in the top bytezIndex: the z-index against the other elements on the overlayshadow: whether to draw the game's drop shadow behind the glyphsscale: the scale to applyrotation: 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 stylingx: the x positiony: the y positioncolor: the colour, with the alpha in the top bytezIndex: the z-index against the other elements on the overlayshadow: whether to draw the game's drop shadow behind the glyphsscale: the scale to applyrotation: 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
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
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
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
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
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
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
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
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
returns the x position where the text line starts; scaling does not change it.
Returns: the x position of this element.
getY
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
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
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
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 intomouseX: the mouse x, not used by this elementmouseY: the mouse y, not used by this elementdelta: the frame delta, not used by this element
setColor
setParent
setPos
setRotateCenter
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
setScale
setShadow
setText
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.
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.