# GUI — Menu and Screen Layouts (`.gui`)
## Overview
**Established** `[02 §6 "Interface panel files"]`, `[07 R-WGT-01]`.
Ordinary `.gui` files in the `guis/` directory define menu and in-game panels:
the main menu, battle rooms, dialogs, and the side command bars used during
play. A normal GUI file is a text file in the general TDF syntax
([tdf.md](tdf.md)) describing a list of **gadgets** — buttons, listboxes,
text fields, scrollbars, labels, dynamic picture surfaces, fonts, and
picture boxes.
Graphics come from a GAF file with the same base name as the GUI
(`MAINMENU.GUI` ↔ `anims/MAINMENU.GAF`) plus the shared
`anims/commongui.GAF`; fonts come from `fonts/*.fnt`. Behavior is largely
hard-coded: a gadget's `name` is matched against engine-known event names
per menu (e.g. `SINGLE`, `MULTI`, `EXIT` in the main menu). Generic widget
behavior (selection, scrolling, linked labels and radio groups)
still applies without a screen-specific event binding `[07 R-WGT-01 §§3–7]`.
**Established — implementation policy.** The installed corpus includes a
binary `ENDGAME.GUI` and truncated text `SCORE.GUI`. `formats.LoadGUI`
extracts fallback labels from the recognized binary signature and repairs one
missing final brace when an unterminated text section ends in a semicolon.
These are Nanolathe recoveries, tested in `formats/source_test.go`; they do
not establish that retail accepts either file through its ordinary panel
loader. That reader uses the fatal TDF syntax path `[02 R-MALF-01 §5]`.
## Format at a glance
```
[GADGET0] ← first gadget = the interface itself (id=0)
{
[COMMON] ← fields every gadget has
{ id=0; name=Mainmenu.GUI; xpos=0; ypos=0; width=640; height=480; ... }
totalgadgets=6; ← gadget-specific fields follow COMMON
[VERSION]
{ major=-51; minor=-51; revision=-51; }
panel=; crdefault=; escdefault=; defaultfocus=SINGLE;
}
[GADGET1] ← subsequent gadgets = the interface's elements
{
[COMMON]
{ id=1; name=SINGLE; xpos=139; ypos=393; width=96; height=20; ... }
status=0; text=SINGLE; quickkey=83; grayedout=0; stages=0;
}
```
(Abbreviated illustration based on `guis/MAINMENU.GUI`; ellipses and
annotations are explanatory, not literal file contents.)
The numeric suffix in `[GADGETn]` is cosmetic — the engine accepts `[]` or
any bracketed name; order in the file is what matters. The first gadget
describes the whole interface (position, size, background); each later
gadget is one element of it.
## Reference
### `[COMMON]` fields (all gadget types)
| Field | Type | Meaning |
| --- | --- | --- |
| `id` | int | Gadget type — dispatches everything else. Known: 0 header, 1 button, 2 listbox, 3 textbox, 4 scrollbar, 5 label, 6 blank surface, 7 font, 12 picture box. **Stored as one byte** (the low eight bits of the integer), so the engine dispatches on `id mod 256`. The executable also knows `8` (raw file, below), `10` (line, below), `11` (built exactly like a header/panel) and `13` (the end-of-mission score bar, created by the engine, never authored); `9` and everything above 13 read only `[COMMON]` and get no build work. Full per-kind key table: [07 R-WGT-01 §11]; builder dispatch: [07 R-WGT-01 §12]. |
| `assoc` | int | Association key linking gadgets, and most gadget kinds do use it. A listbox and scrollbar sharing `assoc` are wired together (listbox drives knob size, scrollbar scrolls list); buttons with the radio attribute use it as their group; a slider's synthesised arrow buttons carry it; a listbox copies its selection to same-`assoc` listboxes and (attribute 8) to a same-`assoc` textbox. See the executable spec [07 R-WGT-01 §3, §5]. |
| `name` | string | Dual purpose: (a) graphic lookup — the name of a GAF entry in `