Skip to content
Axiom/SDK
SDK / The overlay and config

The overlay and config

A mod shows things to the person through the overlay, Axiom's own window over the game, and takes settings through a schema the host draws. A mod never draws pixels and never draws its own settings: it describes panels, and the host renders them in the overlay's own style, so twelve mods look like one application and no mod can draw a convincing copy of Axiom's prompts.

Where the overlay runs today

ui.overlay@1 and config@1 are served by the Axiom Sandbox, whose overlay window is macOS only. F8 opens and closes it and Escape closes it. Closed, only the mods' panels show, in the top right, and clicks pass through to whatever is under them.

A panel

axiom_ui_overlay_panel(title, length, &panel) opens a panel, which gets its own tab in the overlay. Everything else is added to a panel by its handle.

TRAFFIC.Ca panel with a table and controls
#include "surface.h"

#define LEN(s) (sizeof(s) - 1)
#define SPAN(s) \
  ((AxiomSpan){.Offset = (uint32_t)(uintptr_t)(s), .Length = (uint32_t)LEN(s)})

__attribute__((export_name("on_frame"))) void OnFrame(void) {
  AxiomUiOverlayPanelId panel;
  if (axiom_ui_overlay_panel("Traffic", LEN("Traffic"), &panel) != 0) {
    return;
  }

  axiom_ui_overlay_note(panel.index, panel.generation,
                        "Counts refresh every frame.",
                        LEN("Counts refresh every frame."));

  /* A table: the headers once, then the cells row after row. */
  AxiomSpan columns[2] = {SPAN("Kind"), SPAN("Count")};
  AxiomUiOverlayNodeId table;
  if (axiom_ui_overlay_table(panel.index, panel.generation, columns, 2,
                             &table) == 0) {
    AxiomSpan cells[4] = {SPAN("Cars"), SPAN("412"), SPAN("Buses"),
                          SPAN("3")};
    axiom_ui_overlay_set(table.index, table.generation, cells, 4, 2);
  }

  /* Controls name a config key from axiom.toml; the host keeps the value. */
  axiom_ui_overlay_slider(panel.index, panel.generation, "Speed",
                          LEN("Speed"), "speed", LEN("speed"));
  axiom_ui_overlay_toggle(panel.index, panel.generation, "Show grid",
                          LEN("Show grid"), "grid", LEN("grid"));
  axiom_ui_overlay_button(panel.index, panel.generation, "Reset",
                          LEN("Reset"), "reset", LEN("reset"));
}

Describe the panel every frame. The Sandbox draws what a mod described in a frame and clears it for the next, and a panel's handle names nothing after its frame, so a mod that opens a panel once and keeps the handle draws once. Opening the same panel every frame is cheap: what crosses is the description, and the host builds the screen from it.

The host labels each panel's tab with the mod's name and frames it with "Drawn by" the mod's name and id, whatever the mod titles it. Nothing a mod draws can take focus or a key, so a mod cannot put one of Axiom's controls on screen.

What goes in a panel

Call
Draws
text(panel, line)
A line of text, already formatted.
note(panel, text)
Quiet explanatory text, such as why something is unavailable.
list(panel, &node), then set(node, cells, count, 1)
A list of lines, replaced whole each time it is set.
table(panel, columns, count, &node), then set(node, cells, count, columns)
A table: headers, then cells row after row, flat, with columns saying how many make a row.
graph(panel, label, value, window)
A rolling series. Push one value a frame; the host keeps the last window values.
slider(panel, label, key)
A slider for a number setting.
toggle(panel, label, key)
A switch for a toggle setting.
select(panel, label, key)
A picker for a choice setting.
button(panel, label, id)
A button. A press arrives as a pressed event carrying id.

Strings cross as a pointer and a length. A list of strings, such as a table's columns and cells, is an array of AxiomSpan, each an offset into the mod's memory and a length; the SPAN macro above builds one from a literal.

There is no C library, so a mod formats its own numbers. This is the helper the overlay test mod uses:

NUMBERfrom overlaytest.c
/* Writes a number in decimal after a prefix, with no C library to do it.
 * Returns the length. */
static uint32_t Number(char* out, const char* prefix, uint32_t prefixLength,
                       uint64_t value) {
  uint32_t at = 0;
  for (; at < prefixLength; ++at) {
    out[at] = prefix[at];
  }

  char digits[20];
  uint32_t count = 0;
  do {
    digits[count++] = (char)('0' + (value % 10));
    value /= 10;
  } while (value != 0 && count < sizeof(digits));

  while (count > 0) {
    out[at++] = digits[--count];
  }
  return at;
}

How much a frame holds

The overlay draws a bounded amount, so a mod that writes a line every frame cannot grow it without end. A call past a limit returns 2 and draws nothing.

Limit
Value
Panels in a frame
16
Marks in one panel
256
A panel title
256 bytes
One line, note or cell
4,096 bytes
All text in a frame
256 KiB
Columns in a table
32
Cells in one set
1,024

A status of 1 means the panel or node handle names nothing in this frame. Invalid UTF-8, or a span outside the mod's memory, is a fault rather than a status.

Settings

A mod's settings are declared in its manifest and drawn by the host, in a settings panel of the overlay:

AXIOM.TOMLmods/overlay-test
[[config]]
key = "speed"
label = "Speed"
kind = "number"
min = 0
max = 10
step = 1

[[config]]
key = "grid"
label = "Show grid"
kind = "toggle"

[[config]]
key = "theme"
label = "Theme"
kind = "choice"
options = ["dark", "light"]

What the person sets is saved on the spot, in the Sandbox to settings/axiom.sandbox/default.json in Axiom's data directory, and is there again the next run. Every kind and limit is on the manifest page.

Reading settings

A mod that declares config@1 reads its own values, by key, through the schema. Values come back clamped to the range the schema gave them, so a mod never has to defend against its own settings file. It cannot read another mod's.

CONFIGeach kind of read
float speed = 1.0f;
(void)axiom_config_number("speed", LEN("speed"), &speed);

int32_t grid = 0;
(void)axiom_config_flag("grid", LEN("grid"), &grid);

char theme[16];
uint32_t themeLength = 0;
if (axiom_config_text("theme", LEN("theme"), theme, sizeof(theme),
                      &themeLength) != 0 ||
    themeLength > sizeof(theme)) {
  /* Unknown key, wrong kind, or cut short: themeLength is the whole length. */
  themeLength = 0;
}
Call
Reads
Kinds
axiom_config_number(key, length, &out)
A float
number
axiom_config_flag(key, length, &out)
0 or 1
toggle
axiom_config_text(key, length, out, room, &used)
Text, as much as fits in room; used is the whole length
choice, colour, key

Read settings every frame rather than once at start, so a change shows on the next frame, or wait for the config@1 changed event (Events). A key the manifest does not declare is status 1, and the wrong call for a key's kind is 2.

Controls

A slider, toggle or select names a config key, not a value. The host draws the control with the setting's current value, stores what the person picks, and validates it against the schema, so a mod's controls and its settings panel are always the same value. A button names an id of the mod's choosing, and its press arrives through on_event after the mod's next frame.

Not built yet

  • The overlay window on Windows and Linux, and over every screen rather than the main one.
  • A graph drawn as a line. It shows its latest value today.
  • The overlay over a game on the Unity backend. It is planned as Axiom's own window over the game's.
  • input.observe@1, for reading keys and binding a hotkey.