> For the complete documentation index, see [llms.txt](https://docs.quickclient.cc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.quickclient.cc/en/ui/text.md).

# Styled text

Text with colors, styles and gradients, plus your own fonts.

`Text` lets you style parts of a line differently: for example, show the target name with a gradient and the health in green. If the built-in fonts are not enough, you can add your own.

## Text

`Text` is built from parts, and each part can have its own color, style or gradient. The same text can be both sent to chat and drawn on screen. Color and styles apply to the last added part, so put them right after `append`.

```java
Text line = Text.of("target: ").color(0xFF8A8A8A)
        .append(target.name()).gradient(0xFF41C4C8, 0xFF8A5CF6).bold()
        .append(" " + (int) target.health() + " hp").color(0xFF57D977);

chat().print(line);
render.drawText("sf_rounded_semibold", line, 10f, 10f, 7f, 0f);
```

How it works:

* "target:" is gray, the target name is bold with a gradient, the health is green.
* The same line is printed to chat and drawn on screen, there is no need to build it twice.

| Method                                                     | Type      | Description                                                                                   |
| ---------------------------------------------------------- | --------- | --------------------------------------------------------------------------------------------- |
| `Text.of(value)`                                           | `Text`    | start building with the first part                                                            |
| `Text.empty()`                                             | `Text`    | empty text                                                                                    |
| `append(value)`                                            | `Text`    | add a part                                                                                    |
| `append(other)`                                            | `Text`    | append the parts of another text together with their styling                                  |
| `color(argb)`                                              | `Text`    | color the last part                                                                           |
| `gradient(from, to)`                                       | `Text`    | moving gradient on the last part                                                              |
| `gradient(from, to, power, speed)`                         | `Text`    | `power` is the wavelength in characters, `speed` is the speed, at 0 the gradient stands still |
| `bold()`, `italic()`, `underline()`, `strike()`, `magic()` | `Text`    | styles of the last part                                                                       |
| `value(value)`                                             | `Text`    | replace the text of the last part, the styling stays                                          |
| `string()`                                                 | `String`  | plain text without styling                                                                    |
| `parts()`                                                  | `int`     | number of parts                                                                               |
| `partText(i)`, `partColor(i)`                              | none      | access to parts if you draw them yourself                                                     |
| `animated()`                                               | `boolean` | has a moving gradient, so the line needs to be drawn every frame                              |

Quick itself also returns styled text: `Entity.displayName()`, `Scoreboard.lineText(i)`, `Tab.teamPrefixText(team)`, `ChatEvent.text()`.

## Fonts

Quick draws text with MSDF fonts. `sf_rounded_bold`, `sf_rounded_semibold` and `sf_rounded_medium` are built in. Your own font consists of two files in `resources/` of the script jar: `name.png` (atlas) and `name.json` (layout). Quick copies them into the pack and reloads resources.

```java
private final FontFace title = fonts().register("title", "fonts/title");

@Override
public void onRender2D(Render2D render) {
    if (!title.ready()) return;
    render.drawText(title.name(), "quick", 8f, 8f, 7f, 0f, 0xFF41C4C8);
}
```

### FontRegistry

| Method                      | Type       | Description                                                                             |
| --------------------------- | ---------- | --------------------------------------------------------------------------------------- |
| `names()`                   | `String[]` | built-in fonts and your own ones you have already registered                            |
| `of(name)`                  | `FontFace` | handle to a known font; for an unknown one `ready()` returns `false`                    |
| `register(name, assetPath)` | `FontFace` | takes the `assetPath.png/.json` pair from `resources/` and registers it under this name |
| `error(name)`               | `String`   | why the font failed to load, or `null`                                                  |

### FontFace

| Method              | Type      | Description                                                         |
| ------------------- | --------- | ------------------------------------------------------------------- |
| `name()`            | `String`  | the name you pass to `drawText`                                     |
| `width(text, size)` | `float`   | width of a string                                                   |
| `height(size)`      | `float`   | line height                                                         |
| `ready()`           | `boolean` | whether the font has loaded; while `false`, it is too early to draw |
| `error()`           | `String`  | error text or `null`                                                |

Register fonts in the constructor or right in a field. If the files did not change, they are not rewritten, but you still have to wait for `ready()` on the first frame. You can make the atlas and layout with `msdf-atlas-gen` using the `mtsdf` type and the Y axis pointing up from the bottom.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.quickclient.cc/en/ui/text.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
