Files
slate32/sdcard/.lua/apps/Hello/main.lua
T
evan 97abf037b8 refactor(lua)!: camelCase handlers, and type the app tables
Follows the submodule: on_touch_down and friends become onTouchDown, the last
snake_case left in the surface now that handlers are table fields rather than
globals.

main.lua declares SlateApp, this card's contract with its apps, and every app
composes what it fills -- PaintApp is SlateApp plus TouchHandlers, Home is
SlateApp alone -- which is also the only static record of the features an app
needs.
2026-08-05 10:42:06 -04:00

49 lines
1.2 KiB
Lua

local ui = require "ui"
local FONT = screen.FONT_UI
---@class HelloApp : SlateApp, TouchHandlers
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.onTouch(x, y)
log.info("touch at " .. x .. ", " .. y)
screen.fillCircle(x, y, 6, ui.theme.accent)
end
return M