# The three-function menu

> The rule that outranks every other in the framework — the API is as simple as possible for the person making the game — and the three questions a feature has to answer to get in.

Source: https://omardev29.github.io/rmp-docs/framework/why/the-three-function-menu.html

The API has to be as simple as possible for the person using it. Complexity is allowed to exist for the advanced case; it is not allowed to stand in the way of the simple one. And there is a measure for it, which is not a slogan: a main menu is three calls.

```cpp
rmp::ui::begin();
if (rmp::ui::button("Play")) play();
if (rmp::ui::button("Quit")) rmp::app::quit();
rmp::ui::end();
```

Anything that makes those lines longer is wrong, whatever else it buys. That is the rule above every other rule in the framework, and the rest of these pages answer to it.

## What the three lines do not say

The menu is short because everything it does not mention has an answer already. It is centred in the window. It has no coordinates, sizes, fonts or hit boxes, and it keeps its proportions at any window size, because every measurement is in design units scaled from `[window] width` and `height`. It has a theme. The first button is focused, so the keyboard or a gamepad can press it with nothing else written, and the arrows move between the two. And a click on *Play* does not also reach the game drawn underneath, because the UI takes the pointer before the world sees it.

None of that is hidden from the game that wants to change it. [`begin()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#begin) takes options for where the menu goes, [`button()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#button) takes options for how it looks, a theme can be swapped at run time, and [the Clay layout engine underneath can be used directly](https://omardev29.github.io/rmp-docs/examples/ui/03_clay_direct.html). The options are there for the case that needs them; the simple case does not have to know they exist.

## The three questions

A feature gets into the framework by answering three questions, in this order.

1. **Is there a real game that needs it?** "Someone might want it" is a no. The games under [examples/games](https://omardev29.github.io/rmp-docs/examples/games/index.html) are where needs come from, and each of them has to be playable from the title screen to winning, losing and playing again before it counts.
2. **Can it be made from what already exists?** Then it is a pattern, and the place for a pattern is an example, not a new function.
3. **Does it make the three-function menu longer?** Then it is redesigned until it does not.

The second question is the one that keeps the API small. A pause menu is not a feature of the framework: it is a scene pushed on top of the game, and the defaults of a scene already make the world underneath freeze, stay visible and stop hearing its actions and the pointer ([Scenes](https://omardev29.github.io/rmp-docs/manual/core/scenes.html#what-a-scene-lets-through)). A rigid-body physics world is not a feature either. An object's `position`, `rotation` and `velocity` are public fields, so a game that needs a tower that collapses can link a physics library, step it in `_update` and write the position from it. If a real game asks for that, it arrives as an example.

## What the rule decided

The rule is easiest to see in the defaults, because a default is where the simple case lives.

Fields, not accessors

An object's `position`, `velocity`, `flip_x` and the rest are public fields, read and written directly: `player.flip_x = player.velocity.x < 0;` is the point. A getter and a setter in front of each one would be ceremony between the game and its data, so the clang-tidy check that asks for private members is switched off, and says why.

Nothing falls until it asks to

A scene carries a downward gravity, and every object's [`gravity_scale`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#gravity_scale) is 0. A top-down game never mentions gravity, and a platformer sets one field on the player.

Collide with everything, resolve nothing

Every object is on collision layer 1 and collides with layer 1, so the simple game never mentions a layer. Objects are not [`solid`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#solid) by default, because most things in a 2D game — bullets, coins, particles, triggers — are not walls, and the two that are, the floor and the player, are the two you configure.

The pause menu writes no policy

The three fields that say what a scene lets through to the one below default to exactly what a pause menu wants, so a pause scene is a scene with a `_draw()` and nothing else.

A Pong ball is one line

The collision is the framework's own, not a physics engine's, and this rule is the reason given in its source: with a rigid-body library a Pong ball stops being a shape with a velocity and becomes a body with a density, a restitution, a friction, a damping and gravity switched off.

A behavior is a struct

A behavior inherits from nothing and registers nowhere, so that it can be written `add<rmp::behavior::TopDown>({ .speed = 220 })`. The price of a base class would have been that line. [Designated initialisers](https://omardev29.github.io/rmp-docs/framework/why/designated-initialisers.html) explains why.

Escape goes back; it does not quit

raylib makes Escape the key that closes the window. In a game it is the key for "back" and "pause": a menu of `rmp::ui` goes back on it and the `ui_cancel` action is bound to it, so the entry point gives the key back to the game once the window is open, and a pause menu needs no line to keep Escape from ending the game. The game that does want to quit on it writes that one line, with [`rmp::app::quit()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-app.html#quit).

Leaving is one call that returns

[`rmp::app::quit()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-app.html#quit) can be called from anywhere, returns, and the game shuts down cleanly when the frame ends. There is no value to carry back up the call stack and nothing to catch.

Every one of these could have been more general. Each would then have been something the simple game had to know about.
