In TFT_eSPI, a datum is the anchor point thatDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Marcussacapuces91/doc-TFT_eSPI/llms.txt
Use this file to discover all available pages before exploring further.
drawString() and related text functions use to position a string on screen. When you call tft.drawString("Hello", x, y), the coordinates x and y don’t refer to the top-left corner of the text by default — they refer to whatever datum is currently active. TL_DATUM (top-left) is the default, so in the default state x, y is the top-left corner of the first character. Switching to MC_DATUM (middle-centre) makes x, y the geometric centre of the rendered string, which is ideal for centring labels inside buttons or panel headings.
Datum constants
| Constant | Alias | Value | Anchor position |
|---|---|---|---|
TL_DATUM | — | 0 | Top-left corner of the text bounding box (default) |
TC_DATUM | — | 1 | Top-centre |
TR_DATUM | — | 2 | Top-right corner |
ML_DATUM | CL_DATUM | 3 | Middle-left (vertically centred, left-aligned) |
MC_DATUM | CC_DATUM | 4 | Middle-centre (horizontally and vertically centred) |
MR_DATUM | CR_DATUM | 5 | Middle-right |
BL_DATUM | — | 6 | Bottom-left corner |
BC_DATUM | — | 7 | Bottom-centre |
BR_DATUM | — | 8 | Bottom-right corner |
L_BASELINE | — | 9 | Left edge of the character baseline |
C_BASELINE | — | 10 | Centre of the character baseline |
R_BASELINE | — | 11 | Right edge of the character baseline |
ML_DATUM and CL_DATUM are identical integer values (3), as are the MC/CC and MR/CR pairs. They exist purely as readability aliases — choose whichever naming convention reads most naturally in your code.Visual layout of datum positions
The grid below shows where(x, y) maps to on a text bounding box for each of the nine corner/edge datums:
A rests on. Descenders (the tails on g, p, y) extend below the baseline, so the bottom of the bounding box is lower than the baseline for fonts with descenders.
Using datum constants
setTextDatum() — apply a datum globally
drawString(), drawNumber(), and drawFloat() calls until changed again.
Datum in TFT_eSPI_Button::setLabelDatum()
Button labels use MC_DATUM by default. Pass a different datum to setLabelDatum() if you need the label anchored elsewhere: