Files
esp32-lua-api/lua/test/hints.lua
T
2026-08-03 17:46:14 -04:00

37 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")