Files
esp32-lua-api/lua/test/hints.lua
T
evan 291f0f20b5 build: add a format target and one shared editor config
The Lua modules were split between tabs and spaces because nothing pinned a
style; .editorconfig is what lua-language-server reads on save, so the editor
and the tree now agree. clang-format already had a config and left native/
unchanged. Embedded modules regenerate from the reformatted ui.lua.
2026-08-04 13:19:58 -04:00

55 lines
1.4 KiB
Lua

package.path = "./lua/lib/?.lua;" .. package.path
local drawn = {}
local roles = { "confirm", "back", "right" }
gui = {
FONT_SMALL = 0,
STYLE_NORMAL = 0,
color = function(r, g, b)
return r * 65536 + g * 256 + b
end,
getWidth = function()
return 300
end,
getHeight = function()
return 240
end,
getFontHeight = function()
return 8
end,
getTextWidth = function(_, text)
return #text * 6
end,
fillRect = function(x, y, w, h)
drawn.strip = { x, y, w, h }
end,
drawText = function(_, x, _, text)
drawn[#drawn + 1] = { text = text, x = x }
end,
}
input = {
getButtons = function()
return roles
end,
}
local hints = require "hints"
local height = hints.draw { back = "Close", confirm = "Select", up = "Scroll" }
assert(height == 14, "height covers the font plus padding")
assert(drawn.strip[2] == 226, "the strip sits at the bottom by default")
-- "up" is labelled but this device lacks it, so it never reaches the strip.
assert(#drawn == 2, "only labelled roles the device reports are drawn")
assert(drawn[1].text == "Close" and drawn[2].text == "Select", "reading order, not action order")
assert(drawn[1].x == 60 and drawn[2].x == 207, "each label centres in its slot")
drawn = {}
roles = {}
assert(hints.draw { confirm = "Select" } == 14, "a device with no buttons still clears the strip")
assert(#drawn == 0 and drawn.strip, "nothing is labelled, but the strip is cleared")
print "ok"