When displaying a value that changes over time — a sensor reading, counter, or clock — the new text may be shorter than what was previously drawn. Without clearing the old text first, stale pixels remain visible.Documentation 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.
setTextPadding() solves this by forcing drawString() (and related functions) to blank a fixed-width area before drawing the new text, replacing the old value cleanly in a single pass with no flicker.
Text padding only takes effect when a background color is set via
setTextColor(fg, bg). When called with a single color argument (setTextColor(fg)), no background fill is applied and padding is ignored.How setTextPadding Works
setTextPadding(uint16_t x_width) sets a minimum pixel width for the text drawing area. When drawString() renders text:
- It calculates the actual pixel width of the string.
- If that width is less than
x_width, the remaining area is filled with the background color. - The text is drawn over the filled region.
"9" written after "100" will still erase the full width of "100".
Basic Example
Practical Use: Updating a Counter Without Flicker
Without padding, counting down from"100" to "9" leaves "00" residue on screen. With padding sized to the widest expected string, each update is clean:
Live Sensor Display
API Reference
| Function | Signature | Description |
|---|---|---|
setTextPadding | void setTextPadding(uint16_t x_width) | Set minimum draw width in pixels |
getTextPadding | uint16_t getTextPadding() | Read current padding value |
setTextPadding(0). It does not reset automatically between calls.
Related
- Text Methods API —
setTextColor,drawString,textWidth,drawFloat,drawNumber - Text Datum Example — aligning text with datum constants
- Fonts & Datums — font numbers and datum reference