On this page
  1. Themes
  2. Colours
  3. Variants
  4. Sizes
  5. Metrics
  6. Transitions
  7. Breakpoints and scale
  8. Styles
    1. Where a style comes from
    2. One style for every widget of a kind
    3. A look for everything inside a container
    4. A number that is no number
  9. Pictures
    1. Nine-slices
    2. Slices of an Aseprite file
    3. An image you can press
  10. Skins
  11. Shadows and outlines
  12. Motion
  13. Sounds
  14. Fonts
    1. Changing it while the game runs
    2. A font for one widget
    3. Every letter, on demand

Interface style

A control in rmp::ui says what it means — primary, danger, a muted line of text — and how important it is — small, medium, large — and the theme decides what that looks like. Restyling a game is then one theme, and no call site is revisited. When one widget, or one screen, has to look like nothing else — a shop drawn by an artist, a title with an outline, a button that grows under the pointer — a style says so for that widget and everything inside it, over the theme, and the simple calls stay as they are.

The light theme: white panels, a row of buttons in blue, grey and red variants, two disabled buttons, and the Light Theme checkbox ticked
The light theme and button variants — examples/ui/06_style
The Star Shop: a panel framed by a gold nine-slice, buttons skinned with pictures, coin and star icons and a pixel font
A skin: pictures, nine-slices and a font of the game — examples/ui/09_skinned
rmp::ui::button("Start game", { .style = rmp::ui::Variant::PRIMARY, .size = rmp::ui::Size::LARGE });
rmp::ui::text("v1.0.2", { .color = rmp::ui::ColorRole::MUTED, .size = rmp::ui::Size::SMALL });

Themes#

A rmp::ui::Theme is plain data: every colour the widgets are drawn with, as raylib's Color, and every metric, in design units. There is no inheritance, no cascade and no stylesheet. Customising one is assignment — copy it, change what you want, set it back:

rmp::ui::Theme theme = rmp::ui::current_theme();
theme.primary = GOLD;
theme.primary_hover = YELLOW;
theme.primary_press = ORANGE;
theme.corner_radius = 0; // square corners
rmp::ui::set_theme(theme);

current_theme() returns the one theme in use, and set_theme() copies a new one over it. Anything drawn after the call uses the new one, in the same frame. Both work at any time, before the window exists too.

Two themes come with the framework, theme_dark() and theme_light(). Each returns a copy, so the same copy-modify-set works on top of either. Which one the game starts with is [ui] theme:

[ui]
theme = "light"

Only those two names exist, and a typo is refused when the configuration is read instead of falling back to dark at runtime:

[ui]
theme = "blue"
  raylib_multiplatform.toml:2: theme = "blue"
                               ^^^^^^^^^^^^^^

  configure: error: [ui] theme has to be one of dark, light, got 'blue'.
                    It only picks which one the app starts with — rmp::ui::set_theme() changes it at runtime.

After that it is a runtime call, so an appearance setting in the game is one line:

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

The dark theme is a default-constructed Theme; its values are the member initialisers in include/rmp/ui.h. The light one is not the dark one with the numbers flipped. A dark interface separates its surfaces with their own shadows and a light one has none, so the light theme sets border_width to 1, and normal buttons and panels get an outline that keeps a pale button on a pale page a button. Its accents are darker, because the blue that reads as bright on near-black looks washed out on near-white, and white text on it stops being legible.

Colours#

Each colour of the theme has a job, and these are all of them:

FieldPaints
backgroundBehind the interface. No widget paints it: a game of scenes is cleared with it every frame unless the scene sets its own background; a loop of your own passes it to ClearBackground().
panelA panel, and a dropdown's open list.
surfaceA normal button at rest, the field of a dropdown and of a text field, a slider's rail, an unticked checkbox, the track of a progress bar.
surface_hover, surface_pressA normal, outline or ghost button under the pointer, and while the pointer is held down on it; also a checkbox's row, a dropdown's field and the items of its open list.
borderAn outline button, an unticked checkbox, a dropdown's open list; and normal buttons and panels when border_width is above 0.
textText, the labels of normal, outline and ghost buttons and of every control.
text_mutedMuted text, a slider's percentage, a text field's placeholder.
text_on_accentThe label of a primary or danger button, and the dot of a ticked checkbox.
primary, primary_hover, primary_pressA primary button in its three states; also primary text, a ticked checkbox, the filled part of a slider and of a progress bar.
danger, danger_hover, danger_pressA danger button in its three states; also danger text.
disabled, disabled_textThe fill and the label of a button or control whose enabled is false: the fill is a button's, a checkbox's box, a slider's filled part and a text field's field. A disabled dropdown keeps surface for its field and greys only its label and value.
focusThe ring around whatever the keyboard or gamepad is on. A controller build cannot be used without it, which is why it is the theme's and not each widget's.

Text picks one of four of these through a ColorRole, never a colour of its own: TEXT is text, MUTED is text_muted, PRIMARY is primary and DANGER is danger.

Variants#

A button's style is a Variant: what the button is for, not what colour it is.

VariantForLooks
NORMALMost buttons; the default.A filled surface.
PRIMARYThe one thing you want pressed on this screen.primary, with text_on_accent.
DANGERSomething destructive, which should look it.danger, with text_on_accent.
OUTLINEA secondary action.An outline and a label; it fills in under the pointer.
GHOSTToolbars, "back" links.The label alone, in either theme, until the pointer is on it.
rmp::ui::row({ .grow_x = true }, [&] {
    rmp::ui::button("Start game", { .style = rmp::ui::Variant::PRIMARY });
    rmp::ui::button("Load");
    rmp::ui::button("Settings", { .style = rmp::ui::Variant::OUTLINE });
    rmp::ui::button("Back", { .style = rmp::ui::Variant::GHOST });
    rmp::ui::button("Delete", { .style = rmp::ui::Variant::DANGER });
});

Being disabled is not a sixth variant, because it can happen to any of them: it is the enabled flag, and a disabled button of any variant is drawn in disabled and disabled_text.

Sizes#

Anywhere a size is asked for — a button's, a text's — the same field takes one of three steps of the theme's type scale, or a plain number of design units:

rmp::ui::button("Play", { .size = rmp::ui::Size::LARGE });
rmp::ui::text("Chapter One", { .size = 34 });
StepTheme fieldDefault
Size::SMALLfont_size_small0.8 × [ui] font_size
Size::MEDIUMfont_size[ui] font_size, 20 unless set
Size::LARGEfont_size_large1.4 × [ui] font_size

The steps are what to reach for almost always: they come from the theme, so they stay in proportion when someone changes the type scale. A number is the escape hatch — for a title, not for a button. It is one field that takes two spellings rather than two fields that could disagree.

On a button the step moves the type, the padding and the minimum height together, so a large button is large all over and not a normal one with bigger letters. The one exception is a touch screen: on Android and iOS no button is shorter than min_touch_size, small ones included. The labels of checkboxes, sliders, dropdowns and text fields are always at font_size.

The three type sizes are three fields of the theme. Changing font_size moves the medium step only, so making all the text bigger is all three:

rmp::ui::Theme theme = rmp::ui::current_theme();
theme.font_size *= 1.15f;
theme.font_size_small *= 1.15f;
theme.font_size_large *= 1.15f;
rmp::ui::set_theme(theme);

Metrics#

The rest of the theme is measurements, every one in design units:

FieldDefaultIs
padding_x20Inside a button, left and right of the label.
padding_y12Inside a button, above and below it.
gap12Between siblings.
panel_padding20Inside a panel, and around what begin() lays out.
corner_radius8Of buttons, panels and the controls' fields; 0 is square.
border_width0 dark, 1 lightThe outline of normal buttons and of panels; 0 draws none.
control_size22A checkbox's box, and the height of a slider's drag area.
track_thickness6A slider's rail.
focus_ring2The outline on the focused control.
min_touch_size44The shortest a button can be: Apple's touch-target guidance, close to Material's 48 dp. It follows a button's type size, except on Android and iOS.
transition0.12Seconds, not design units: how long a colour takes to change. See below.

Transitions#

Controls fade between their colours — at rest, under the pointer, pressed — instead of snapping, and a checkbox's box fills in instead of switching. There is nothing to opt into and one knob, transition, the time a change takes. A control seen for the first time starts at the colour it should have, so nothing fades in from nowhere.

A transition moves only colour. Nothing about the layout is animated, so a control is always exactly where it was drawn and an animation can never make the player miss what they aimed at. A style's motion — growing under the pointer, a panel sliding in — moves the drawing and never the layout either, and is off unless a game asks for it. transition = 0 turns it off — every control takes its new colour on the frame it changes — which is what a "reduce motion" setting does:

rmp::ui::Theme theme = rmp::ui::current_theme();
theme.transition = reduce_motion ? 0.0f : 0.12f;
rmp::ui::set_theme(theme);

Breakpoints and scale#

Two mechanisms make an interface fit a screen, and knowing which to reach for is most of the skill. The scale makes everything bigger or smaller together; it is automatic, and you rarely touch it. A breakpoint changes the shape of a layout, which no amount of growing, fitting or fixing can do: on a phone held upright, a sidebar beside the content has to go above it.

if (rmp::ui::compact()) {
    rmp::ui::column([&] { sidebar(); content(); });
} else {
    rmp::ui::row([&] { sidebar(); content(); });
}

current_breakpoint() classifies the screen by its aspect ratio, width over height, and compact() is the case that comes up:

BreakpointWidth ÷ heightIn practice
COMPACTbelow 1A phone held upright, a narrow window.
MEDIUM1 up to 1.6A tablet, a small desktop window, 4:3.
EXPANDED1.6 and widerAn ordinary desktop, a TV, a phone on its side.

Aspect ratio and not pixels, deliberately: a pixel threshold would call a phone 1080 pixels wide a desktop, and the scale has already dealt with how big everything is. What is left — the only thing that decides whether a row still fits — is how wide the screen is next to how tall. It reads the window's size when it is called, so it needs no begin() first; a window with no height yet is MEDIUM.

More exactly, it is the shape of the game's area. Under [window] stretch "letterbox" — the default of a game rmp new makes — that is the design inside its bars, the same shape whatever the window does, and the breakpoint never changes. An interface that should change shape with the window wants "none" or "expand", which give it the whole window; the responsive example sets NONE for that reason.

Reach for a breakpoint when the layout has to become a different layout. Using one to pick a size undoes the work the scale already did, and is how a layout ends up right on exactly one machine. The responsive example turns a sidebar and its content from a row into a column as the window is resized.

Styles#

A rmp::ui::Style is how one thing looks: a button, a panel, a line of text. Every field is optional, and a field left unset is taken from around it. A widget you keep has one in its style field:

const rmp::ui::Style gold{
    .background = GOLD,
    .radius = 0,
    .shadow = rmp::ui::Shadow{},
    .text = BLACK,
    .text_outline = rmp::ui::TextOutline{ .color = WHITE },
};
rmp::ui::Button buy{ .text = "Buy", .style = gold };

The fields are written in the order they are declared — C++20 requires it of designated initialisers — and they are declared in the order you would think of them: the box, its spacing, its text, and how it feels.

FieldTypeIs
backgroundColorThe fill of the box. On a button, a checkbox, a dropdown or a field, the hover and press colours are worked out from it — a little lighter, a little darker — unless the next two give them.
background_hoverColorThe fill under the pointer. Given without a background, it is used alone over the theme's fill.
background_pressColorThe fill while held down; alone too, like the one above.
background_disabledColorThe fill when enabled is false.
skinSkinPictures instead of the fill, one per state. See skins.
tintColorMultiplies the colours of a skin or an image; WHITE leaves them as drawn.
borderColorThe outline's colour, drawn when border_width is above 0.
border_widthfloatThe outline's width in design units; 0 draws none.
radiusfloatThe corners, in design units; 0 is square.
shadowShadowA soft shadow under the box. See shadows and outlines.
padding_xfloatInside, left and right, in design units. On a panel it is its padding all round.
padding_yfloatInside, above and below.
gapfloatBetween the children of a container.
textColorThe colour of its text, over the role a call gives it.
text_disabledColorThe same, when enabled is false.
fontrmp::FontA font you loaded. The interface draws with that font's file; see fonts. An empty one is inherited.
font_sizefloatWhat Size::MEDIUM is here, in design units. SMALL and LARGE follow it, in proportion.
text_outlineTextOutlineAn outline around every letter.
text_shadowTextShadowA copy of the text under it, offset.
motionMotionHow it moves under the pointer, as it appears and when it shakes. See motion.
soundsSoundsA sound per event. See sounds.

Every field but font and sounds is a std::optional, and "unset" is what it says: not 0, not black. font is unset when it is an empty handle, and each sound of sounds is an optional of its own.

Where a style comes from#

A field a widget's own style leaves unset is looked for, in this order, and the first that sets it wins:

  1. the widget's own style;
  2. the children style of the Panels it is inside, the nearest first;
  3. the theme's style for its kind of widget, Theme::styles;
  4. the theme's own colours and metrics, as the rest of this page describes them.

Inside a widget, current_theme() answers with the theme as that style changes it, so every widget reads its style the way it already read the theme, and a style can do nothing the theme could not do on its own but for one widget.

One style for every widget of a kind#

Theme::styles holds one Style for each kind of widget. What is set there is how every widget of that kind looks before its own style — the ones written the simple way, rmp::ui::button("Play"), included. A skinned game is then one theme, and its menus stay three lines:

rmp::ui::Theme theme = rmp::ui::current_theme();
theme.styles.button.skin = rmp::ui::Skin{ .normal = frame };
theme.styles.button.text = WHITE;
theme.styles.panel.shadow = rmp::ui::Shadow{};
rmp::ui::set_theme(theme);
Field of stylesUnder
buttonbutton(), image_button(), Button
labeltext(), Label
imageimage(), Image
panelpanel(), Panel
checkboxcheckbox(), Checkbox
sliderslider(), Slider
dropdowndropdown(), Dropdown
text_inputtext_input(), TextInput
progressprogress(), ProgressBar

Two of them are not empty in theme_dark() and theme_light(), and they are the framework's own look. styles.button grows a button 3 % under the pointer, gives it 3 % while it is held, and sits it on a soft shadow; styles.panel puts a panel on a deeper shadow and fades it in, rising 10 design units, over 0.18 seconds the first frame it is drawn — an overlay's panel included, so a pause menu arrives instead of appearing. The light theme's shadows are the same, fainter. There is never a text shadow by default. The other seven are empty, and so are the theme's sounds and motion: silent.

rmp::ui::Theme theme = rmp::ui::theme_dark();
theme.styles.button.shadow.reset();         // buttons with no shadow, still growing
theme.styles.panel = {};                    // panels as flat and still as text
rmp::ui::set_theme(theme);

A Style{} is empty, so theme.styles.panel = {} takes the whole look of panels away. theme.styles = {} is not that: it is a new Styles, which has the framework's look in it again.

A look for everything inside a container#

A kept Panel has two styles, the way a Godot container has its own theme override and one for its children: style is how the panel itself looks, and children is a style every widget inside it inherits, however deep. Panels nest, and the nearest one's wins:

rmp::ui::Panel shop{
    .style = { .background = DARKBROWN, .shadow = rmp::ui::Shadow{} },
    .children = { .text = GOLD, .font = title },
};
shop.show([] {
    rmp::ui::text("Shop");
    rmp::ui::button("Buy");
});

With background = false a panel is a bare row or column — no fill of its own unless its style gives one, no padding unless asked — that still styles its children: a way to give one part of a screen a font or a colour without drawing a box.

A number that is no number#

A length, a time or a scale that is not a finite number in its range — a NaN from a division by zero, a radius of minus four — is drawn the way no style would draw it, and said once: UI: a Style's … of … is not from … to …; … is used. A negative length is 0 without a word: a border of -4 is no border.

Pictures#

Everything in the interface that shows an image — image(), an icon on a button, a skin behind a button or a panel, the fill of a bar — takes an rmp::ui::Picture, and a picture is made from whatever you have, without naming it:

FromIs
an rmp::TextureThe whole texture.
{ texture, Rectangle{ … } }A part of it: an atlas, a sheet laid out by hand.
an rmp::SpriteWhat the sprite shows now: its texture, or its sheet's current frame. A snapshot: make one each frame to see it move, or keep an Image, which plays it.
a NineSliceA picture that stretches by its middle. See below.
slice(sheet, name)A slice of an Aseprite file, by its name.
rmp::ui::image(logo);
rmp::ui::image({ atlas, Rectangle{ 32, 0, 16, 16 } });
rmp::ui::image(hero);

A picture holds counted handles to what it shows, so the texture stays loaded for as long as a picture that shows it exists — through the end of the frame that draws it — and a temporary is safe. empty() is true when there is nothing to draw: no texture, or one that did not load; an empty picture draws nothing and takes no room. size() is its size in pixels of the source, and sliced() is true when it has nine-slice margins. Its fields are public — texture, sheet, source, the margins left, top, right, bottom and slice_scale — but one of the constructors normally sets them.

Nine-slices#

A NineSlice is the classic "9-patch": four margins cut the picture into a three-by-three grid, and it is drawn stretched to any box with its corners at their own size, its edges stretched along one axis and its middle along both. One small frame becomes a button of any length:

const rmp::ui::NineSlice frame{ .texture = ui_art,
                                .source = { 0, 0, 24, 24 },
                                .left = 8,
                                .top = 8,
                                .right = 8,
                                .bottom = 8,
                                .scale = 3 };
rmp::ui::Button play{ .text = "Play", .style = { .skin = rmp::ui::Skin{ .normal = frame } } };
FieldDefaultIs
textureemptyThe picture.
sheetemptyOr an Aseprite sheet's texture, when texture is empty.
sourceall of itThe part of the texture to cut, in pixels.
left, top, right, bottom0The margins, in pixels of the source.
scale0, which is 1How big one source pixel is drawn, in design units, so the corners grow with the interface's scale like everything else. Pixel art wants a whole number.

A box smaller than its corners shrinks the corners together rather than letting them overlap. All four margins 0 is a picture that simply stretches.

Slices of an Aseprite file#

An artist marks the parts of an .aseprite with the slice tool and names them: an icon of an atlas, the frame of a button. slice(sheet, name) is the part of the first frame the slice covers, as a picture, and one with "9-Slices" ticked in Aseprite comes with its margins, so it is already a nine-slice. nine_slice(sheet, name) is the same slice as a NineSlice, to change its scale or keep it:

static const rmp::SpriteSheet icons = rmp::assets::load_sheet("skin.aseprite");
rmp::ui::image(rmp::ui::slice(icons, "coin"));
rmp::ui::NineSlice frame = rmp::ui::nine_slice(icons, "button");
frame.scale = 3;

A name the sheet does not have is an empty picture, and said once: UI: rmp::ui::…(sheet, "…"): the sheet has no slice by that name. A slice without 9-slices asked for as one stretches whole, and says UI: rmp::ui::nine_slice(sheet, "…"): the slice has no 9-slices; it stretches whole. The slices themselves are in the sheet's SheetData::slices; sprites says what is read from the file.

An image you can press#

rmp::ui::image_button is a button that is a picture: an icon, an inventory slot, a "Play" drawn by the artist. It is pressed and focused like button(), and wears theme.styles.button — its skin behind the picture, its sounds:

if (rmp::ui::image_button(gear)) open_settings();
if (rmp::ui::image_button(gear, { .width = 64, .height = 64, .id = "settings" })) open_settings();

ImageButtonOptions: width and height in design units, 0 for the picture's own size; enabled; and id, since a picture has no label to be told apart by — without one, unnamed image buttons are told apart by their order. It has no padding around it and no minimum height, except on Android and iOS, where it is still as tall as a thumb needs.

Skins#

A Skin is pictures instead of a flat fill, one per state. Only normal is needed: a state without its own picture shows normal, changed the way the colours of that state would be — lit under the pointer, darker while held, grey and faded when disabled. Give the others when the artist drew them:

const rmp::ui::Style wooden{ .skin = rmp::ui::Skin{ .normal = up, .press = down } };
FieldShownWhen it is missing
normalat restno skin at all: the theme's fill
hoverunder the pointernormal, drawn a second time on top, faintly, to light it
pressheld downnormal, darker
disabledenabled = falsenormal, grey and a little transparent
focuswith the keyboard or gamepad focusnormal; the focus ring is drawn either way

The picture is the box: a skinned button has no flat fill over it or under it, and its style's tint multiplies it. On an image, the skin is a frame behind the picture, as far in as the style's padding.

Shadows and outlines#

A Shadow under a box is drawn as a few rounded rectangles, each fainter than the last, outwards. That reads as blurred on every target — the software renderer and OpenGL ES 2.0 included — and costs a handful of rectangles:

const rmp::ui::Style card{ .shadow = rmp::ui::Shadow{ .offset = { 0, 6 }, .blur = 12 } };
FieldDefaultIs
offset{ 0, 4 }Where it falls, in design units: down a little, as light from above.
blur8How far it fades out past the box; 0 is one hard shadow.
spread0How much bigger than the box it is before it fades.
colorblack at 90 of 255Its colour at the box.

Text has two of its own. A TextOutline draws copies of the text around it, so a title reads over any background — width in design units (1 by default; keep it from 1 to 3, every copy is drawn), color black. A TextShadow is one copy under it — offset { 1, 2 } design units, color black at 160 of 255. A box's own outline is border and border_width.

rmp::ui::Label title{ .text = "Game over",
                      .size = rmp::ui::Size::LARGE,
                      .style = { .text = GOLD,
                                 .text_outline = rmp::ui::TextOutline{ .width = 2 },
                                 .text_shadow = rmp::ui::TextShadow{} } };

Motion#

A Motion is movement. The framework's themes have a little of it, in their styles: buttons grow under the pointer and give when pressed, and panels fade and rise in. Anything more is a choice of style, and a game that wants it says so. Nothing here moves the layout. A control is drawn bigger, lifted or sliding, with everything inside it, but it is laid out — and clicked — where it always was.

rmp::ui::Theme theme = rmp::ui::current_theme();
theme.styles.button.motion = rmp::ui::Motion{ .hover_scale = 1.05f, .press_scale = 0.95f };
theme.styles.panel.motion = rmp::ui::Motion{ .appear = 0.25f, .appear_offset = 24 };
rmp::ui::set_theme(theme);
FieldDefaultIs
hover_scale1How big under the pointer: 1.05 is 5 % bigger.
press_scale1How big while held: 0.95 is 5 % smaller.
hover_lift0How far it rises under the pointer, in design units, its shadow falling further below it: a card lifting off the table.
speed0.12Seconds hover and press take to get there.
appear0Seconds a box takes to fade in the first frame it is drawn; 0, it is simply there. Panels and overlays are what it is for.
appear_offset0How far below it starts as it appears, in design units, sliding up.
appear_scale1How big it starts as it appears, growing to 1.
shake0.4Seconds a shake() lasts.
shake_strength8How far side to side it shakes, in design units, dying away.

A shake is a kept widget's shake() — "that did not work": a wrong password, a coin you do not have. It needs no Motion to be set: the defaults above shake. Hover and press follow the same clock as the scenes, so a script that plays the game sees the same frames every run.

Sounds#

A Sounds names a sound for each thing a control does, by the name rmp::audio::play() takes — "click" is click.wav, click.ogg… in resources/. In the theme, every control makes them; in a style, one widget does, or everything inside a panel:

