# Interface layout

> Rows, columns, panels, stacks, grids and scrolling lists, and the three ways anything in rmp::ui is sized — fit, grow and fixed — in design units that follow the screen.

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

Everything inside `begin()` and `end()` arranges itself in a centred column, which is the right answer for a menu and the wrong one for anything with structure. Containers are how you get structure: they nest, they take their contents as a lambda, and every size they take is in design units, so a layout drawn for the `[window]` resolution keeps its proportions on any screen.

Rows, columns and cards — [examples/ui/02_layout](https://omardev29.github.io/rmp-docs/examples/ui/02_layout.html)

One layout that changes with the window — [examples/ui/07_responsive](https://omardev29.github.io/rmp-docs/examples/ui/07_responsive.html)

```cpp
rmp::ui::begin();
rmp::ui::panel([&] {
    rmp::ui::text("Really quit?");
    rmp::ui::row({ .grow_x = true }, [&] {
        if (rmp::ui::button("Yes")) quit();
        rmp::ui::spacer();
        rmp::ui::button("No");
    });
});
rmp::ui::end();
```

The contents are a lambda, and that is the reason there is no closing call to forget: the container closes when the lambda returns. Capture with `[&]` when the body needs your variables, which is most of the time.

| Container | What it does |
|---|---|
| [`row`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#row) | Its children left to right. |
| [`column`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#column) | Its children top to bottom. |
| [`panel`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#panel) | A column with a background, padding and rounded corners: a dialog, a card. |
| [`center`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#center) | Fills the space it is given and puts its contents in the middle of it. |
| [`stack`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#stack) and [`layer`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#layer) | Layers in the same box, the later ones on top. |
| [`grid`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#grid) and [`cell`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#cell) | Equal columns, as many rows as it takes. |
| [`scroll`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#scroll) | Clips its contents and scrolls them. |
| [`spacer`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#spacer) | Not a container: it eats the space left over, or leaves a gap of a given size. |

## The frame begin() opens

[`begin()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#begin) opens two boxes before anything of yours: a root that fills the screen, and one column inside it that everything you declare goes into. The column is as big as its contents, and the root places it — in the middle, unless you say otherwise. [`FrameOptions`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#FrameOptions) says otherwise:

| Field | Default | Means |
|---|---|---|
| [`placement`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#FrameOptions-placement) | `Align::CENTER` | Where the column sits on the screen. |
| [`gap`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#FrameOptions-gap) | the theme's `gap` | Between the things in the column. |
| [`padding`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#FrameOptions-padding) | the theme's `panel_padding` | Kept clear around the edge of the screen. |
| [`grow`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#FrameOptions-grow) | `false` | `true`: the column fills the window, less the padding, instead of fitting what is in it. See [filling the window](https://omardev29.github.io/rmp-docs/manual/modules/ui-layout.html#filling-the-window). |
| [`focus_first`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#FrameOptions-focus_first) | unset | Whether the first control takes the focus by itself. Unset, the framework decides: yes, unless the scene drawing it is a game being played. See [a button in the HUD](https://omardev29.github.io/rmp-docs/manual/modules/ui.html#a-button-in-the-hud). |

The screen, here, is the game's area. Under `[window] stretch` `"letterbox"` that is the design inside its bars, and what the frame lays out keeps clear of them as it keeps clear of a phone's notch; see [scale and design units](https://omardev29.github.io/rmp-docs/manual/modules/ui.html#scale-and-design-units).

[`Align`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Align) has the nine values you would guess, a three-by-three grid of the vertical (`TOP`, `CENTER`, `BOTTOM`) crossed with the horizontal (`LEFT`, `CENTER`, `RIGHT`): `TOP_LEFT`, `TOP_CENTER`, `TOP_RIGHT`, `CENTER_LEFT`, `CENTER`, `CENTER_RIGHT`, `BOTTOM_LEFT`, `BOTTOM_CENTER` and `BOTTOM_RIGHT`. A HUD in the corner is a placement and a smaller gap:

```cpp
rmp::ui::begin({ .placement = rmp::ui::Align::TOP_LEFT, .gap = 4 });
rmp::ui::text("Score " + std::to_string(score));
rmp::ui::text("Lives " + std::to_string(lives), { .color = rmp::ui::ColorRole::MUTED });
rmp::ui::end();
```

On Android and iOS the root also keeps 24 design units clear at every edge, for the status bar and the notch.

Inside a scene, `_draw()` can hold more than one pair — the score in one corner, a button in another — and they are drawn as parts of the same frame. In a game that runs its own loop, keep to one pair per frame.

## Sizing: fit, grow, fixed

Each axis of a box is sized one of three ways, and there is no fourth:

| Sizing | Written | Means |
|---|---|---|
| Fit | nothing: the default | As big as its contents need. |
| Grow | [`grow_x`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#BoxOptions-grow_x), [`grow_y`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#BoxOptions-grow_y) | Fill the space its parent offers on that axis — along a row or a column, shared with the siblings that grow too. |
| Fixed | [`width`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#BoxOptions-width), [`height`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#BoxOptions-height) above 0 | That many design units, whatever else is set. |

A box that fits its contents, holding children that grow into it, is the pairing that makes the buttons of a menu the same width: the column is as wide as its widest button, and every other button grows to match.

The fields are interleaved by axis — `grow_x`, `width`, `grow_y`, `height` — and not grouped by kind, because designated initialisers have to be written in declaration order. This way round the most ordinary thing anyone writes, a sidebar of a fixed width that fills the height, is legal:

```cpp
rmp::ui::panel({ .box = { .width = 240, .grow_y = true } }, [&] {
    rmp::ui::text("Sections");
});
```

### Filling the window

Grow fills the parent, and the column that `begin()` opens fits its contents. So `grow_x` on something directly inside it fills the width of that column — the width of the widest thing next to it — and not the width of the screen. A menu wants exactly that, which is why it is the default.

A screen laid out edge to edge — a sidebar beside a content area, a list as tall as the window — asks for the other kind of frame. [`begin({ .grow = true })`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#FrameOptions-grow) makes the column fill the window, less the padding, on both axes, so whatever grows inside it reaches the edges:

```cpp
rmp::ui::begin({ .grow = true });
rmp::ui::row({ .grow_x = true, .grow_y = true }, [&] {
    rmp::ui::panel({ .box = { .width = 200, .grow_y = true } }, [&] {
        rmp::ui::text("Sections");
    });
    rmp::ui::panel({ .box = { .grow_x = true, .grow_y = true } }, [&] {
        rmp::ui::text("World");
    });
});
rmp::ui::end();
```

What does not grow is still placed by `placement`: in a frame opened with `{ .placement = rmp::ui::Align::TOP_CENTER, .grow = true }`, a line of text sits at the top in the middle, and a row that grows beneath it takes the rest. Without `grow`, the frame is the one the three-function menu is drawn in. The [inventory](https://omardev29.github.io/rmp-docs/examples/ui/05_inventory.html) and [responsive](https://omardev29.github.io/rmp-docs/examples/ui/07_responsive.html) examples are both laid out this way.

Inside a frame that fits, a bar that has to be a given size gets that size: a fixed `width` or `height`, in design units, which the scale turns into pixels with everything else. Everything that grows inside it then has something to grow into:

```cpp
rmp::ui::begin({ .placement = rmp::ui::Align::TOP_CENTER });
rmp::ui::row({ .width = 760 }, [&] {
    rmp::ui::text("Inventory");
    rmp::ui::spacer();
    rmp::ui::text("24 / 40", { .color = rmp::ui::ColorRole::MUTED });
});
rmp::ui::end();
```

A fixed width is a fixed number of design units: on a window wider than the `[window]` resolution's shape, there is room left at the sides, because the scale follows the tighter axis.

## Gap, padding and where children sit

Rows, columns and panels take [`BoxOptions`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#BoxOptions) — a panel inside its `.box` — and three of its fields decide the space around things:

| Field | Default | Means |
|---|---|---|
| [`gap`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#BoxOptions-gap) | the theme's `gap`, 12 | Between children, in design units. |
| [`padding`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#BoxOptions-padding) | none; a panel's is the theme's `panel_padding`, 20 | Inside the container, the same on all four sides. |
| [`items`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#BoxOptions-items) | `Align::CENTER` | Where the children sit in the space left over. |

`items` is the one that makes a card look like a card: a column of text is centred unless it is told to hug the left.

```cpp
rmp::ui::column({ .gap = 6, .items = rmp::ui::Align::CENTER_LEFT }, [&] {
    rmp::ui::text("Rabbit", { .color = rmp::ui::ColorRole::PRIMARY });
    rmp::ui::text("Level 7", { .color = rmp::ui::ColorRole::MUTED, .size = 14 });
});
```

### Spacers

[`spacer()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#spacer) grows on both axes and eats the space left over, which is how two things are pushed to opposite ends of a row. The row has to have space left over for it to eat, so it is given a width or set to grow:

```cpp
rmp::ui::panel({ .box = { .width = 300 } }, [&] {
    rmp::ui::row({ .grow_x = true }, [&] {
        rmp::ui::text("Health");
        rmp::ui::spacer(); // shoves what follows to the right
        rmp::ui::text("999");
    });
});
```

`spacer(n)` is the other one: a fixed box of `n` by `n` design units, for breathing room in one place without changing the container's gap.

## Panels

A [`panel`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#panel) is a column with a background, which is what makes it visible, padding of the theme's `panel_padding`, and the theme's `corner_radius`. [`PanelOptions`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#PanelOptions) holds the layout in `.box` and the look after it:

| Field | Default | Means |
|---|---|---|
| [`box`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#PanelOptions-box) | `{}` | The layout, as a column takes it, except that its padding defaults to the theme's `panel_padding`. |
| [`background`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#PanelOptions-background) | the theme's `panel` | The fill. `{ 0, 0, 0, 0 }` means the theme's. |
| [`radius`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#PanelOptions-radius) | the theme's `corner_radius` | Of the corners, in design units; 0 is square. |
| [`border`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#PanelOptions-border) | none | An outline colour. Left unset, the theme's `border` is drawn only when the theme's `border_width` is above 0 — in the light theme, not in the dark one. |
| [`border_width`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#PanelOptions-border_width) | 1 | The width of an outline you set, in design units. |

```cpp
rmp::ui::panel({ .box = { .width = 260, .height = 70 },
                 .border = rmp::ui::current_theme().border },
               [&] {
                   rmp::ui::center([&] {
                       rmp::ui::text("nothing here",
                                     { .color = rmp::ui::ColorRole::MUTED });
                   });
               });
```

Simple: a call each frame

```cpp
rmp::ui::Panel empty{
    .box = { .width = 260, .height = 70 },
    .style = { .border = GRAY, .border_width = 1 },
};

void _draw() override {
    rmp::ui::begin();
    empty.show([&] {
        rmp::ui::center([&] {
            rmp::ui::text("nothing here",
                          { .color = rmp::ui::ColorRole::MUTED });
        });
    });
    rmp::ui::end();
}
```

Full: a widget you keep

In the framework's themes a panel sits on a soft shadow, and fades and rises into place the first frame it is drawn — see [styles](https://omardev29.github.io/rmp-docs/manual/modules/ui-style.html#styles) for that look and how to take it away. A kept [`Panel`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Panel.html) can also be clicked, and styles everything inside it: [Panel](https://omardev29.github.io/rmp-docs/manual/modules/ui-controls.html#panel).

## Centring and layers

[`center()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#center) grows on both axes and puts its contents in the middle of what it grew into — so it centres within its parent, and its parent decides how much room that is: a panel of a fixed size, a grid cell.

[`stack()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#stack) puts things on top of each other. Every child of a stack has to be a [`layer()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#layer); each layer fills the stack, centres what is in it, and is drawn over the layers written before it:

```cpp
rmp::ui::panel({ .box = { .width = 260, .height = 90 } }, [&] {
    rmp::ui::stack([&] {
        rmp::ui::layer([&] {
            rmp::ui::image(portrait, { .grow = true, .tint = CLITERAL(Color){ 255, 255, 255, 60 } });
        });
        rmp::ui::layer([&] {
            rmp::ui::text("PAUSED", { .color = rmp::ui::ColorRole::DANGER });
        });
    });
});
```

The explicit `layer()` is not ceremony: it is what tells the layout which things are meant to overlap and which are ordinary children. And because layers overlap, they take no room of their own — a stack is as big as the space its parent gives it, so it goes inside something with a size, like the panel above. In a box that only fits its contents, a stack has no size at all and its layers spill over whatever comes next.

## Grids

A [`grid`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#grid) lays its items out in equal columns and starts a new row when one fills. Each item goes in a [`cell()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#cell), which is what lets the grid count them; the layout engine underneath wraps text, not boxes, so the rows are built as real rows:

```cpp
rmp::ui::grid(4, [&] {
    for (auto &item : inventory)
        rmp::ui::cell([&] { rmp::ui::image(item.icon); });
});
```

Every cell in a row is the same width, its share of the row, and what is in it is centred. A `cell()` outside a grid is a plain box, so the mistake shows on screen instead of breaking the frame.

With [`columns`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#GridOptions-columns) at 0 the grid works out how many cells of [`min_cell`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#GridOptions-min_cell) design units, each with its gap, fit in the width it had last frame, and works it out again as the window changes. An inventory then reflows on a phone held upright instead of staying at the number someone typed on a desktop. This is also the row that wraps: there is no wrap flag on `row()`, because `grid({ .columns = 0 })` is one.

```cpp
rmp::ui::panel({ .box = { .width = 480 } }, [&] {
    rmp::ui::grid({ .columns = 0, .min_cell = 88, .id = "inventory" }, [&] {
        for (const std::string_view name : names)
            rmp::ui::cell([&] { rmp::ui::text(name, { .size = 13 }); });
    });
});
```

It is never fewer than one column and never more than fit. A grid too narrow for even one cell of `min_cell` is one column, so the narrower it gets, the fewer columns it has, down to one. Its first frame, with no width measured yet, is one column too, and it has its real count from the second.

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

| Field | Default | Means |
|---|---|---|
| `columns` | 0 | How many; 0 is as many as fit, and at least one. |
| `min_cell` | 96 | The width a column needs, when `columns` is 0. |
| [`gap`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#GridOptions-gap) | the theme's `gap` | Between cells and between rows. |
| [`padding`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#GridOptions-padding) | none | Inside the grid. |
| [`grow_x`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#GridOptions-grow_x) | `true` | Take the width it is offered. |
| [`grow_y`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#GridOptions-grow_y) | `false` | Fill the parent's height instead of fitting the rows. |
| [`id`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#GridOptions-id) | none | Which grid it is, from frame to frame. See below. |

To work out its columns, a grid finds its own width from last frame, with or without a name. A grid with an `id` finds itself by that name; one without is found by its order among the unnamed grids of the same `begin()`/`end()`, and a grid that comes and goes before it can make it borrow another's width. Name the ones that share a screen with others that come and go.

## Scrolling

[`scroll()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#scroll) clips its contents to its own box and scrolls them: with the mouse wheel, or by dragging inside it — with a finger on a phone, with the mouse on a desktop. It stops at the end of the contents. Neither gesture needs a line of code:

[examples/ui/05_inventory/src/panels/list.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/ui/05_inventory/src/panels/list.cpp#L1-L36)

```cpp
// The list. scroll() clips its contents; the wheel and a dragging finger both
// move it, and neither needs a line of code here. Each item says what it is
// with tooltip().
#include "inventory.h"

#include <rmp/ui.h>

#include <string>

void item_list() {
    rmp::ui::panel({ .box = { .width = 240, .grow_y = true } }, [&] {
        rmp::ui::text("All items");

        rmp::ui::scroll({ .gap = 4, .id = "list" }, [&] {
            for (int i = 0; i < ITEM_COUNT; ++i) {
                // Two buttons could share a label across a long list, so the
                // ids are made explicit. Identical labels in one frame are told
                // apart automatically; this is for when you want the identity
                // to survive the list being reordered.
                const std::string id = "item" + std::to_string(i);
                if (rmp::ui::button(items[i].name, { .id = id })) {
                    selected = i;
                }
                // About the button just above, and only that: shown when the
                // pointer rests on it for half a second, or at once when the
                // keyboard or a gamepad walks onto it. To the left, over the
                // grid, where it hides no other item of the list.
                rmp::ui::tooltip(items[i].description,
                                 { .side = rmp::ui::Align::CENTER_LEFT });
            }
        });

        rmp::ui::text("scroll me", { .color = rmp::ui::ColorRole::MUTED, .size = 12 });
    });
}
```

How big the area is follows the sizing rules. By default it grows on both axes: it takes the room its parent gives it and clips there. The list above is in a panel that grows to the height of the example's frame, which [fills the window](https://omardev29.github.io/rmp-docs/manual/modules/ui-layout.html#filling-the-window), and the area takes what the panel has left once its two lines of text are in. Its rows never push a parent past the window: where everything around it only fits its contents, the area is squeezed to the room the window has left, and clips there. [`height`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ScrollOptions-height) makes it a window of a fixed size onto a longer list:

```cpp
rmp::ui::scroll({ .height = 200, .id = "levels" }, [&] {
    for (int i = 1; i <= level_count; ++i) {
        if (rmp::ui::button("Level " + std::to_string(i))) play_level(i);
    }
});
```

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

| Field | Default | Means |
|---|---|---|
| [`horizontal`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ScrollOptions-horizontal) | `false` | Clip and scroll left to right. |
| [`vertical`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ScrollOptions-vertical) | `true` | Clip and scroll top to bottom. |
| [`gap`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ScrollOptions-gap) | the theme's `gap` | Between children. |
| [`padding`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ScrollOptions-padding) | none | Inside the area. |
| [`grow_x`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ScrollOptions-grow_x), [`width`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ScrollOptions-width) | `true`, 0 | Fill the parent's width, or a fixed one. |
| [`grow_y`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ScrollOptions-grow_y), [`height`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ScrollOptions-height) | `true`, 0 | Fill the parent's height, or a fixed one. |
| [`id`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ScrollOptions-id) | none | Which area it is, from frame to frame. |

Inside the area, children are laid out top to bottom whichever way it scrolls; a strip that scrolls sideways is a `row()` inside a horizontal area. How far an area has scrolled is remembered by the area, and an area without an `id` is told apart by its order among the unnamed ones, as a grid is — so one that shares a screen with areas that come and go gets a name.

What is scrolled out of view cannot be clicked: only the part of a control inside the area takes the pointer, and the area itself — its empty part included — is the interface's, so a drag inside it scrolls the list instead of reaching the game.

The keyboard and the gamepad scroll it too, by moving the focus. When the focus lands on a control the area has clipped away, and its ring is showing, the area moves just far enough to show the control — and a list inside a scrolling page shows its row first, then the page shows the list. It happens once for each move of the focus, so the wheel or a finger can take the list somewhere else afterwards without being pulled back to it.

## Images and progress bars

[`rmp::ui::image`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#image) draws a texture. With no options it is drawn at its own size, its pixels taken as design units, so an icon grows with the rest of the interface instead of shrinking into nothing on a big screen. [`ImageOptions`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ImageOptions) changes that:

| Field | Default | Means |
|---|---|---|
| [`grow`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ImageOptions-grow) | `false` | Fill the space available on both axes; the picture is stretched to it. |
| [`width`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ImageOptions-width), [`height`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ImageOptions-height) | 0 | A size in design units; 0 is the texture's own. |
| [`tint`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ImageOptions-tint) | `WHITE` | Multiplies the picture's colours; `WHITE` leaves them as they are. |

```cpp
rmp::ui::image(portrait, { .width = 96, .height = 96 });
```

Simple: a call each frame

```cpp
rmp::ui::Image face{ .picture = portrait,
                     .width = 96, .height = 96,
                     .on_click = [] { TraceLog(LOG_INFO, "hi"); } };

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

Full: a widget you keep

What it draws is any [`rmp::ui::Picture`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Picture.html): an [`rmp::Texture`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#Texture), a part of one, the frame an [`rmp::Sprite`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Sprite.html) shows, a slice of an Aseprite file, a nine-slice. [Pictures](https://omardev29.github.io/rmp-docs/manual/modules/ui-style.html#pictures) says how each is made. A picture holds counted handles, so the texture stays loaded until `end()` has drawn the frame, and a temporary is safe:

```cpp
rmp::ui::image(rmp::assets::load_texture("icon.png"), { .width = 40, .height = 40 });
```

A raylib `Texture2D` is taken too, for a texture the game made itself — a render texture, an image it generated. It is copied on the way in, but what is copied is a handle to something on the GPU, so that texture has to stay loaded until `end()` has drawn the frame:

```cpp
rmp::ui::image(minimap.texture, { .width = 160, .height = 160 });
```

[`rmp::ui::progress`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#progress) is a bar, filled to a fraction from 0 to 1 — clamped, so a health of -5 draws empty rather than going wrong:

```cpp
rmp::ui::progress(health, { .width = 180 });
rmp::ui::progress(mana, { .width = 180, .height = 8,
                          .fill = SKYBLUE });
```

Simple: a call each frame

```cpp
rmp::ui::ProgressBar health_bar{ .width = 180 };
rmp::ui::ProgressBar mana_bar{ .width = 180, .height = 8,
                               .fill = SKYBLUE };

void _draw() override {
    health_bar.value = health;
    mana_bar.value = mana;
    rmp::ui::begin();
    health_bar.show();
    mana_bar.show();
    rmp::ui::end();
}
```

Full: a widget you keep

[`ProgressOptions`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ProgressOptions): [`width`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ProgressOptions-width) (0 fills the space available), [`height`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ProgressOptions-height) (by default 0.6 of the theme's type size), [`radius`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ProgressOptions-radius) (by default half the height, for round ends), [`fill`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ProgressOptions-fill) and [`track`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ProgressOptions-track) (the theme's `primary` and `surface` unless set), and [`id`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ProgressOptions-id).

A bar drawn by the artist — a filled part that is a picture, its ends kept round by a nine-slice — is a kept [`rmp::ui::ProgressBar`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-ProgressBar.html) with a [`fill_picture`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-ProgressBar.html#fill_picture); see [widgets you keep](https://omardev29.github.io/rmp-docs/manual/modules/ui-controls.html#widgets-you-keep).

## Naming a container

Containers are anonymous unless you give them an `id` — [`BoxOptions::id`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#BoxOptions-id), and the same field on a panel's `.box`, a grid, a scroll area and a progress bar. A named one is the same element from frame to frame, whatever else is on screen. Nothing needs it for a row, a column or a panel; it is what a test uses to find one, and for grids and scroll areas it is their identity, as above.

```cpp
rmp::ui::panel({ .box = { .id = "inventory" } }, [&] {
    rmp::ui::text("Inventory");
});
```

## A whole layout

`examples/ui/02_layout` puts most of this page on one screen — a toolbar with a spacer, a card of a row and a column, a stack, a centred placeholder — with bars that move so it is clear the layout is rebuilt every frame:

[examples/ui/02_layout/src/main.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/ui/02_layout/src/main.cpp#L1-L169)

```cpp
// ---------------------------------------------------------------------------
// examples/ui/02_layout/src/main.cpp
//
// Containers: row, column, panel, center, stack, spacer — plus image and
// progress, the two widgets that only make sense once you have somewhere to
// put them.
//
// The rule that shapes all of it: a container takes its contents as a lambda.
// There is no closing call to forget, because the compiler closes it for you.
// Capture with [&] when the body needs your variables, which is most of the
// time.
//
// Every measurement below is in DESIGN UNITS, at the [window] resolution from
// raylib_multiplatform.toml. rmp::ui multiplies them by the current scale, so
// `width = 200` is 200 at your design Size, 400 at twice it, and never a
// hard-coded pixel count that looks right on exactly one monitor.
//
// Run it: `rmp example 02_layout`.
// ---------------------------------------------------------------------------

#include <rmp/app.h>
#include <rmp/assets.h>
#include <rmp/scene.h>
#include <rmp/ui.h>

#include <string>

class LayoutScene : public rmp::Scene {
public:
    void _ready() override {
        // Resize the window and watch everything follow.
        _portrait = rmp::assets::load_texture("rabbit.png");
    }

    void _update(float delta) override {
        // Bars that move, so the layout is doing something rather than sitting
        // still -- and so it is obvious the numbers are read fresh every frame.
        _health -= delta * 0.05f;
        if (_health < 0) _health = 1.0f;
        _mana += delta * 0.08f;
        if (_mana > 1) _mana = 0.0f;
    }

    void _draw() override {
        // begin() is a centred column. placement moves the whole thing: this one
        // hugs the top-left corner, like a HUD would.
        rmp::ui::begin({ .placement = rmp::ui::Align::TOP_LEFT, .gap = 14 });

        toolbar();
        character_card();
        banner();
        empty_slot();

        if (rmp::ui::button("Done")) rmp::app::quit();

        rmp::ui::end();
    }

private:
    // An rmp::Texture, not a Texture2D. The handle OWNS the texture; a raw
    // Texture2D copied out of the temporary would have been unloaded on the
    // same line, before the next statement ran.
    rmp::Texture _portrait;
    float _health = 0.72f;
    float _mana = 0.35f;

    // -------------------------------------------------------------------
    // row and column: the two directions
    // -------------------------------------------------------------------
    void character_card() {
        // panel = a column with a background and padding. It is what you put
        // a dialog, a card or a tooltip inside.
        rmp::ui::panel([&] {
            // row lays out left to right.
            rmp::ui::row({ .gap = 16 }, [&] {
                rmp::ui::image(_portrait, { .width = 72, .height = 72 });

                // column lays out top to bottom. items decides where children
                // sit across the other axis -- here, hard against the left
                // instead of centred, which is what makes a card look like a
                // card.
                rmp::ui::column({ .gap = 6, .items = rmp::ui::Align::CENTER_LEFT }, [&] {
                    rmp::ui::text("Rabbit", { .color = rmp::ui::ColorRole::PRIMARY });
                    rmp::ui::progress(_health, { .width = 180 });
                    rmp::ui::progress(_mana,
                                      { .width = 180, .height = 8, .fill = SKYBLUE });
                    rmp::ui::text("Level 7",
                                  { .color = rmp::ui::ColorRole::MUTED, .size = 14 });
                });
            });
        });
    }

    // -------------------------------------------------------------------
    // spacer: how you push things apart
    // -------------------------------------------------------------------
    static void toolbar() {
        // grow_x makes the row take the full width it is offered; without it
        // the row would shrink to fit its contents and the spacer would have
        // nothing to eat.
        rmp::ui::row({ .grow_x = true }, [&] {
            rmp::ui::text("Inventory");
            rmp::ui::spacer(); // <- takes everything left over
            rmp::ui::text("24 / 40", { .color = rmp::ui::ColorRole::MUTED });
        });

        // spacer(n) is the other one: a fixed gap, when you want breathing
        // room in one specific place rather than changing the container's gap.
        rmp::ui::spacer(8);
    }

    // -------------------------------------------------------------------
    // stack and layer: things on top of each other
    // -------------------------------------------------------------------
    void banner() {
        rmp::ui::panel({ .box = { .width = 260, .height = 90 } }, [&] {
            // Every child of a stack has to be a layer(). That is not
            // ceremony: it is what says "these are meant to overlap" instead
            // of "these are ordinary children in a column". Later layers draw
            // on top.
            rmp::ui::stack([&] {
                rmp::ui::layer([&] {
                    rmp::ui::image(
                        _portrait,
                        { .grow = true, .tint = CLITERAL(Color){ 255, 255, 255, 60 } });
                });
                rmp::ui::layer([&] {
                    rmp::ui::text("PAUSED", { .color = rmp::ui::ColorRole::DANGER });
                });
            });
        });
    }

    // -------------------------------------------------------------------
    // center: fill what you were given, put the contents in the middle
    // -------------------------------------------------------------------
    static void empty_slot() {
        rmp::ui::panel({ .box = { .width = 260, .height = 70 },
                         .border = rmp::ui::current_theme().border },
                       [&] {
                           rmp::ui::center([&] {
                               rmp::ui::text("nothing here",
                                             { .color = rmp::ui::ColorRole::MUTED });
                           });
                       });
    }
};

RMP_GAME(LayoutScene);

// ---------------------------------------------------------------------------
// The Sizing model, in three lines
// ---------------------------------------------------------------------------
//
//   default        fit — as big as the contents need
//   grow_x/grow_y  fill the space the parent is offering
//   width/height   a fixed number of design units, overriding both
//
// A container fits its contents; a child with grow expands to fill whatever
// the container ended up being. That pairing is what makes the buttons in a
// menu come out the same width without anyone measuring anything.
//
// NAMING A CONTAINER. Every container takes an optional `.id`: a stable name,
// the same element from frame to frame whatever else is on screen.
//
//     rmp::ui::panel({ .box = { .id = "inventory" } }, [&]{ ... });
//
// Unnamed containers are anonymous, which is right for almost all of them.
```
