Files
slate32/sdcard/lib/statusbar.lua
T
evan 114c8c5f72 feat(ui): add persistent status bar and card grid launcher
The bar is host-owned chrome: the firmware clips apps into a viewport below
it, so no app can paint over it, while /lib/statusbar.lua owns the height,
repaint interval and painting. gui.fullscreen() lets touch calibration take
the physical panel back.

Launcher and settings become grids of square cards (3 across landscape, 2
portrait) via the new gui.setTextSize, ui.label and ui.cardSide. The one
function on the `app` table moves to sys.setTickInterval, alongside the new
sys.appName the bar needs.
2026-08-01 22:50:19 -04:00

47 lines
1.5 KiB
Lua

-- The top bar, painted by the firmware once a second in every app. It draws in panel
-- coordinates (the firmware drops the app viewport around the call), so gui.width()
-- here is the whole screen.
local ui = require("ui")
local PAD = 6
-- The firmware reads both: `height` is the strip it keeps apps out of, `interval` is how
-- often it calls draw().
local M = {height = 22, interval = 1000}
local BAR_H = M.height
local function clock()
return sys.clockSynced() and os.date("%H:%M") or "--:--"
end
-- Bars rather than glyphs: there is no icon font, and signal strength is a scale.
local function drawSignal(x, y, color, muted)
local status = wifi.status()
local bars = 0
if status.state == "connected" then
bars = status.rssi >= -60 and 3 or status.rssi >= -75 and 2 or 1
end
for i = 1, 3 do
local h = i * 3
gui.fillRect(x + (i - 1) * 4, y + 9 - h, 3, h, i <= bars and color or muted)
end
end
function M.draw()
local theme = ui.theme
gui.setTextSize(1) -- panel state: the app may have left it scaled up
local w = gui.width()
gui.fillRect(0, 0, w, BAR_H, theme.bg)
gui.fillRect(0, BAR_H - 1, w, 1, theme.muted) -- a rule, so the bar reads as chrome
local textY = math.floor((BAR_H - 1 - gui.fontHeight()) / 2)
gui.drawText(sys.appName(), PAD, textY, theme.fg, theme.bg)
local time = clock()
gui.drawText(time, w - PAD - gui.textWidth(time), textY, theme.muted, theme.bg)
drawSignal(w - PAD - gui.textWidth(time) - 8 - 11, textY, theme.fg, theme.muted)
end
return M