Skip to content

lcd.themeColor

since 1.1.0

Get / Set the theme color.

local color = lcd.themeColor(index[, color])

Parameters

Name Type Required Description
index integer yes theme color index
color integer optional color value

Returns

color (integer)

Examples

local function paint(widget)
  local w, h = lcd.getWindowSize()
  lcd.color(lcd.themeColor(THEME_DEFAULT_BGCOLOR))
  lcd.drawFilledRectangle(0, 0, w, h)
  lcd.color(lcd.themeColor(THEME_DEFAULT_COLOR))
  lcd.drawText(4, 4, widget.label)
  lcd.color(lcd.themeColor(THEME_WARNING_COLOR))
  lcd.drawText(4, 30, "Low battery")
end

Using theme colors keeps a script readable on light and dark themes. All indexes are listed under Theme colors.

Used in

Real-world usage

Called 10 times across 3 open-source Ethos Lua projects. A few short excerpts:
lcd.font(FONT_STD)
lcd.color(lcd.themeColor(THEME_DEFAULT_COLOR))

gps-qrcode/main.lua:179

local function resolveThemeConstant(name)
  if not supportsSystemThemeColors() then return nil end
  local key = _G and _G[name]
  if type(key) ~= "number" then return nil end
  return lcd.themeColor(key)
end

src/rfsuite/widgets/dashboard/context.lua:412

local function resolveToolbarThemeColor(themeColorKey, fallback)
  if type(themeColorKey) == "number" and type(lcd.themeColor) == "function" and ensureEthosVersion().atLeast({26, 1, 0}) then
    return lcd.themeColor(themeColorKey)
  end
  return fallback
end

src/wfsuite/widgets/dashboard.lua:464