# 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>

![](https://8383976-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fs4yG60a7UCSjUx5DT1wQ%2Fuploads%2FXWcEa1kjdFXu0DuWdjMU%2Fjava_VROI8U8sCh.png?alt=media\&token=87aa0297-db2b-4266-ac6d-bd79b16b98dc)![](https://8383976-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fs4yG60a7UCSjUx5DT1wQ%2Fuploads%2FwjxEpGaM1rS2UjBdO4F6%2Fjava_GQGtXD1SRJ.png?alt=media\&token=e5519ecb-a1d4-4ba1-936d-f16cd6871266)

</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.

![](https://8383976-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fs4yG60a7UCSjUx5DT1wQ%2Fuploads%2FIcQqGBjwyKeLQVxDnTbL%2Fjava_4DLHxyCy5h.png?alt=media\&token=7df04149-78da-4bcd-9aeb-a88743bfae1f)

</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
```

![](https://8383976-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fs4yG60a7UCSjUx5DT1wQ%2Fuploads%2FY46EjR6f6JrxOoeKRPO6%2Fjava_0tiJ9ys7yG.png?alt=media\&token=51d8c7ea-4bbe-4bca-b224-c6f077b02706)![](https://8383976-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fs4yG60a7UCSjUx5DT1wQ%2Fuploads%2FcCNDiQjO167iQAkjbe2t%2Fjava_qku1qm9wDC.png?alt=media\&token=d3f09cad-65ea-421f-b228-b6471bc7d717)![](https://8383976-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fs4yG60a7UCSjUx5DT1wQ%2Fuploads%2FWf6Tq0w5LgaAsoXT0fU9%2Fjava_ysYlg7hxGU.png?alt=media\&token=63c80f11-a0b2-4360-b29d-65dbbeab7acb)![](https://8383976-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fs4yG60a7UCSjUx5DT1wQ%2Fuploads%2F3q4reY1ZbEi5j6OdVjDa%2Fjava_wgfnQitV2T.png?alt=media\&token=6be506ff-11d6-4671-b6cc-a9669adb632a)

![](https://8383976-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fs4yG60a7UCSjUx5DT1wQ%2Fuploads%2FnzuilrUfOQXv1TLccIkb%2Fjava_33thNIC5OK.png?alt=media\&token=46f0aa94-c575-48e4-b3ab-951af673b16c)![](https://8383976-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fs4yG60a7UCSjUx5DT1wQ%2Fuploads%2Fs2CeO1EAzBgr4wS9gjaC%2Fjava_7bigpV0mxD.png?alt=media\&token=abbc9254-12ff-4f28-9d80-59d0900f2ba2)![](https://8383976-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fs4yG60a7UCSjUx5DT1wQ%2Fuploads%2F5IkNNEcEEcfOoiEV5thu%2Fjava_cnGgxbcjdi.png?alt=media\&token=266fa3bf-ce01-48d0-8097-0661e2d8e027)![](https://8383976-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fs4yG60a7UCSjUx5DT1wQ%2Fuploads%2Fl7t4I8ffIT6yUNlErJPs%2Fjava_NvztjD91sj.png?alt=media\&token=7053df46-bac5-4ff2-90ab-c38be5dfa551)

</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="https://8383976-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fs4yG60a7UCSjUx5DT1wQ%2Fuploads%2FuvgzaCopRaISHUo1RYpd%2Fjava_cFqi0yTGBc.png?alt=media&#x26;token=4d2bdcbc-28b4-4914-a313-a9e7716ef01b" 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.

![](https://8383976-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fs4yG60a7UCSjUx5DT1wQ%2Fuploads%2FCisNntGIdEoz8yDOpygZ%2Fjava_q3pKUNj5ph.png?alt=media\&token=6e967591-71a7-456e-8365-f9b5c0e6bd20)

</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))
```

![](https://8383976-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fs4yG60a7UCSjUx5DT1wQ%2Fuploads%2F7qdvm0Zed9WpMy6f2P55%2Fjava_yG4eNdRHPO.png?alt=media\&token=7c604874-6bcc-4c71-8b74-09320b7dff7c)

</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
