Your own variables: <variables>
What goes in the file: the tag, the naming rules, the scope.
This page describes what goes in the file. To create them without writing a line of XML, see Your custom variables, in “Dynamic data”.
It is the most useful mechanism of any serious theme, and yet the least known.
<variables>
<variable name="CouleurPrincipale" value="2E447C" />
<variable name="PoliceTitre" value="${root}/data/fonts/Exo2.otf" />
<variable name="Alpha50" value="80" />
</variables>
Then, anywhere in the theme:
<box name="fond">
<color>${CouleurPrincipale}</color>
</box>
<text name="titre">
<fontPath>${PoliceTitre}</fontPath>
<color>${CouleurPrincipale}${Alpha50}</color>
</text>
Change the value in one place, the whole theme follows. That is what makes color options possible: an overlay file redefines the variable, and nothing else.
The rules
nameandvalueare both mandatory; without either, the line is ignored and reported in the log;- an empty
nameis rejected; - a variable can contain another one, including a Recalbox variable:
<variable name="CheminLogo" value="${root}/data/logos/${system.name}.svg" />
- the
<variables>block accepts a condition, and each<variable>too:
<variables if="crt">
<variable name="TailleTitre" value="0.09" />
</variables>
- you can have several
<variables>blocks, in any file; - a variable redefined further down overwrites the previous one — like components.
⚠️ It is not the place in the file that counts
Within a file, Recalbox reads ALL the
<variables>blocks first, wherever they are written — before the includes, before the views.
A block placed at the bottom of the file therefore also applies to the views written above it. The custom remains to put it at the top, so that it can be found, but that is a matter of readability, not of behavior.
What counts is the order of the files: a variable redefined in an included file overrides the one of the file that includes it, and it overrides it even for that file’s own views (they are read afterwards). That is what lets an option choice recolor a whole theme. See Declaring an option.
Where to declare them
In theme.xml: the engine reads a file's variables before processing its includes, so they arrive in time for every included file.
The custom, taken from the official theme, is to give them their own file — variables.xml — included first of all:
<include>${root}/variables.xml</include>