# Interface controls

> Checkboxes, sliders, dropdowns and text fields that take your variable by reference; the widgets you keep, Godot style, with their own style and callbacks; and the events every control sends.

Source: https://omardev29.github.io/rmp-docs/manual/modules/ui-controls.html

Four controls own a value: a checkbox, a slider, a dropdown and a text field. Each one takes *your* variable, by reference, and writes to it, and that is the whole of their state model — there is no widget object holding a copy, and nothing to keep in sync. For a screen designed widget by widget there are also [widgets you keep](https://omardev29.github.io/rmp-docs/manual/modules/ui-controls.html#widgets-you-keep), each with its own style and callbacks, and every control sends [events](https://omardev29.github.io/rmp-docs/manual/modules/ui-controls.html#events).

Checkboxes, sliders, a dropdown and a text field — [examples/ui/04_settings](https://omardev29.github.io/rmp-docs/examples/ui/04_settings.html), a frame its e2e script compares exactly.

```cpp
rmp::ui::begin();
rmp::ui::checkbox("Fullscreen", settings.fullscreen);
rmp::ui::slider("Music", settings.music, 0.0f, 1.0f);
rmp::ui::dropdown("Quality", settings.quality, { "Low", "Medium", "High" });
rmp::ui::text_input("Name", settings.name);
rmp::ui::end();
```

## The state model

Every control reads your variable and writes it back in the same call, so what is on screen is what is in your struct because it was read this frame. Delete the screen and the settings still exist: they were never the interface's. The struct stays plain data, which is also what makes it easy to save:

[examples/ui/04_settings/include/settings.h](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/ui/04_settings/include/settings.h#L1-L28)

```cpp
#pragma once
// Plain data. This is the whole model, and it is the point of the example: the
// controls take a field of this, by reference, and write to it. Delete the UI
// and your settings still exist; they were never ours.

#include <array>
#include <string>
#include <string_view>

struct Settings {
    bool fullscreen = false;
    bool vsync = true;
    bool subtitles = false;
    float master = 0.8f;
    float music = 0.5f;
    float sensitivity = 0.35f;
    int quality = 1;
    int language = 0;
    std::string player; // "Player" until the player says otherwise: see _ready()
};

// What the two dropdowns offer: a std::array the dropdown takes as a span, so
// nobody has to tell it how long the list is.
inline constexpr std::array<std::string_view, 4> QUALITY{ "Low", "Medium", "High",
                                                          "Ultra" };
inline constexpr std::array<std::string_view, 3> LANGUAGE{ "English", "Espanol",
                                                           "Francais" };
```

Each control returns `true` on the frame its value changed, so "do something when it changes" reads the way it sounds:

```cpp
if (rmp::ui::checkbox("Fullscreen", cfg.fullscreen)) apply(cfg);
```

The variable stays yours: the control reads it and writes it during the call, and keeps nothing of it afterwards.

What the interface does keep is the state that means nothing to your game — whether a dropdown is open, whether a slider is being dragged — and it keeps it by the control's id, which is its label unless you give it an `id`. The rules are the ones for buttons, in [labels are ids](https://omardev29.github.io/rmp-docs/manual/modules/ui.html#labels-are-ids).

## What they have in common

Each control is a row: a slider, a dropdown and a text field put their label on the left and the control after it; a checkbox puts its box first and the label after it. The row fills the width it is offered and is focusable as one thing, so the focus ring goes around the whole row and the keyboard and gamepad reach it like a button (see [focus, keyboard and gamepad](https://omardev29.github.io/rmp-docs/manual/modules/ui.html#focus-keyboard-and-gamepad)). The label is drawn at the theme's `font_size`.

A checkbox, a dropdown and a text field count a click the way a button does: the press has to start on the control and the release end on it. A release alone is not a click, so a drag that starts in the game and ends on a settings panel ticks no box, opens no list and starts no typing. The items of an open dropdown are clicked the same way.

All four options structs have the two fields buttons have:

- **`enabled`** — `false` draws the control in the theme's disabled colours: its label in `disabled_text`, and a checkbox's box, a slider's filled part and a text field's field in `disabled`. A dropdown greys only its label and value; its field keeps the theme's `surface`. A disabled control cannot be changed, and the focus skips it. A control that is unavailable right now reads better disabled than missing: a menu whose items appear and disappear is a menu nobody can learn.
- **`id`** — a name that is the same control whatever its label says, for two controls that share a label on a screen that changes.

## Checkbox

[`rmp::ui::checkbox`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#checkbox) flips a `bool` when its row is clicked, or when it is pressed — Enter, Space, the bottom face button — while it has the focus. It returns `true` on the frame it flipped:

```cpp
if (rmp::ui::checkbox("Light theme", light))
    rmp::ui::set_theme(light ? rmp::ui::theme_light()
                             : rmp::ui::theme_dark());
```

Simple: a call each frame

```cpp
rmp::ui::Checkbox light{
    .text = "Light theme",
    .on_change = [](bool on) {
        rmp::ui::set_theme(on ? rmp::ui::theme_light()
                              : rmp::ui::theme_dark());
    },
};

void _draw() override {
    rmp::ui::begin();
    light.show();
    rmp::ui::end();
}
```

Full: a widget you keep

The box is filled with the theme's `primary` and carries a dot when the value is `true`, and is the theme's `surface` inside a `border` when it is `false` — a difference that reads at a glance without a tick, which the built-in font does not have. Its size is the theme's `control_size`. [`CheckboxOptions`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#CheckboxOptions) is [`enabled`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#CheckboxOptions-enabled) and [`id`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#CheckboxOptions-id).

## Slider

[`rmp::ui::slider`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#slider) sets a `float` between a minimum and a maximum:

```cpp
if (rmp::ui::slider("Music", music, 0.0f, 1.0f))
    rmp::audio::set_volume(rmp::audio::Bus::MUSIC, music);
rmp::ui::slider("Sensitivity", sensitivity, 0.0f, 1.0f,
                { .step = 0.05f });
```

Simple: a call each frame

```cpp
rmp::ui::Slider music{
    .text = "Music",
    .value = 0.8f,
    .on_change = [](float v) {
        rmp::audio::set_volume(rmp::audio::Bus::MUSIC, v);
    },
};
rmp::ui::Slider sensitivity{ .text = "Sensitivity",
                             .value = 0.35f, .step = 0.05f };

void _draw() override {
    rmp::ui::begin();
    music.show();
    sensitivity.show();
    rmp::ui::end();
}
```

Full: a widget you keep

- **With the pointer**, press on the rail and drag: the value follows where the pointer is along it. The area that takes the press is a little taller than the rail, which is thinner than a finger. While a drag lasts the slider holds the pointer — `wants_pointer()` stays true — even when the pointer leaves the rail.
- **With the keyboard or a gamepad**, while it has the focus, Left and Right — or the d-pad, or the left stick — move it one step per press, then twelve steps a second while held. A step is `step`, or 5 % of the range when there is none, so a controller can move a slider of any range.

The value is clamped to the range, and snapped to `step` when there is one, on every call — not only when it is touched. A variable that starts outside the range is corrected on the first frame, and the slider returns `true` for that frame like for any other change. Nothing is drawn when `max` is not above `min`.

[`SliderOptions`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#SliderOptions):

| Field | Default | Means |
|---|---|---|
| [`width`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#SliderOptions-width) | 0 | Of the rail, in design units; 0 fills the space available. |
| [`step`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#SliderOptions-step) | 0 | 0 is continuous; otherwise the value snaps to `min` plus a multiple of it. |
| [`enabled`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#SliderOptions-enabled) | `true` | As above. |
| [`show_value`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#SliderOptions-show_value) | `true` | Draw the position after the rail, as a percentage of the range. |
| [`id`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#SliderOptions-id) | none | As above. |

The number `show_value` draws is where the handle is, not the value: a slider from 0 to 60 standing at 30 shows 50%. A screen that wants the value itself turns it off and draws it with `text()`.

## Dropdown

[`rmp::ui::dropdown`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#dropdown) picks one string of a list. The value it writes is an index into that list:

```cpp
if (rmp::ui::dropdown("Quality", quality,
                      { "Low", "Medium", "High", "Ultra" }))
    apply_quality(quality);
```

Simple: a call each frame

```cpp
rmp::ui::Dropdown quality{
    .text = "Quality",
    .items = { "Low", "Medium", "High", "Ultra" },
    .selected = 1,
    .on_change = [](int index) { apply_quality(index); },
};

void _draw() override {
    rmp::ui::begin();
    quality.show();
    rmp::ui::end();
}
```

Full: a widget you keep

The list can be written in place, as there, or kept somewhere — a `std::array`, a `std::vector` or a plain array of `std::string_view` — and handed over as it is, because the dropdown takes a `std::span` of them and the span knows its length. `settings.h` above keeps its two lists that way.

A click on it opens the list, which floats over whatever is below instead of pushing it down the screen. A click on an item picks it and closes the list; a click anywhere else closes it. The return value is `true` when a different item was picked. While the list is open it is in front of everything else in the scene: `wants_pointer()` is true wherever the pointer is, and a click on the list does not reach what is behind it.

A controller has to be able to pick from a list it can open, so the keyboard and the gamepad work the whole of it. While the dropdown has the focus, Enter, Space or the bottom face button opens the list. Open and focused, the list takes the keys that would move the focus — Up and Down, the d-pad, the stick — for itself: they walk a highlight that starts on the current value and stops at the first and the last item, and once the player has used a key it lights up the way an item under the pointer does. Enter, Space or the bottom face button picks the highlighted item and closes the list, returning `true` if it is a different one; Escape or the right face button closes it and changes nothing.

The index is clamped into the list on every call, so a value read from an old save cannot point past the end of a shorter list. Nothing is drawn for an empty list. The strings are copied as they are drawn, so they only have to live through the call — which is what lets a list written in place be a temporary. [`DropdownOptions`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#DropdownOptions) is [`width`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#DropdownOptions-width) — of the field, in design units, 0 filling the space available — [`enabled`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#DropdownOptions-enabled) and [`id`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#DropdownOptions-id). Two dropdowns that both have a "Low" in them are still two lists: an item belongs to its dropdown, not to its text.

## Text field

[`rmp::ui::text_input`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#text_input) edits a `std::string` of yours, in UTF-8:

```cpp
static std::string name;
rmp::ui::text_input("Name", name,
                    { .placeholder = "your name",
                      .max_length = 16 });
```

Simple: a call each frame

```cpp
rmp::ui::TextInput name{ .text = "Name",
                         .placeholder = "your name",
                         .max_length = 16 };

void _draw() override {
    rmp::ui::begin();
    name.show(); // what is typed is name.value
    rmp::ui::end();
}
```

Full: a widget you keep

While the field is typing — which is not the same as having the focus; see [below](https://omardev29.github.io/rmp-docs/manual/modules/ui-controls.html#typing-is-having-the-keyboard) — what the player types is added at the end, any character but a control character, and Backspace removes the last character, never half of one, repeating while it is held. A blinking `_` marks the end of the text. There is no caret to move, no selection and no clipboard. Typing arrives through raylib's `GetCharPressed()`; the field does not open an on-screen keyboard on Android or iOS.

The return value is `true` on the frames the text changed. [`TextInputOptions`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#TextInputOptions):

| Field | Default | Means |
|---|---|---|
| [`width`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#TextInputOptions-width) | 0 | Of the field, in design units; 0 fills the space available. |
| [`enabled`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#TextInputOptions-enabled) | `true` | As above. |
| [`placeholder`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#TextInputOptions-placeholder) | none | Shown in the theme's `text_muted` while the field is empty and not typing. It is copied, so a temporary is fine. |
| [`id`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#TextInputOptions-id) | none | As above. |
| [`max_length`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#TextInputOptions-max_length) | 0 | The most characters it holds; 0 is no limit. |

A `max_length` counts characters, which is what a player counts: an `é` is one, not the two bytes it takes. Typing stops at it. A string longer than that — one you hand in, or one left by a `max_length` that came down — is cut to it when the field is drawn, at the end of a character, and the field returns `true` for that frame like for any other change. An empty label draws the field alone.

### Typing is having the keyboard

A field types only while it has the *keyboard*, and the keyboard is not the focus. The focus says which control Enter would press; the keyboard says which field the keys are typed into. The focus can rest on a field that is not typing, and a player who reaches a field with a controller can always leave it again.

- **It takes the keyboard** when it is clicked, when the focus is moved onto it — by Tab, Up or Down, the d-pad, or `rmp::ui::focus()` — and when Enter, Space or the bottom face button is pressed while it has the focus. The focus a screen gives its first control by itself is not one of those: a screen whose first control is a name field opens with the field focused and not typing.
- **It gives the keyboard back** on Enter or the bottom face button, on Escape or the right face button, on a press of the pointer anywhere else, and when the focus moves on. Space is typed, not taken as Enter. The focus stays on the field, so Enter again starts typing again.
- **Tab, Up and Down leave a field** like any other control, and the keyboard goes with the focus: off this field, and into the next one if that is a field too.

While a field is typing, [`rmp::ui::wants_keyboard()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#wants_keyboard) is true, and every [rmp::input](https://omardev29.github.io/rmp-docs/manual/modules/input.html) action reads its keys, gamepad buttons and sticks as not pressed; only its mouse buttons still count. Typing "Wolf" into a name field does not walk the player across the level. A field that has the focus and not the keyboard leaves them alone, so once the player presses Enter the game hears its keys again.

## A settings screen

[The settings example](https://omardev29.github.io/rmp-docs/examples/ui/04_settings.html) puts all four on one screen over the `Settings` struct above: toggles, two volume sliders that drive the audio buses, a stepped slider, two dropdowns and a name field, with Revert and Apply buttons that are disabled until something changes, and the struct saved with [`rmp::save`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-save.html) when it is applied.

```shell
rmp example 04_settings
```

## Widgets you keep

Everything above is immediate: a call each frame, and nothing to keep. That is the simple way, and the three-function menu stays exactly that. A screen that is *designed* rather than written — each button with its own look, an icon, its sounds, and something to run when it is clicked, hovered or focused — is easier to read as objects you keep, the way a Godot scene keeps its nodes: members of your scene, set up once with designated initialisers, and shown each frame where they go.

```cpp
rmp::ui::Button play{
    .text = "Play",
    .variant = rmp::ui::Variant::PRIMARY,
    .style = { .shadow = rmp::ui::Shadow{} },
    .on_click = [this] { change<GameScene>(); },
};
rmp::ui::Button quit{ .text = "Quit", .on_click = [] { rmp::app::quit(); } };

void _draw() override {
    rmp::ui::begin();
    play.show();
    quit.show();
    rmp::ui::end();
}
```

`show()` puts the widget in the layout like the immediate call of the same name — between `begin()` and `end()`, in a row, a column, a panel — and is drawn by the same code, so it lays out, navigates and is hit-tested exactly as that call is. The callbacks run inside `show()`, on the frame the thing happened, in the order it happened. A widget that is kept and not shown is not on screen and hears nothing.

- **Every field can change between frames.** `play.text = "Continue";` and the next `show()` draws it.
- **It cannot be copied.** Its callbacks are [`rmp::Callback`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Callback.html)s, which hold lambdas that capture what they like, a `std::unique_ptr` too, and cannot be copied; keep the widget where it lives.
- **It remembers what it is doing** in `ours`, a [`KeptState`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#KeptState) — [`hovered`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#KeptState-hovered), [`pressed`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#KeptState-pressed), [`focused`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#KeptState-focused) and the [`shakes`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#KeptState-shakes) not yet started. It is public only so the widget stays a struct you can write with designated initialisers; read it with the methods `hovered()`, `pressed()` and `focused()`.
- **`shake()`** shakes it side to side by its style's [`Motion`](https://omardev29.github.io/rmp-docs/manual/modules/ui-style.html#motion), plays its `shake` sound and sends [`EventKind::SHAKE`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#EventKind-SHAKE): "that did not work". It starts at the next `show()`.
- **`style`** is its own [style](https://omardev29.github.io/rmp-docs/manual/modules/ui-style.html#styles), over everything around it, and **`id`** is the [same id](https://omardev29.github.io/rmp-docs/manual/modules/ui.html#labels-are-ids) the immediate calls take.

The callbacks, each one optional — an empty one is not called:

| Callback | Runs when | On |
|---|---|---|
| `on_click` | it was clicked: released on it after a press on it, or Enter or the gamepad's A with the focus | `Button`, `Label`, `Image`, `Panel` |
| `on_hover` | the pointer arrived on it | all nine |
| `on_unhover` | …and left | all nine |
| `on_press` | the pointer went down on it | `Button`, `Image`, `Panel` |
| `on_release` | …and came up, on it or not | `Button`, `Image`, `Panel` |
| `on_focus` | the keyboard or gamepad focus arrived | `Button` and the four value controls |
| `on_blur` | …and left | `Button` and the four value controls |
| `on_change` | its value changed, with the new value | `Checkbox` (`bool`), `Slider` (`float`), `Dropdown` (`int`, the index), `TextInput` (`std::string_view`, the text) |

A pointer that arrives on a button gives it the focus too, so moving onto one and clicking it runs `on_hover`, `on_focus`, `on_press`, `on_release` and `on_click`, over as many frames as the player took. `show()` also returns what the immediate call would — `true` on the frame it was clicked, or changed — so `if (play.show())` works as well as `on_click`.

### Button

[`rmp::ui::Button`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Button.html): text, an icon, or both.

```cpp
rmp::ui::Button settings{ .text = "Settings",
                          .icon = gear_icon,
                          .icon_size = 24,
                          .on_click = [] { open_settings(); } };
rmp::ui::Button tool{ .icon = gear_icon, .icon_above = true, .id = "tool" };
```

| Field | Default | Is |
|---|---|---|
| [`text`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Button.html#text) | "" | The label; empty for a button that is only its icon. |
| [`icon`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Button.html#icon) | none | A [picture](https://omardev29.github.io/rmp-docs/manual/modules/ui-style.html#pictures) before the label, or alone. |
| [`icon_size`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Button.html#icon_size) | 0 | The icon's height in design units; 0 is the label's type size, or the picture's own height when there is no label. |
| [`icon_above`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Button.html#icon_above) | `false` | `true` puts the icon over the label, as a toolbar tile. |
| [`variant`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Button.html#variant) | `NORMAL` | What it means, as `ButtonOptions::style`. |
| [`size`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Button.html#size) | the theme's | A step or design units, as `ButtonOptions::size`. |
| [`width`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Button.html#width), [`height`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Button.html#height) | 0 | Above 0, a fixed size in design units; 0, sized as `button()` is. |
| [`enabled`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Button.html#enabled) | `true` | `false`: disabled colours, no press, no focus. |
| [`id`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Button.html#id) | "" | Only for two buttons with one label. |
| [`style`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Button.html#style) | empty | Its look. |
| `on_click`, `on_hover`, `on_unhover`, `on_press`, `on_release`, `on_focus`, `on_blur` | empty | See the table above. |

[`show()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Button.html#show) is `true` on the frame it was clicked; [`hovered()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Button.html#hovered), [`pressed()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Button.html#pressed) and [`focused()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Button.html#focused) say what it is doing now. An icon-only button has no padding and is the size of its picture, as [`image_button()`](https://omardev29.github.io/rmp-docs/manual/modules/ui-style.html#an-image-you-can-press) is.

### Label

[`rmp::ui::Label`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Label.html) is text as `text()` draws it, with a style of its own — a title in another font, with an outline — and clickable when it has an `on_click`:

```cpp
rmp::ui::Label credits{ .text = "Credits",
                        .color = rmp::ui::ColorRole::MUTED,
                        .on_click = [] { rmp::ui::notify("Made with raylib"); } };
```

Its fields: [`text`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Label.html#text); [`color`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Label.html#color), a `ColorRole` used when the style sets no text colour; [`size`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Label.html#size) and [`wrap`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Label.html#wrap), as `TextOptions` has them; [`id`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Label.html#id); [`style`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Label.html#style); and `on_click`, `on_hover`, `on_unhover`. [`show()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Label.html#show) is `true` on the frame it was clicked, and [`hovered()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Label.html#hovered) says whether the pointer is on it.

### Image

[`rmp::ui::Image`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Image.html) is a picture with a style — a frame behind it, a shadow, a tint — that can be clicked. With a [`sprite`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Image.html#sprite) that has a sheet, it plays the sprite's animation, one step of the game's clock every `show()`:

```cpp
rmp::ui::Image coin{ .sprite = rmp::Sprite{ .sheet = rmp::assets::load_sheet("coin.aseprite") },
                     .width = 32,
                     .height = 32 };
coin.sprite.play("spin");
```

| Field | Default | Is |
|---|---|---|
| [`picture`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Image.html#picture) | none | What it shows, unless `sprite` has a texture or a sheet. |
| [`sprite`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Image.html#sprite) | none | An animated picture, advanced every `show()`. |
| [`grow`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Image.html#grow) | `false` | Fill the space available, as `ImageOptions::grow`. |
| [`width`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Image.html#width), [`height`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Image.html#height) | 0 | Above 0, a fixed size in design units; 0, the picture's own. |
| [`enabled`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Image.html#enabled) | `true` | `false`: never clicked. |
| [`id`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Image.html#id) | "" | Its id; images have no label to go by. |
| [`style`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Image.html#style) | empty | Tint, a skin behind it, a shadow, a border. |
| `on_click`, `on_hover`, `on_unhover`, `on_press`, `on_release` | empty | See above. |

[`show()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Image.html#show) is `true` on the frame it was clicked; [`hovered()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Image.html#hovered) and [`pressed()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Image.html#pressed) say what it is doing.

### Panel

[`rmp::ui::Panel`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Panel.html) is a container with a look of its own, [`style`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Panel.html#style), and a look for everything inside it, [`children`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Panel.html#children) — see [a look for everything inside a container](https://omardev29.github.io/rmp-docs/manual/modules/ui-style.html#a-look-for-everything-inside-a-container). Its `show()` takes what goes inside it, as `panel()` does, and it is clickable as a whole when it has an `on_click`: an inventory slot, a card.

```cpp
rmp::ui::Panel slot{ .box = { .width = 64, .height = 64 },
                     .id = "slot-1",
                     .style = { .background = DARKGRAY },
                     .on_click = [] { equip(1); } };
slot.show([] { rmp::ui::text("Sword"); });
```

| Field | Default | Is |
|---|---|---|
| [`row`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Panel.html#row) | `false` | Its children left to right; `false`, top to bottom. |
| [`box`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Panel.html#box) | fit | Its layout — sizing, padding, gap, alignment — as `panel()` takes it. |
| [`background`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Panel.html#background) | `true` | `false`: a bare row or column, with no fill unless its style gives one, that still styles its children. |
| [`id`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Panel.html#id) | "" | Its id: one per clickable panel, so each is told apart. |
| [`style`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Panel.html#style), [`children`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Panel.html#children) | empty | Its look, and the look of everything inside it. |
| `on_click`, `on_hover`, `on_unhover`, `on_press`, `on_release` | empty | See above. |

[`show(body)`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Panel.html#show) lays it out with `body` inside it and is `true` on the frame it was clicked; [`hovered()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Panel.html#hovered) and [`pressed()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Panel.html#pressed) say what it is doing.

### Checkbox, Slider, Dropdown, TextInput

The four value controls, each holding its own value instead of writing to yours. Their fields are the immediate control's options, plus the value and the callbacks:

```cpp
rmp::ui::Checkbox fullscreen{ .text = "Fullscreen", .on_change = [](bool on) { (void)on; } };
rmp::ui::Slider music{ .text = "Music",
                       .value = 0.5f,
                       .step = 0.1f,
                       .on_change = [](float v) {
                           rmp::audio::set_volume(rmp::audio::Bus::MUSIC, v);
                       } };
rmp::ui::Dropdown quality{ .text = "Quality",
                           .items = { "Low", "Medium", "High" },
                           .selected = 1 };
rmp::ui::TextInput name{ .text = "Name", .placeholder = "Your name", .max_length = 16 };
```

| Widget | Its value | Its other fields |
|---|---|---|
| [`Checkbox`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Checkbox.html) | [`checked`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Checkbox.html#checked) (`false`) | [`text`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Checkbox.html#text), [`enabled`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Checkbox.html#enabled), [`id`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Checkbox.html#id), [`style`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Checkbox.html#style) |
| [`Slider`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Slider.html) | [`value`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Slider.html#value) (0), kept from [`min`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Slider.html#min) (0) to [`max`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Slider.html#max) (1) | [`text`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Slider.html#text), [`step`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Slider.html#step), [`width`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Slider.html#width), [`show_value`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Slider.html#show_value), [`enabled`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Slider.html#enabled), [`id`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Slider.html#id), [`style`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Slider.html#style) |
| [`Dropdown`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Dropdown.html) | [`selected`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Dropdown.html#selected) (0), an index into [`items`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Dropdown.html#items) | [`text`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Dropdown.html#text), [`width`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Dropdown.html#width), [`enabled`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Dropdown.html#enabled), [`id`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Dropdown.html#id), [`style`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Dropdown.html#style) |
| [`TextInput`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-TextInput.html) | [`value`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-TextInput.html#value) (""), what is typed | [`text`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-TextInput.html#text) (its label), [`placeholder`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-TextInput.html#placeholder), [`max_length`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-TextInput.html#max_length), [`width`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-TextInput.html#width), [`enabled`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-TextInput.html#enabled), [`id`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-TextInput.html#id), [`style`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-TextInput.html#style) |

Each has `on_change` with the new value, `on_hover`, `on_unhover`, `on_focus` and `on_blur`. Each one's `show()` is `true` on a frame its value changed, and `hovered()` and `focused()` say what it is doing. What every field means is what the immediate control's option of the same name means, above.

### ProgressBar

[`rmp::ui::ProgressBar`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-ProgressBar.html) is a bar with a look of its own: the style is the track's — its background, its skin — and [`fill`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-ProgressBar.html#fill) and [`fill_picture`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-ProgressBar.html#fill_picture) are the bar's. A nine-slice as the fill stretches with the bar and keeps its ends:

```cpp
rmp::ui::ProgressBar hp{ .value = health, .width = 200, .fill_picture = bar_art };
hp.show();
```

| Field | Default | Is |
|---|---|---|
| [`value`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-ProgressBar.html#value) | 0 | From 0 to 1, clamped. |
| [`width`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-ProgressBar.html#width) | 0 | In design units; 0 fills the space available. |
| [`height`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-ProgressBar.html#height) | -1 | -1 is from the type size. |
| [`radius`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-ProgressBar.html#radius) | -1 | -1 is round ends. |
| [`fill`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-ProgressBar.html#fill) | none | The bar's colour; none is the theme's `primary`. |
| [`fill_picture`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-ProgressBar.html#fill_picture) | none | The filled part as a picture, tinted by the style's `tint`. |
| [`id`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-ProgressBar.html#id), [`style`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-ProgressBar.html#style) |  | As every other. |
| `on_hover`, `on_unhover` | empty | A bar is never pressed. |

[`show()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-ProgressBar.html#show) returns nothing, and [`hovered()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-ProgressBar.html#hovered) says whether the pointer is on it: what a bar's tooltip needs.

## Events

Everything a control does, as it happens, is an [`Event`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Event): the pointer arriving and leaving, a press, a click, the focus coming and going, a value changing. The [sounds](https://omardev29.github.io/rmp-docs/manual/modules/ui-style.html#sounds) of the theme and of a style play on these; [`on_event()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#on_event) is one hook for everything else — a vibration on a phone, a particle, a counter for achievements. Every control sends them, the ones written as `rmp::ui::button("Play")` too:

```cpp
rmp::ui::on_event([](const rmp::ui::Event &e) {
    if (e.kind == rmp::ui::EventKind::CLICK) ++clicks;
});
```

An event has three fields: [`kind`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Event-kind), what happened; [`widget`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Event-widget), a [`WidgetKind`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#WidgetKind) — `BUTTON`, `LABEL`, `IMAGE`, `PANEL`, `CHECKBOX`, `SLIDER`, `DROPDOWN`, `TEXT_INPUT` or `PROGRESS`; and [`name`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Event-name), the control's label, or its id when it has one, valid during the call only.

| [`EventKind`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#EventKind) | When |
|---|---|
| `HOVER` | the pointer arrived on it |
| `UNHOVER` | …and left |
| `PRESS` | the pointer went down on it |
| `RELEASE` | the pointer came up after a `PRESS`, on it or not |
| `CLICK` | it was pressed: released on it, or Enter or the A button with the focus |
| `FOCUS` | the keyboard or gamepad focus arrived |
| `BLUR` | …and left |
| `CHANGE` | a checkbox, slider, dropdown or text field changed its value |
| `OPEN` | a dropdown opened its list |
| `CLOSE` | …and closed it |
| `SHAKE` | a kept widget's `shake()` started |

An event's sound plays first, then the hook. There is one hook: setting it again replaces it, and `rmp::ui::on_event({})` turns it off. A kept widget's own callbacks run in its `show()`, after the hook has heard the same thing.