rmp::ui::Theme theme = rmp::ui::current_theme();
theme.sounds.hover = "hover";
theme.sounds.click = "click";
theme.sounds.volume = 0.6f;
rmp::ui::set_theme(theme);
rmp::ui::Button quiet{ .text = "Back", .style = { .sounds = { .hover = "" } } };
FieldPlays when
hoverthe pointer arrives on a control
pressthe pointer goes down on it
release…and comes up
clickit is pressed: the pointer, Enter, the gamepad's A button
focusthe keyboard or gamepad focus arrives
changea checkbox, slider, dropdown or text field changes its value
opena dropdown opens its list
close…and closes it
shakea widget's shake() starts
volumenot a sound: 0 to 1, for all of them; 1 when nothing sets it

Each one is inherited on its own, like every field of a style, so an empty name is silence: .hover = "" turns off a hover sound the theme or a panel set. Unset is "whatever is around it"; empty is "nothing".

A name is a SoundName, written as a string — a literal, a std::string or a std::string_view, copied — with view() to read it, empty() for silence and == to compare it with a string. It is a type of its own for one reason: writing one is what brings rmp::audio's player and its decoders into the game. A game whose interface names no sound links none of them.

Every sound goes through rmp::audio, so it follows the mixer's sound-effect volume and master volume, and a sound that is missing says so once, as any play() does. Anything else that should happen on an event — a vibration, a particle — is on_event().

Fonts#

The interface draws its text in one global font unless a style gives another. The global font starts as [ui] font, at sizes measured from [ui] font_size; that is only where the game starts, and it can change at any time.

Text is drawn at the pixel size the layout asks for: its size in design units — a step or a number — times the scale.

Left empty, the default, the font is raylib's built-in one: no file, no licence, and it works on every platform. It is a bitmap 10 pixels tall, stretched to whatever size the text asks for.

A font of your own is a file in resources/, named relative to it:

[ui]
font = "ui.ttf"
font_size = 24

font_size is the medium step in design units, a whole number from 6 to 200; the small and large steps start at 0.8 and 1.4 times it.

Changing it while the game runs#

set_font() changes the global font: by its name in resources/, or from a font the game loaded — the interface takes that font's file and bakes it itself. "", an empty font or one that failed to load is raylib's built-in one. font_name() says which it is now. A language with other letters, an accessibility setting for a plainer face:

rmp::ui::set_font(dyslexia_friendly ? "plain.ttf" : "ui.ttf");

A font for one widget#

Style::font gives one widget, or everything in a panel, a font of its own: one the game loaded with rmp::assets::load_font. The size it was loaded at does not matter. The interface draws with that font's file, baked by itself at every size it draws, so a title at 48 and a caption at 14 in the same font are both sharp:

static const rmp::Font title = rmp::assets::load_font("title.ttf", 32);
rmp::ui::Label heading{ .text = "Chapter one",
                        .size = rmp::ui::Size::LARGE,
                        .style = { .font = title } };

Every letter, on demand#

A font file is a set of outlines, and drawing it means baking the letters it needs into a texture first. The interface bakes a letter the first time a text uses it — Spanish, Polish, Russian, Japanese, whatever the file has — and then bakes the face again with it, before the frame is drawn. Latin-1 and Latin Extended-A are there from the start. A game that draws more than 8192 different letters with one font draws the ones past that as ?, and says so once: UI: more than … different letters drawn with a [ui] font; the ones past that are drawn as '?'.

It is loaded through rmp::assets, so it works the same loose in resources/ and packed in a release. A font file is only sharp at the size it was rasterised at, so the interface rasterises it once for every pixel size it draws — SMALL, MEDIUM, LARGE and every number, each times the scale, for every font in use — and keeps each of those faces until the interface shuts down. Text is then drawn from a face made at exactly its size, so it stays sharp at any scale. Sixteen faces are kept at once; one more makes room by letting go of the face used longest ago, never of one drawn in the same frame, whose glyphs may still be waiting to be drawn. A frame that draws more than sixteen sizes draws the extra ones from the nearest face of the same font, stretched.

A font file that is missing or cannot be read does not switch the interface off: it falls back to the built-in font and says so once, UI: font '…' could not be loaded; using the built-in font.