Skip to content

lcd.font

since 1.1.0

Get / Set the current font.

local font = lcd.font(font)

Parameters

Name Type Required Description
font integer yes one of the available fonts (FONT_M, FONT_M_BOLD, FONT_M_ITALIC, FONT_XS, FONT_XS_BOLD, FONT_S, FONT_L, FONT_L_BOLD, FONT_XL, FONT_XXL)

Returns

font (integer)

Examples

lcd.font(FONT_XL)
lcd.drawText(0, 0, "Big")
lcd.font(FONT_S)
lcd.drawText(0, 40, "small print")

Pick a font from the widget's height so it scales across screen layouts:

local function fontFor(h)
  if h >= 120 then return FONT_XXL elseif h >= 70 then return FONT_XL
  elseif h >= 40 then return FONT_L else return FONT_S end
end

local function paint(widget)
  local w, h = lcd.getWindowSize()
  lcd.font(fontFor(h))
  -- ...
end

All font constants are under Fonts.

Used in

Real-world usage

Called 323 times across 11 open-source Ethos Lua projects. A few short excerpts: