Files
slate32/sdcard/.lua/apps/Hello/main.lua
T
evan 7bc9afae33 refactor(lua)!: migrate to the per-feature namespaces
Follows lib/esp32-lua-api: gui -> screen, node -> tree, settings and input
split into screen/sys/touch/buttons. Settings is one provider lighter, with
timezone on Sys and rotation and theme on Gui, which now applies and persists a
rotation in one call. The calibration screen stashes the rotation it borrows
rather than relying on a transient setter.
2026-08-05 10:26:43 -04:00

48 lines
1.1 KiB
Lua

local ui = require "ui"
local FONT = screen.FONT_UI
local M = {}
local seconds = 0
local uptime
local function text()
return "uptime: " .. seconds .. "s"
end
function M.init()
timer.every(1000, function()
seconds = seconds + 1
ui.setText(uptime, text())
end)
log.info("hello app started, screen " .. screen.getWidth() .. "x" .. screen.getHeight())
end
function M.node()
-- A fixed slot for the clock, because a node keeps the box it was measured with and the
-- text grows a digit at a time.
uptime = ui.text(text(), {
w = screen.getTextWidth(FONT, "uptime: 00000s"),
h = screen.getFontHeight(FONT),
font = FONT,
})
return ui.box {
w = "fill",
h = "fill",
pad = 10,
gap = 20,
ui.text("hello from sd card", { font = FONT }),
ui.text("touch the screen", { font = FONT, color = ui.theme.muted }),
uptime,
}
end
-- Painted straight to the panel rather than as nodes: the dots are a scribble, and the
-- tree would need one node each to remember them.
function M.on_touch(x, y)
log.info("touch at " .. x .. ", " .. y)
screen.fillCircle(x, y, 6, ui.theme.accent)
end
return M