# Controllers

## Built-in controllers

{% hint style="warning" %}
This is an incomplete list of controllers!
{% endhint %}

There are many different built-in controllers to get you set up quickly.

<details>

<summary><code>BooleanController</code></summary>

A toggleable controller that displays a different `Text` based on the state of the option.

```java
.controller(BooleanControllerBuilder::create)
```

* `valueFormatter` parameter is a function to return `Text` based on the state of the option. *(optional)*
* `coloured` parameter is a boolean that colours the returned text red or green based on the state. *(optional)*

To pass extra parameters, you need to construct a `BooleanController` like so.

<pre class="language-java"><code class="lang-java"><strong>.controller(opt -> BooleanControllerBuilder.create(opt)
</strong><strong>        .valueFormatter(val -> val ? Component.literal("Amazing") : Component.literal("Not Amazing"))
</strong><strong>        .coloured(true))
</strong></code></pre>

![](/files/1ritFqzzDnaiWCYD9LKK)![](/files/vPfD5b7Wa6vfLsnuhXO1)

</details>

<details>

<summary><code>TickBoxController</code></summary>

A toggleable controller that displays a tick box.

```java
.controller(TickBoxControllerBuilder::create)
```

There are no optional parameters for this controller.

![](/files/cUgcAlxADiLVpjyeMRVi)

</details>

<details>

<summary><code>&#x3C;Number>SliderController</code></summary>

Replace `<Number>` with either `Double`, `Float`, `Integer` and `Long`.

Slider controllers take a minimum, a maximum and a step for the slider in their respected number types.

```java
.controller(opt -> FloatSliderController.create(opt)
        .range(0, 10)
        .step(1)
        .valueFormatter(val -> Component.literal(val + " ticks"))) // sliders can also take a formatter
```

![](/files/Rl3d8vQUoJW5NpKm24ux)![](/files/xtWH1gPQ1uhDF7tB4Jhf)![](/files/Xe6SnUwewHMzZTxXZmdn)![](/files/NWkzPfXJy0OMVHwW00Yx)

![](/files/V9zSaNnSD7jx2WcBrv4Q)![](/files/Y8axWC4kudTS8trIOMhx)![](/files/adNHl5Gge0BZJu43znQZ)![](/files/do9BomEnanvh5wERDM3z)

</details>

<details>

<summary><code>EnumController</code></summary>

A controller that allows you to cycle through Enum constants.

```java
.controller(opt -> EnumControllerBuilder.create(opt)
        .enumClass(Alphabet.class))
```

Enums can implement the `NameableEnum` interface to automatically name each constant without a value formatter function.

```java
public enum Alphabet implements NameableEnum {
    A,
    B,
    C;
    
    @Override
    public Component getDisplayName() {
        return Component.translatable("mymod.alphabet." + name().toLowerCase());
    }
}
```

Or alternatively, just pass a `valueFormatter` to the controller as usual;

```java
.controller(opt -> EnumControllerBuilder.create(opt)
        .enumClass(Alphabet.class)
        .valueFormatter(v -> Component.translatable("mymod.alphabet." + v.name().toLowerCase())))
```

<img src="/files/6pd7a0wxydj544nfX0Vb" alt="" data-size="original">

</details>

<details>

<summary><code>StringController</code></summary>

An input box that allows users to input text as a `String`. This allows for highlighting text with the keyboard and strings that are longer than the option itself, similarly to Minecraft's `EditBox`

```java
.controller(StringControllerBuilder::create)
```

This controller has no arguments, though its functionality can be extended by creating your own controller, implementing `IStringController`, more on this here.

![](/files/9WaIosIOdKj8KW0Tzvq6)

</details>

<details>

<summary><code>ColorController</code></summary>

A controller that allows users to input colors as RGB hex format, with a preview.

```java
.controller(ColorControllerBuilder::create)
```

* `allowAlpha` parameter adds an alpha channel to the hex format as RGBA.

```java
.controller(opt -> ColorControllerBuilder.create(opt)
        .alpha(true))
```

![](/files/fEVk4Knflus7sGSVIygI)

</details>

<details>

<summary><code>&#x3C;Number>FieldController</code></summary>

Replace `<Number>` with either `Double`, `Float`, `Long` or `Integer`.

Similar to [`StringController`](#stringcontroller),  but forces a number format, doubles and floats allow decimals, but longs and integers do not.

```java
.controller(<Number>SliderControllerBuilder::create)
```

It also has a optional range where you can specify the upper and lower bound if necessary. And like usual has a value formatter.

```java
.controller(opt -> <Number>SliderControllerBuilder.create(opt)
        .min(0).max(10)
        .valueFormatter(...))
```

</details>

## Creating a custom Controller


---

# Agent Instructions: 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:

```
GET https://docs.isxander.dev/yet-another-config-lib/gui-builder/controllers.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
