rmp::ui
rmp::ui — the interface layer.
The whole point, in four lines:
rmp::ui::begin();
if (rmp::ui::button("Play")) play();
if (rmp::ui::button("Quit")) quit();
rmp::ui::end();That is a centred, responsive main menu. No coordinates, no sizes, no anchors, no fonts, no hitboxes, and it looks the same at 800x600 as it does at 4K. Everything else in this header is what you reach for when the default is not what you want — and you only pay for it when you use it.
Three rules worth knowing, and that is genuinely all of them:
end()draws. So thebegin()/end()pair goes betweenBeginDrawing()andEndDrawing(), and beforeSmokeTest_CaptureFrame()if you keep that.- Describe it where it is drawn: in a scene's
_draw(), in screen space. Not in_update(), which draws nothing, and not in an object's_draw(), which runs under the camera —at()is how a box follows the world. A call in the wrong place is reported once, and does nothing. Eachbegin()/end()pair is a pass, and a frame may hold several: a HUD and the pause menu over it, or a screen and itsoverlay(). - Interaction uses the previous frame's geometry. A button cannot be clicked on the very first frame it appears — 16 ms at 60 fps. This is inherent to immediate mode; see TECHNICAL.md for why the alternative is worse.
The layout engine underneath is Clay, and it is deliberately invisible: not one of its types appears in this header, so it can be replaced without any of your code changing.
On pages of their own
rmp::ui::Picture— Anythingrmp::uican show.rmp::ui::SoundName— The name of a sound, asrmp::audio::play()takes it ("click" is click.wav, click.ogg...): written as a string,.click = "click".rmp::ui::DialogueBox— The classic box: along the bottom of the screen, the speaker's portrait and name beside the line, the choices as buttons under it.rmp::ui::DialogueStage— A visual novel's stage: big portraits of who is on it, the speaker in front and the rest dimmed, and the line in a box under them.rmp::ui::Button— A button: text, an icon, or both.rmp::ui::Label— Text, astext()draws it, with a style of its own: a title in another font, with an outline.rmp::ui::Image— A picture with a style — a frame, a shadow — that can be clicked.rmp::ui::Panel— A container: a panel with a look of its own (style), and a look for everything inside it (children), which every descendant inherits — the nearest container's wins.rmp::ui::Checkbox— A checkbox that holds its own value.rmp::ui::Slider— A slider that holds its own value.rmp::ui::Dropdown— A dropdown that holds its items and its choice.rmp::ui::TextInput— A text field that holds its own text.rmp::ui::ProgressBar— A progress bar with a look of its own: the style is the track's (its background, its skin),fillandfill_picturethe bar's.
Vocabulary
Align
Where content sits inside the space it was given. Read them as a 3x3 grid: three verticals (top/center/bottom) crossed with three horizontals (left/center/right).
| Value | Means | |
|---|---|---|
TOP_LEFT | ||
TOP_CENTER | ||
TOP_RIGHT | ||
CENTER_LEFT | ||
CENTER | ||
CENTER_RIGHT | ||
BOTTOM_LEFT | ||
BOTTOM_CENTER | ||
BOTTOM_RIGHT |
Variant
What a control *means*, not what colour it is. The theme decides the colour, so restyling the game never means revisiting every call site.
normal a filled surface: the default, and most buttons
primary the one thing you want pressed on this screen
danger destructive, and it should look like it
outline an outline and a label, no fill: a secondary action
ghost just the label until you point at it: toolbars, "back" links| Value | Means | |
|---|---|---|
NORMAL | ||
PRIMARY | ||
DANGER | ||
OUTLINE | ||
GHOST |
ColorRole
Which colour of the theme a piece of text uses: TEXT is the theme's text, MUTED its text_muted, PRIMARY its primary and DANGER its danger.
| Value | Means | |
|---|---|---|
TEXT | ||
MUTED | ||
PRIMARY | ||
DANGER |
Size
The three type steps. Anywhere a size is asked for you can write one of these or a plain number of design units — it is the same field either way:
rmp::ui::text("Chapter One", { .size = rmp::ui::Size::LARGE });
rmp::ui::text("Chapter One", { .size = 34 });The steps are what you want almost always: they come from the theme, so they move together when someone changes the type scale, and they stay in proportion at every screen size. A number is the escape hatch. SMALL, MEDIUM and LARGE are the theme's font_size_small, font_size and font_size_large.
| Value | Means | |
|---|---|---|
SMALL | ||
MEDIUM | ||
LARGE |
Pictures
NineSlice
A picture that stretches without stretching its corners: the classic "9-patch". The four margins cut the source into a 3x3 grid; the corners are drawn at their size, the edges stretch along one axis and the middle along both. That is how one small frame becomes a button of any length.
rmp::ui::NineSlice frame{ .texture = ui_art, .source = { 0, 0, 24, 24 },
.left = 8, .top = 8, .right = 8, .bottom = 8 };Or read from Aseprite, where an artist draws it: a slice with 9-slices on gives its own margins — rmp::ui::nine_slice(sheet, "button").
| Field | Type | Default | What it is |
|---|---|---|---|
texture | rmp::Texture | The picture | |
sheet | rmp::SpriteSheet | Or an Aseprite sheet's, when | |
source | Rectangle | {} | The part of it to cut; {0,0,0,0} = all of it |
left | float | 0 | The margins, in pixels of the SOURCE: the left column |
top | float | 0 | The top row |
right | float | 0 | The right column |
bottom | float | 0 | The bottom row |
scale | float | 0 | How big a source pixel is drawn, in design units: the corners are left * scale design units wide, and grow with the UI's scale like everything else. 0 = 1, so a 24-pixel frame is drawn as drawn. Pixel art wants a whole number: 2, 3, 4. |
slice
A named slice of an Aseprite file, as a Picture: the part of the first frame the slice covers, with its 9-slice margins when the slice has them. This is how one .aseprite becomes an atlas of icons, by name:
static rmp::SpriteSheet icons = rmp::assets::load_sheet("icons.aseprite");
rmp::ui::image(rmp::ui::slice(icons, "coin"));A name the sheet does not have is an empty Picture, said once.
nine_slice
The same slice as a NineSlice, to change its scale or hand it on. A slice without 9-slices comes back with all four margins 0, said once.
Looks: shadows, outlines, skins, sounds and motion
Shadow
A soft shadow under a box: under a button, a panel, an image. Drawn as a few rounded rectangles that get fainter outwards, which reads as blurred on every target — the software renderer and OpenGL ES 2.0 included — and costs a handful of rectangles. Sizes are in design units.
| Field | Type | Default | What it is |
|---|---|---|---|
offset | Vector2 | { 0, 4 } | Where it falls: down a little, as light from above |
blur | float | 8 | How far it fades out past the box; 0 = a hard shadow |
spread | float | 0 | How much bigger than the box it is before it fades |
color | Color | CLITERAL(Color){ 0, 0, 0, 90 } | At the box; fainter outwards |
TextOutline
An outline around every letter, so a title reads over any background. In design units; drawn as copies of the text around it, so keep it small: 1 to 3.
| Field | Type | Default | What it is |
|---|---|---|---|
width | float | 1 | How far it reaches past each letter, in design units |
color | Color | CLITERAL(Color){ 0, 0, 0, 255 } | Its colour |
TextShadow
A copy of the text under it, offset: the shadow of a letter.
| Field | Type | Default | What it is |
|---|---|---|---|
offset | Vector2 | { 1, 2 } | Design units |
color | Color | CLITERAL(Color){ 0, 0, 0, 160 } | Its colour |
Skin
Pictures instead of a flat colour, one per state. Only normal is needed: a state without its own picture shows normal, tinted the way the colours of that state would be — lighter under the pointer, darker pressed, grey disabled. Give the others when the artist drew them.
| Field | Type | Default | What it is |
|---|---|---|---|
normal | Picture | At rest | |
hover | Picture | Under the pointer | |
press | Picture | Held down | |
disabled | Picture | Enabled = false | |
focus | Picture | Has the keyboard or gamepad focus (the ring is still drawn) |
Sounds
Sounds, by name. Each event has its own; one that is not set is inherited from what is around it and, at the end, from the Theme. An EMPTY name is silence: .hover = "" turns off a hover sound set further out.
| Field | Type | Default | What it is |
|---|---|---|---|
hover | std::optional<SoundName> | The pointer arrives on a control | |
press | std::optional<SoundName> | The pointer goes down on it | |
release | std::optional<SoundName> | ...and comes up | |
click | std::optional<SoundName> | It was pressed: pointer, Enter, the A button | |
focus | std::optional<SoundName> | The keyboard or gamepad focus arrives | |
change | std::optional<SoundName> | A checkbox, slider, dropdown or field changed | |
open | std::optional<SoundName> | A dropdown opened | |
close | std::optional<SoundName> | ...and closed | |
shake | std::optional<SoundName> |
| |
volume | std::optional<float> | 0..1, for all of them; 1 when nobody sets it |
Motion
Movement, which the framework's own themes leave all off: a button that grows under the pointer is a choice of style, and a game that wants it says so here. Nothing here moves the LAYOUT: a control is drawn bigger, lifted or sliding, but it is laid out — and clicked — where it always was.
| Field | Type | Default | What it is |
|---|---|---|---|
hover_scale | float | 1 | 1.05: 5% bigger under the pointer |
press_scale | float | 1 | 0.95: 5% smaller while held down |
hover_lift | float | 0 | How far the box rises under the pointer, in design units, its shadow falling further below it: a card lifting off the table. |
speed | float | 0.12f | How long hover and press take to get there, in seconds. |
appear | float | 0 | Arriving: the first frame a box is drawn, it fades in over |
appear_offset | float | 0 | Arriving: the first frame a box is drawn, it fades in over |
appear_scale | float | 1 | Arriving: the first frame a box is drawn, it fades in over |
shake | float | 0.4f |
|
shake_strength | float | 8 |
|
Style
How ONE thing looks: a button, a panel, a label. Every field is optional, and one that is not set comes from around it: the children style of the containers it is in (the nearest wins), then the Theme's style for its kind (theme.styles.button, theme.styles.panel...), then the Theme's colours and metrics.
const rmp::ui::Style gold{
.background = GOLD, .text = BLACK, .radius = 0,
.shadow = rmp::ui::Shadow{}, .text_outline = rmp::ui::TextOutline{ .color = WHITE },
};
rmp::ui::Button buy{ .text = "Buy", .style = gold };Theme::styles holds one for every kind of widget, under them all.
Written in the order you would think of them: the box, its spacing, its text, and how it feels. Designated initialisers have to follow that order.
| Field | Type | Default | What it is |
|---|---|---|---|
background | std::optional<Color> | Its fill. On a button, checkbox, dropdown or field, the hover and press colours are worked out from it — a little lighter, a little darker — unless you give them. | |
background_hover | std::optional<Color> | Its fill. On a button, checkbox, dropdown or field, the hover and press colours are worked out from it — a little lighter, a little darker — unless you give them. | |
background_press | std::optional<Color> | Its fill. On a button, checkbox, dropdown or field, the hover and press colours are worked out from it — a little lighter, a little darker — unless you give them. | |
background_disabled | std::optional<Color> | Its fill. On a button, checkbox, dropdown or field, the hover and press colours are worked out from it — a little lighter, a little darker — unless you give them. | |
skin | std::optional<Skin> | Pictures instead of the fill, per state. See Skin. | |
tint | std::optional<Color> | Multiplies the colours of a skin or an image: WHITE leaves them as drawn. | |
border | std::optional<Color> | The outline's colour; shown when border_width > 0 | |
border_width | std::optional<float> | Design units; 0 = none | |
radius | std::optional<float> | Of the corners, design units; 0 = square | |
shadow | std::optional<Shadow> | Under the box | |
padding_x | std::optional<float> | Inside, left and right | |
padding_y | std::optional<float> | Inside, above and below | |
gap | std::optional<float> | Between the children of a container | |
text | std::optional<Color> | The colour of its text | |
text_disabled | std::optional<Color> | ...when enabled = false | |
font | rmp::Font | A font you loaded: | |
font_size | std::optional<float> | Design units: what | |
text_outline | std::optional<TextOutline> | A font you loaded: | |
text_shadow | std::optional<TextShadow> | A font you loaded: | |
motion | std::optional<Motion> | How it moves; see Motion | |
sounds | Sounds | Per event; see Sounds |
The theme
Theme
Every colour and metric the widgets are drawn with. A default-constructed Theme is the dark theme: theme_dark() returns exactly that.
| Field | Type | Default | What it is |
|---|---|---|---|
background | Color | CLITERAL(Color){ 18, 18, 22, 255 } | The colour behind the interface; no widget paints it. |
panel | Color | CLITERAL(Color){ 30, 30, 38, 255 } | The fill of |
surface | Color | CLITERAL(Color){ 44, 44, 56, 255 } | A NORMAL button at rest, the field of a dropdown and of a text input, a slider's rail, an unticked checkbox's box, and the track of |
surface_hover | Color | CLITERAL(Color){ 60, 60, 76, 255 } | A NORMAL, OUTLINE or GHOST button under the pointer; also a checkbox's row, a dropdown's field and the items of its open list. |
surface_press | Color | CLITERAL(Color){ 26, 26, 34, 255 } | What surface_hover paints, while the pointer is held down on it. |
border | Color | CLITERAL(Color){ 70, 70, 88, 255 } | The outline of an OUTLINE button, of an unticked checkbox's box and of a dropdown's open list; and, when border_width > 0, of a NORMAL button and of a panel that has no border of its own. |
text | Color | CLITERAL(Color){ 235, 235, 242, 255 } |
|
text_muted | Color | CLITERAL(Color){ 150, 150, 168, 255 } |
|
text_on_accent | Color | CLITERAL(Color){ 255, 255, 255, 255 } | The label of a PRIMARY or DANGER button, and the dot of a ticked checkbox. |
primary | Color | CLITERAL(Color){ 88, 120, 245, 255 } | A PRIMARY button at rest, |
primary_hover | Color | CLITERAL(Color){ 110, 140, 255, 255 } | A PRIMARY button under the pointer. |
primary_press | Color | CLITERAL(Color){ 70, 98, 210, 255 } | A PRIMARY button while the pointer is held down on it. |
danger | Color | CLITERAL(Color){ 220, 72, 80, 255 } | A DANGER button at rest, and |
danger_hover | Color | CLITERAL(Color){ 236, 96, 104, 255 } | A DANGER button under the pointer. |
danger_press | Color | CLITERAL(Color){ 184, 56, 64, 255 } | A DANGER button while the pointer is held down on it. |
disabled | Color | CLITERAL(Color){ 60, 60, 70, 255 } | The fill of a control whose |
disabled_text | Color | CLITERAL(Color){ 110, 110, 124, 255 } | The label of a control whose |
focus | Color | CLITERAL(Color){ 130, 170, 255, 255 } | The outline on whatever the keyboard or gamepad is pointing at. Without it a controller build is unusable, so it is a theme colour rather than something each widget decides. |
font_size | float | RMP_UI_FONT_SIZE |
|
font_size_small | float | RMP_UI_FONT_SIZE * 0.8f |
|
font_size_large | float | RMP_UI_FONT_SIZE * 1.4f |
|
padding_x | float | 20 | Inside a button, left and right of the label |
padding_y | float | 12 | Inside a button, above and below the label |
gap | float | 12 | Between siblings |
panel_padding | float | 20 | Inside a |
corner_radius | float | 8 | Of buttons, panels and the controls' fields; 0 = square |
border_width | float | 0 | 0 = the default Theme draws no borders |
control_size | float | 22 | A checkbox's box; the height of a slider's drag area |
track_thickness | float | 6 | A slider's rail |
focus_ring | float | 2 | The outline on the focused control |
transition | float | 0.12f | How long a control takes to reach its new colour, in seconds. Nothing about the layout moves — only colour — so this can never make a button arrive somewhere else than where you clicked. 0 turns it off, which is both the "reduce motion" setting and what a test wants. |
min_touch_size | float | 44 | The shortest a button can be. It follows the button's type size, so a SMALL one may be shorter, except on Android and iOS, where no button is. 44 design units is Apple's touch target guidance and close to Material's 48dp — it is the difference between a menu you can use with a thumb and one you cannot. |
sounds | Sounds | {} | Sounds and motion every widget starts from. Silent in |
motion | Motion | {} | Sounds and motion every widget starts from. Silent in |
styles | | {} | One Style per kind of widget, under every widget of it |
current_theme, set_theme
The theme every widget is drawn with: current_theme() reads it, set_theme() copies a new one over it. There is one stored copy, so the reference current_theme() returns sees every later set_theme(), and a widget drawn after the call already uses the new one. Both work at any time, before the window exists too; until the first set_theme() it is the one [ui] theme names. A metric set_theme() is handed that is NaN, below 0 or past 4096 design units (transition: 60 seconds) is the game's mistake: said once by its name, and theme_dark()'s is kept in its place.
theme_dark, theme_light
The two that come with the framework. Which one starts is [ui] theme in raylib_multiplatform.toml; these let you switch at runtime, which is what an in-game "appearance" setting does:
if (rmp::ui::checkbox("Light Theme", light))
rmp::ui::set_theme(light ? rmp::ui::theme_light() : rmp::ui::theme_dark());They return a copy, so the usual copy-modify-set still applies on top.
Fonts
set_font
The global font, by its name in resources/ ("" = raylib's built-in one).
font_name
The global font's name right now: the last set_font(), or [ui] font.
Scale
scale
The factor in use right now.
set_scale
Pin it, above 0 and at most 16. 0 goes back to automatic; NaN or below 0 is a mistake, said once, and automatic too, and past 16 is 16, said once. This is how you would implement an "interface size" accessibility option.
Breakpoints
Breakpoint
The shape of the screen, by width / height: COMPACT below 1 (taller than it is wide), MEDIUM from 1 up to 1.6, EXPANDED at 1.6 and wider.
| Value | Means | |
|---|---|---|
COMPACT | ||
MEDIUM | ||
EXPANDED |
current_breakpoint
Which Breakpoint the game's area is right now: the window, or under rmp::app::Stretch::LETTERBOX the world inside its bars — the design's shape, whatever the window does. It reads the size when it is called, so it needs no begin() first; a window with no height yet is MEDIUM.
compact
Shorthand for the case that comes up: current_breakpoint() == Breakpoint::COMPACT.
The frame
FrameOptions
How begin() lays out the frame: a root that fills the screen, holding one column that everything you declare goes into. The defaults are the centred menu that begin() with no arguments opens.
| Field | Type | Default | What it is |
|---|---|---|---|
placement | Align | Align::CENTER | Where the root's content sits |
gap | float | -1 | Between children; -1 = the theme's |
padding | float | -1 | Inside the root; -1 = the theme's |
grow | bool | false | False: the column FITS what is in it, so a child that grows fills the column and no more — which is what makes the buttons of a menu one width. true: the column fills the window, less the padding, on both axes, so a child with grow_x or grow_y reaches the edges: a sidebar and a content area that take the whole screen. What does not grow is still placed by |
focus_first | std::optional<bool> | {} | Whether the frame's first control takes the focus by itself, so that Enter and the A button press it the moment it appears. Left unset, the framework decides: yes — which is what keeps a menu three functions long — unless the scene drawing it reads the keys the interface navigates with (Enter, Space, the arrows, Tab, the d-pad, the A button, the left stick) through |
begin
Open the UI for this frame. The default is a centred column, which is what makes a main menu three functions.
end
Lay out, resolve interaction, and draw. Call it between BeginDrawing() and EndDrawing().
Overlays
OverlayOptions
How overlay() covers what is under it, and where its content goes.
| Field | Type | Default | What it is |
|---|---|---|---|
placement | Align | Align::CENTER | Where its content sits, as |
blur | float | 0 | How far to blur what is underneath: the Gaussian's standard deviation in design units, as CSS's |
dim | float | 0.45f | 0..1: how far what is underneath goes towards |
veil | Color | CLITERAL(Color){ 0, 0, 0, 255 } | What it is dimmed towards |
overlay
A frame in front of everything drawn before it. See above.
Widgets
ButtonOptions
How a button() looks, how big it is, and whether it can be pressed.
| Field | Type | Default | What it is |
|---|---|---|---|
style | Variant | Variant::NORMAL | What it means; the theme picks its colours |
size | detail::Sizing | {} | One of the three steps, or a number of design units. The padding and the minimum touch height follow the type size, so a large button is a large button all over rather than a normal one with bigger letters. |
enabled | bool | true | False = the theme's disabled colours; no press, no focus |
id | std::string_view | {} | Only needed when two buttons share a label AND the UI is conditional. Identical labels in one frame are already told apart automatically. Empty means none. It is hashed on the spot, so a temporary is fine. |
TextOptions
How text() paints a string: its colour, its size, and whether it wraps.
| Field | Type | Default | What it is |
|---|---|---|---|
color | ColorRole | ColorRole::TEXT | Which theme colour it is painted in |
size | detail::Sizing | {} | A step, a number, or nothing for the theme's |
wrap | bool | true | Break between words to fit; false = never broken to fit |
RichTextOptions
Text with markup, drawn a letter at a time: Yarn's markup, which a dialogue line already carries --
rmp::ui::rich_text("A [wave]strange[/wave] [color=#ffcc00]light[/color]!");[b] bold [color=#rrggbb] or [color=red]
[size=30] in design units [wave] [shake] [rainbow]: moving lettersIts visible letters, the rest held back: a typewriter counts them up.
| Field | Type | Default | What it is |
|---|---|---|---|
width | float | 0 | Wrap at this many design units; 0 = the width it is given |
size | detail::Sizing | {} | A step, a number, or nothing for the theme's |
color | ColorRole | ColorRole::TEXT | The colour of what no |
visible | int | -1 | How many letters show; -1 = every one |
id | std::string_view | {} | As |
rich_text
rich_text_length
How many letters a rich text has once its markup is gone: where a typewriter stops.
button
True on the frame it is pressed: the pointer released over it, or, while it has the focus, Enter or the gamepad's accept button. Reads as it looks:
if (rmp::ui::button("Play")) play();ImageButtonOptions
How image_button() is sized, and whether it can be pressed. Sizes are in design units.
| Field | Type | Default | What it is |
|---|---|---|---|
width | float | 0 | 0 = the picture's own width, scaled |
height | float | 0 | 0 = the picture's own height, scaled |
enabled | bool | true | False = the disabled tint; no press, no focus |
id | std::string_view | {} | It has no label to be told apart by, so two image buttons that come and go are told apart by this. Empty = by its order among the unnamed ones. |
image_button
A button that is a picture: an icon, an inventory slot, a skinned "Play" drawn by your artist. Pressed like button(), focusable like button(), and it wears theme.styles.button — its skin behind the picture, its sounds.
if (rmp::ui::image_button(gear)) open_settings();text
The string is copied immediately, so a temporary is safe:
rmp::ui::text(std::to_string(score));Containers
BoxOptions
Shared by every container. All measurements are in design units and are scaled; -1 means "whatever the theme says".
| Field | Type | Default | What it is |
|---|---|---|---|
gap | float | -1 | Between children |
padding | float | -1 | Inside this container; -1 = none, panel_padding in a panel |
items | Align | Align::CENTER | Where children sit in the leftover space |
grow_x | bool | false | Sizing is interleaved by axis — x then y — rather than grouped by kind, and that is not cosmetic. Designated initialisers have to be written in declaration order, so grouping them as grow_x, grow_y, width, height would make { .width = 240, .grow_y = true } illegal: a fixed-width sidebar that fills the height, which is about the most ordinary thing anyone writes. This way round, every combination is legal. |
width | float | 0 | > 0 = a fixed width, overriding fit/grow |
grow_y | bool | false | Fill the parent's height instead of fitting content |
height | float | 0 | > 0 = a fixed height, overriding fit/grow |
id | std::string_view | {} | A stable name for the container: the same element from frame to frame, whatever else is on screen. Nothing in |
PanelOptions
A panel is a box with a background, which is what makes it visible.
| Field | Type | Default | What it is |
|---|---|---|---|
box | BoxOptions | {} | The layout, as |
background | Color | CLITERAL(Color){ 0, 0, 0, 0 } | {0,0,0,0} = the theme's panel |
radius | float | -1 | -1 = the theme's |
border | Color | CLITERAL(Color){ 0, 0, 0, 0 } | {0,0,0,0} = the theme's border, drawn only when the theme's border_width is above 0 (it is 1 in |
border_width | float | -1 | Of |
ImageOptions
How image() sizes and tints a texture. Sizes are in design units.
| Field | Type | Default | What it is |
|---|---|---|---|
grow | bool | false | Fill the space available |
width | float | 0 | Otherwise: 0 = the texture's own width, scaled |
height | float | 0 | 0 = the texture's own height, scaled |
tint | Color | WHITE | Multiplies the texture's colours; WHITE leaves them as they are |
ProgressOptions
How progress() sizes and colours its bar. Sizes are in design units.
| Field | Type | Default | What it is |
|---|---|---|---|
width | float | 0 | 0 = fill the space available |
height | float | -1 | -1 = derived from the theme's font size |
radius | float | -1 | -1 = half the height, for round ends |
fill | Color | CLITERAL(Color){ 0, 0, 0, 0 } | {0,0,0,0} = the theme's primary |
track | Color | CLITERAL(Color){ 0, 0, 0, 0 } | {0,0,0,0} = the theme's surface |
id | std::string_view | {} | Names the bar, as |
row
Left to right.
column
Top to bottom.
panel
A column with a background and padding: the thing you put a dialog in.
center
Takes all the space it is given and puts its contents in the middle of it.
stack, layer
Layers, drawn back to front. Each child has to be a layer():
rmp::ui::stack([&]{
rmp::ui::layer([&]{ rmp::ui::image(background); });
rmp::ui::layer([&]{ rmp::ui::text("PAUSED"); });
});The explicit layer() is not ceremony — it is what tells the layout which things are supposed to overlap and which are ordinary children.
spacer
Eats the space left over, which is how you push things apart:
rmp::ui::row({ .grow_x = true }, []{
rmp::ui::text("Health");
rmp::ui::spacer(); // <- shoves the score to the right
rmp::ui::text("999");
});More widgets
image
The Texture2D is copied on the way in, so the struct you pass may be a temporary. What the copy holds is a GPU handle, though, so the texture itself has to stay loaded until end() has drawn the frame: keep the rmp::Texture that owns it, as a member or a global. A temporary rmp::Texture does not compile here — image(rmp::assets::load_texture("icon.png")) would unload the texture at the semicolon. By default it is drawn at its own size, scaled with the rest of the UI.
progress
A bar. fraction is 0..1 and is clamped; NaN — hp / max_hp with no max_hp — is an empty bar, said once.
Grid and scroll
GridOptions
How grid() counts its columns, spaces its cells, and how much room it takes. Measurements are in design units, and -1 means the default given beside it.
| Field | Type | Default | What it is |
|---|---|---|---|
columns | int | 0 | 0 = as many as fit, at least one, recomputed as the window changes |
min_cell | float | 96 | Only used when columns = 0 |
gap | float | -1 | Between cells and between rows; -1 = the theme's |
padding | float | -1 | Inside the grid; -1 = none |
grow_x | bool | true | A grid almost always wants the width it is offered |
grow_y | bool | false | Fill the parent's height instead of fitting the rows |
id | std::string_view | {} | A name for the grid. columns = 0 reads the width the grid had last frame and finds it by this name; without one, by its order among the unnamed grids of the pass, which a grid that comes and goes before it changes. |
ScrollOptions
How scroll() clips its contents, spaces them, and how much room it takes. Measurements are in design units, and -1 means the default given beside it.
| Field | Type | Default | What it is |
|---|---|---|---|
horizontal | bool | false | Vertical by default, which is what lists want |
vertical | bool | true | Clip and scroll top to bottom |
gap | float | -1 | Between children; -1 = the theme's |
padding | float | -1 | Inside the area; -1 = none |
grow_x | bool | true | Fill the parent's width |
width | float | 0 | > 0 = a fixed width, overriding grow_x |
grow_y | bool | true | Fill the parent's height, and clip there. In a parent that fits its contents, that is the room left in the window: the rows never push it. |
height | float | 0 | > 0 = a fixed height, overriding grow_y |
id | std::string_view | {} | A name for the area. Without one it is told apart by its order among the unnamed scroll areas of the pass, so an area that comes and goes before it changes which one it is. |
grid
Equal columns, as many rows as it takes. Each item goes in a cell(), which is what lets the grid count them and start a new row at the right moment — the layout engine underneath wraps text, not elements, so the rows are real rows.
rmp::ui::grid(4, [&]{
for (auto &item : inventory)
rmp::ui::cell([&]{ rmp::ui::image(item.icon); });
});With columns = 0 it works out how many fit in the width it has and works it out again when the window changes, which is what an inventory should do rather than staying at the number someone typed on a desktop.
cell, grid
One item in a grid. Every child of a grid has to be one.
scroll
Clips its contents and scrolls them. The wheel works, and so does dragging with a finger — the same gesture on a phone.
Controls that own a value
CheckboxOptions
Whether a checkbox() can be toggled, and the name that tells it apart.
| Field | Type | Default | What it is |
|---|---|---|---|
enabled | bool | true | False = the theme's disabled colours; no toggle, no focus |
id | std::string_view | {} | As |
SliderOptions
How a slider() is sized, stepped and shown. Sizes are in design units.
| Field | Type | Default | What it is |
|---|---|---|---|
width | float | 0 | 0 = fill the space available |
step | float | 0 | 0 = continuous; otherwise snap to multiples |
enabled | bool | true | False = the theme's disabled colours; no drag, no focus |
show_value | bool | true | Draw the position, as a percentage, after the bar |
id | std::string_view | {} | As |
DropdownOptions
How a dropdown() is sized, and whether it can be opened.
| Field | Type | Default | What it is |
|---|---|---|---|
width | float | 0 | Of the field, in design units; 0 = fill the space available |
enabled | bool | true | False = the disabled text colour; no opening, no focus |
id | std::string_view | {} | As |
TextInputOptions
How a text_input() is sized, what it shows while it is empty, and how much it takes.
| Field | Type | Default | What it is |
|---|---|---|---|
width | float | 0 | Of the field, in design units; 0 = fill the space available |
enabled | bool | true | False = the theme's disabled colours; no typing, no focus |
placeholder | rmp::Text | {} | Shown in the theme's text_muted while the field is empty and does not have the focus. It is copied, so a temporary is fine. |
id | std::string_view | {} | As |
max_length | int | 0 | The most CHARACTERS it holds — what the player counts, so an "é" is one and not the two bytes it takes. 0 = no limit. Typing stops at it, and a longer value you hand in is cut to it on the frame the field is drawn, never inside a character. |
checkbox
A box that flips value when it is clicked, or activated from the keyboard or a gamepad while it has the focus. True on the frame it flipped.
slider
A bar that sets value between min and max: dragged, or moved with left and right while it has the focus, one step (or 5% of the range) per press, then twelve a second while held. value is clamped to the range, and snapped to step when there is one, on every call; true on any frame that changed it. Nothing is drawn when max <= min — nor when an end is NaN or an infinity, which is said once. A value that is NaN is set to min, and a step that is not a positive number is none, each said once.
dropdown
selected is the index into items, and is kept inside it.
rmp::ui::dropdown("Quality", quality, { "Low", "Medium", "High" });A list written in place, as above, or any array of string_views you keep — std::array, std::vector, a C array — they are copied on the way in. A click, or Enter or the A button while it has the focus, opens the list. Open and focused, up and down walk its items instead of moving the focus, Enter or A picks the one they are on, and Escape or B closes it without changing anything. True on the frame selected changed. Nothing is drawn for an empty list.
text_input
Edits your string, in UTF-8 — what the player types goes on the end, and Backspace takes off the last character, never half of one — and only while the field has the keyboard; TextInputOptions::max_length caps it. True on the frame it changed. It takes the keyboard when it is clicked, when the focus is moved onto it (Tab, the arrows, the d-pad, focus()), or when Enter, Space or the A button is pressed while it has the focus — but not from the focus a screen gives its first control by itself. It gives it back on Enter or the A button (Space is typed), on Escape or the B button, and on a click anywhere else; the focus stays on it. Tab, up and down move the focus on from a field as from any other control, and take the keyboard with them.
Over the world, over a control, over everything
AtOptions
Where at() puts its box, relative to the point it follows.
| Field | Type | Default | What it is |
|---|---|---|---|
anchor | Align | Align::BOTTOM_CENTER | The point of the box that sits on the world position: BOTTOM_CENTER puts the box above it, which is where a health bar or a name goes. |
offset | Vector2 | { 0, 0 } | Design units, after projecting: { 0, -8 } lifts it |
id | std::string_view | {} | A stable name for the box, as |
at
A box over a point of the WORLD, wherever the scene's camera shows it — zoomed, scrolled, shaken and stretched with it. Between begin() and end(), in the scene's _draw(), like everything else here:
rmp::ui::begin();
for (const rmp::Handle<Enemy> &e : enemies)
if (e) rmp::ui::at(e->position, [&] { rmp::ui::progress(e->hp / 10.0f); });
rmp::ui::end();What it paints does not take the pointer: a click on the enemy under its health bar still reaches the enemy. A control inside it is a control like any other — it can be clicked and focused where it is drawn. While the point is off the screen the box is not drawn at all, and nothing in it takes the pointer, the focus or the keys. Without scenes there is no camera, and the world is the screen.
Dialogue presenters
Portrait
A speaker's picture, and one for each mood a line's #mood:happy names.
| Field | Type | Default | What it is |
|---|---|---|---|
speaker | std::string | The name before the colon of a line: "Mika" | |
mood | std::string | {} | Empty: the picture for any mood without its own |
picture | Picture | {} | A texture, an atlas region, a sprite's frame or a nine-slice |
Speaker
Who speaks, as they look and sound: their lines in a box of their own, their name plate, their voice. Unset fields are the presenter's.
| Field | Type | Default | What it is |
|---|---|---|---|
name | std::string | The name before the colon of a line: "Mika" | |
blip | SoundName | {} | Their blip; empty: the flow's |
pitch | float | 1 | Their blip's pitch: 1.3 higher, 0.8 lower |
style | Style | {} | Over the presenter's style, for their lines |
name_style | Style | {} | Over the presenter's name_style |
DialogueSide
Which side of the box a portrait sits on.
| Value | Means | |
|---|---|---|
LEFT | Before the line | |
RIGHT | After it |
DialogueChoices
Where a box puts the choices.
| Value | Means | |
|---|---|---|
IN_BOX | In the box, in place of the line | |
ABOVE | In a panel of their own above the box, at its right | |
CENTER | In a panel in the middle of the screen |
DialogueFlow
How a presenter types a line out, and goes on.
| Field | Type | Default | What it is |
|---|---|---|---|
letters_per_second | float | 45 | The typewriter; 0 = the whole line at once |
blip | SoundName | {} | A sound as the letters appear |
blip_every | int | 2 | Letters between two blips |
blip_jitter | float | 0 | Each blip's pitch moves by up to this: 0.08 = 8 % |
auto_advance | float | 0 | Seconds a whole line stays before it goes on; 0 = wait |
skip_seen | bool | false | A line already read goes by at once |
voices | std::string | {} | A recorded line: the sound named voices + its id ("vo/hello") |
choice_seconds | float | 0 | A timed choice: seconds to choose; 0 = no timer |
default_choice | int | 0 | What a timed choice takes when the time is up |
DialogueMemory
What a presenter remembers from one frame to the next.
| Field | Type | Default | What it is |
|---|---|---|---|
line_id | std::string | The line on screen | |
shown | float | 0 | Letters typed so far |
length | int | 0 | Letters in the line |
waited | float | 0 | Seconds since it was all shown, or of a [pause] |
choice_left | float | 0 | Seconds left of a timed choice |
blips | int | 0 | Blips played for this line |
history | std::vector<std::pair<std::string, std::string>> | Speaker, line: read so far | |
seen | std::vector<std::string> | The ids of the lines read | |
stage | std::vector<std::string> | DialogueStage: who is on stage, left to right | |
entered | std::vector<float> | DialogueStage: seconds each has been on stage | |
focus | std::vector<float> | DialogueStage: 0..1, how much each is the speaker | |
shaking | float | -1 | DialogueStage: seconds into a |
shake_strength | float | 0 | ...how far, in design units |
shake_seconds | float | 0 | ...how long |
flashing | float | -1 | DialogueStage: seconds into a |
flash_seconds | float | 0 | ...how long |
flash_color | Color | WHITE | ...of which colour |
showing_history | bool | false |
|
dialogue_line
A presenter's pieces, for a presenter of your own: the dialogue's line, typed out where the call is in your layout — its [speed] and [pause], its blips and recorded voice, auto-advance, skip-seen, and a click or Enter going on (on the line, or the next button it draws after it). True while there is a line. The flow blip is the one played: a Speaker's is yours to put in it.
dialogue_choices
The choices, as buttons in a column where the call is, and a timed choice's bar. True while there are choices.
BubbleSpeaker
Who a bubble points at: a speaker by name, and the object that speaks.
| Field | Type | Default | What it is |
|---|---|---|---|
name | std::string | The speaker of the lines it says | |
object | rmp::Handle<rmp::Object> | {} | What it is drawn over; empty: where the UI puts it |
offset | Vector2 | { 0, -18 } | From the object's position, in world units |
blip | SoundName | {} | Their blip; empty: the flow's |
pitch | float | 1 | Their blip's pitch |
style | Style | {} | Over the bubble's style, for their lines |
DialogueBubble
A bubble over the speaker's head, in the world (rmp::ui::at()), the choices in it too. The world goes on around it.
| Field | Type | Default | What it is |
|---|---|---|---|
speakers | std::vector<BubbleSpeaker> | {} | Who says what, and over which object |
flow | DialogueFlow | {} | The typewriter, the blips, auto-advance, timed choices |
width | float | 220 | Design units: the line wraps inside it |
tail | float | 10 | Design units: the tail under it, to the speaker; 0 = none |
tail_color | Color | CLITERAL(Color){ 0, 0, 0, 0 } | The tail's colour; { 0, 0, 0, 0 } = the bubble's background, or the theme's panel. A bubble of art draws its own: give it a tail_picture. |
tail_picture | Picture | {} | Drawn in the tail's place, 2 tails wide, 1 tall |
pauses_world | bool | false | The world goes on around a bubble |
style | Style | {} | The bubble |
choice_style | Style | {} | Each choice |
ours | DialogueMemory | Its state between frames; yours to read |
Draws the line or the choices, and takes the player's answer. True while the dialogue has something to show.
TooltipOptions
How tooltip() places its line, and how long it waits.
| Field | Type | Default | What it is |
|---|---|---|---|
side | Align | Align::TOP_CENTER | Which side of the control it appears on |
delay | float | 0.5f | Seconds the pointer rests on the control before it shows; infinity: never by the pointer, by the focus alone. |
tooltip
A line about the control declared just before it, shown while the pointer rests on that control, or while the keyboard or gamepad focus is on it:
if (rmp::ui::button("Sell")) sell(item);
rmp::ui::tooltip("Gives you half of what it cost");The text is copied. One with no control before it in the frame is reported once and shows nothing. An empty one shows nothing and is no mistake: tooltip(item.description) for an item without one.
NotifyOptions
How long notify() keeps a message, and its colour.
| Field | Type | Default | What it is |
|---|---|---|---|
seconds | float | 3 | On screen for this long, then it fades out |
color | ColorRole | ColorRole::TEXT | Which theme colour the text is painted in |
notify
A short message at the bottom of the screen that goes away by itself: "Saved", "Achievement unlocked". Call it from anywhere — _update(), a callback, a frame with no UI — because it only queues: the framework draws what is queued over everything else, and it never takes the pointer or the focus. The newest few are shown, one above the other. (In a game with its own frame hook they are drawn over the frame's first begin()/end(), there being no telling which end() is the last; and a frame of its that describes no interface draws none, so they wait, no older, for the next one that does.)
In a debug build the framework's own warnings arrive here too: a mistake it reports once in the log (an action nobody defined, a widget outside begin()/end()) is also said on screen, where it cannot scroll past.
Input, and who gets it
wants_pointer
The pointer is over the interface, or the interface is using it (dragging a slider). "Over the interface" is over anything it paints as a surface: every control, every box with a background colour or a border (a panel, a progress bar, an open dropdown list), an image, and a scroll area, empty part included — but not where a scroll area has clipped its contents away. Plain text with nothing behind it is NOT: a score drawn over the game does not stop the game being clicked through it.
wants_keyboard
A text field has the keyboard, so the keys are its own: see text_input(). Having the focus is not enough — a field the player pressed Enter on keeps the focus and gives the keyboard back. And a HUD over a game being played that the player walked into with Tab, or whose control the game chose with focus(), has the keys until Escape, the B button, a click elsewhere or set_navigation_enabled(false): see FrameOptions::focus_first.
Focus, keyboard and gamepad
focus
Give a named control the focus — when a menu opens, or to point a controller at something other than the first control. Pass "" to clear it. A focus asked for by name is drawn straight away: you meant it, and a text field given it takes the keyboard. id is the control's label, or its explicit .id.
Outside begin()/end() — in a scene's _ready(), say — it waits for the next frame that draws controls and lands on the first one carrying that name, whichever scene draws it; if that frame has none, the request is dropped and the screen keeps its own default. On a HUD over a game being played it is the game choosing that control, as Tab would be: the keys are the interface's until Escape, the B button or a click elsewhere.
focused
What has the focus right now, or "" if nothing does.
Events
EventKind
What a control did.
| Value | Means | |
|---|---|---|
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 | Shake() was called on it |
WidgetKind
Which kind of widget an event came from.
| Value | Means | |
|---|---|---|
BUTTON | ||
LABEL | ||
IMAGE | ||
PANEL | ||
CHECKBOX | ||
SLIDER | ||
DROPDOWN | ||
TEXT_INPUT | ||
PROGRESS |
Event
One event. name is the control's label, or its id when it has one; it is valid during the call only.
| Field | Type | Default | What it is |
|---|---|---|---|
kind | EventKind | EventKind::CLICK | What happened |
widget | WidgetKind | WidgetKind::BUTTON | To which kind of widget |
name | std::string_view | {} | Its label or id |
on_event
The one hook every event goes to, after its sound. Setting it again replaces it; an empty one — rmp::ui::on_event({}) — turns it off.
Widgets you keep
KeptState
What a kept widget remembers between frames.
| Field | Type | Default | What it is |
|---|---|---|---|
hovered | bool | false | The pointer is on it |
pressed | bool | false | Held down on it |
focused | bool | false | It has the focus |
shakes | int | 0 |
|
Lifecycle
shutdown
Called for you by the entry point macro, before on_exit() — while the window is still open, because releasing a font after CloseWindow() would be touching a GL context that no longer exists.
There is no init(): the UI starts itself on the first begin(), by which time there is a window. A game that never draws UI allocates nothing.