lcd.drawText¶
since 1.1.0
Draw a text.
Parameters¶
| Name | Type | Required | Description |
|---|---|---|---|
x |
number | yes | X coordinate |
y |
number | yes | Y coordinate |
text |
string | yes | displayed text |
flags |
integer | optional | flags (LEFT / RIGHT / CENTERED) |
Returns¶
Nothing.
Examples¶
local function paint(widget)
local w, h = lcd.getWindowSize()
lcd.font(FONT_L)
lcd.color(lcd.themeColor(THEME_DEFAULT_COLOR))
lcd.drawText(4, 4, "Left") -- default: x is the left edge
lcd.drawText(w / 2, 4, "Centre", CENTERED) -- x is the centre
lcd.drawText(w - 4, 4, "Right", RIGHT) -- x is the right edge
-- vertically centre a line of text
local _, th = lcd.getTextSize("Ag")
lcd.drawText(w / 2, (h - th) / 2, widget.text, CENTERED)
end
yis the top of the text, not the baseline.- Use
lcd.drawNumberfor values with units: it formats decimals and the unit for you. - Only works inside
paint.
Used in¶
- Battery gauge widget
- Timer control
- Telemetry value widget
- lazy-loading
- widget-flvss
- widget-gauge
- widget-jet
- widget-lcddemo
- widget-rssi
- xxxxl
Real-world usage¶
Called 409 times across 13 open-source Ethos Lua projects. A few short excerpts: