# Text.Builder

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

**Since:** 1.8.4

Builds a text element for an overlay. Text can be supplied as a literal string,  
 a [TextHelper](../../../helper/TextHelper.md) retaining its styling, or a [TextBuilder](../../TextBuilder.md) 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](Text.md).

## Constructors

### new Text.Builder {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Text.Builder_constructor-IDraw2D-}

```js
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 {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Text.Builder_color-int-}

```js
color(int color): Text.Builder
```

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.

**Since:** 1.8.4

### color {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Text.Builder_color-int-int-int-}

```js
color(int r, int g, int b): Text.Builder
```

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.

**Since:** 1.8.4

### color {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Text.Builder_color-int-int-int-int-}

```js
color(int r, int g, int b, int a): Text.Builder
```

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.

**Since:** 1.8.4

### createElement {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Text.Builder_createElement-}

```js
createElement(): Text
```

Creates a text element from this builder's settings and binds it to the originating overlay.

**Returns:** the new text element.

### getColor {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Text.Builder_getColor-}

```js
getColor(): int
```

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.

**Since:** 1.8.4

### getHeight {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Text.Builder_getHeight-}

```js
getHeight(): int
```

Returns the font's line height in unscaled units.

**Returns:** the height of the string.

**Since:** 1.8.4

### getParentHeight {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Text.Builder_getParentHeight-}

```js
getParentHeight(): int
```

Returns the height of the overlay this builder was created from.

**Returns:** the height of the parent

### getParentWidth {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Text.Builder_getParentWidth-}

```js
getParentWidth(): int
```

Returns the width of the overlay this builder was created from.

**Returns:** the width of the parent

### getRotation {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Text.Builder_getRotation-}

```js
getRotation(): float
```

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.

**Since:** 1.8.4

### getScale {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Text.Builder_getScale-}

```js
getScale(): double
```

Returns the scale configured for this builder; it defaults to `1`.

**Returns:** the scale of the text element.

**Since:** 1.8.4

### getScaledHeight {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Text.Builder_getScaledHeight-}

```js
getScaledHeight(): int
```

Returns the text height multiplied by scale and truncated to an integer.

**Returns:** the scaled height

### getScaledLeft {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Text.Builder_getScaledLeft-}

```js
getScaledLeft(): int
```

Returns the text's x position, unchanged by scale.

**Returns:** the text's x position, unchanged by scale

### getScaledTop {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Text.Builder_getScaledTop-}

```js
getScaledTop(): int
```

Returns the text's y position, unchanged by scale.

**Returns:** the text's y position, unchanged by scale

### getScaledWidth {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Text.Builder_getScaledWidth-}

```js
getScaledWidth(): int
```

Returns the text width multiplied by scale and truncated to an integer; alignment uses this width.

**Returns:** the scaled width

### getText {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Text.Builder_getText-}

```js
getText(): TextHelper
```

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.

**Since:** 1.8.4

### getWidth {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Text.Builder_getWidth-}

```js
getWidth(): int
```

Measures and returns the builder's text width in unscaled font units.

**Returns:** the width of the string.

**Since:** 1.8.4

### getX {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Text.Builder_getX-}

```js
getX(): int
```

Returns the builder's x-coordinate, initially zero.

**Returns:** the x position of the text element.

**Since:** 1.8.4

### getY {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Text.Builder_getY-}

```js
getY(): int
```

Returns the builder's y-coordinate, initially zero.

**Returns:** the y position of the text element.

**Since:** 1.8.4

### getZIndex {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Text.Builder_getZIndex-}

```js
getZIndex(): int
```

Returns the z-index configured for elements built by this builder; defaults to zero.

**Returns:** the z-index of the text element.

**Since:** 1.8.4

### hasShadow {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Text.Builder_hasShadow-}

```js
hasShadow(): boolean
```

Returns whether created text has the game's font shadow; defaults to `false`.

**Returns:** `true` if the text element has a shadow, `false` otherwise.

**Since:** 1.8.4

### isRotatingCenter {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Text.Builder_isRotatingCenter-}

```js
isRotatingCenter(): boolean
```

Returns whether created text rotates about its center; defaults to `true`.

**Returns:** `true` if this text should be rotated around its center,  
 `false` otherwise.

**Since:** 1.8.4

### moveTo {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Text.Builder_moveTo-int-int-}

```js
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 {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Text.Builder_pos-int-int-}

```js
pos(int x, int y): Text.Builder
```

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.

**Since:** 1.8.4

### rotateCenter {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Text.Builder_rotateCenter-boolean-}

```js
rotateCenter(boolean rotateCenter): Text.Builder
```

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.

**Since:** 1.8.4

### rotation {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Text.Builder_rotation-double-}

```js
rotation(double rotation): Text.Builder
```

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.

**Since:** 1.8.4

### scale {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Text.Builder_scale-double-}

```js
scale(double scale): Text.Builder
```

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.

**Since:** 1.8.4

### shadow {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Text.Builder_shadow-boolean-}

```js
shadow(boolean shadow): Text.Builder
```

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.

**Since:** 1.8.4

### text {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Text.Builder_text-TextHelper-}

```js
text(TextHelper text): Text.Builder
```

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.

**Since:** 1.8.4

### text {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Text.Builder_text-TextBuilder-}

```js
text(TextBuilder text): Text.Builder
```

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.

**Since:** 1.8.4

### text {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Text.Builder_text-String-}

```js
text(String text): Text.Builder
```

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.

**Since:** 1.8.4

### x {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Text.Builder_x-int-}

```js
x(int x): Text.Builder
```

Sets the x-coordinate without changing the y-coordinate.

**Parameters:**
- `x`: the x position of the text element

**Returns:** self for chaining.

**Since:** 1.8.4

### y {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Text.Builder_y-int-}

```js
y(int y): Text.Builder
```

Sets the y-coordinate without changing the x-coordinate.

**Parameters:**
- `y`: the y position of the text element

**Returns:** self for chaining.

**Since:** 1.8.4

### zIndex {#com.jsmacrosce.jsmacros.client.api.classes.render.components.Text.Builder_zIndex-int-}

```js
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.
