Files
slate32/test/statusbar_dirty.lua
T
evan b2f58118e1 revert(gui): return text rendering to built-in Font 1
Remove OpenFontRender, embedded Meslo assets, custom-font APIs, and their runtime allocation overhead. Keep the taller status layout and compact card grid, with used RAM, aligned faded WiFi bars, and tighter telemetry rows.
2026-08-02 15:26:40 -04:00

75 lines
2.7 KiB
Lua

-- Run: lua test/statusbar_dirty.lua
-- Asserts the bar repaints only what changed, and that it notices the two things it can
-- only learn by looking: rotation and theme. The clock is pinned unsynced so its text is
-- constant and every other field can be steered on its own.
package.path = "sdcard/lib/?.lua;test/?.lua;" .. package.path
local device = require("fake_device").install()
local ui = require("ui")
local statusbar = require("statusbar")
device.clockSynced = false
-- Returns the labels drawn by one draw() call.
local function paint()
device.painted = {}
statusbar.draw(true)
local labels = {}
for _, entry in ipairs(device.painted) do labels[#labels + 1] = entry.label end
return labels
end
local function has(labels, want)
for _, label in ipairs(labels) do if label == want then return true end end
return false
end
local first = paint()
assert(has(first, device.appName), "first draw paints the app name")
assert(has(first, "--:--:--"), "first draw paints the clock")
assert(has(first, "117kB"), "first draw paints used memory")
assert(#paint() == 0, "an unchanged bar paints nothing")
device.freeHeap = device.freeHeap - 32000
local memOnly = paint()
assert(#memOnly == 1 and memOnly[1] == "148kB", "only the memory slot repaints")
device.status = {state = "connected", ssid = "x", ip = "", rssi = -50}
assert(#paint() == 0, "signal bars are not text, so nothing is drawn")
device.status = {state = "disconnected", ssid = "", ip = "", rssi = 0}
-- Rotation and theme invalidate everything, because every slot moves or recolors.
device.rotation = 180
assert(has(paint(), device.appName), "rotation repaints the whole bar")
assert(#paint() == 0, "and settles again afterwards")
device.theme = "dark"
ui.reloadTheme()
assert(has(paint(), device.appName), "a theme change repaints the whole bar")
-- An app renaming itself is a bar change like any other, with no invalidation call.
sys.setAppName("settings - wifi")
assert(has(paint(), "settings - wifi"), "a renamed app repaints the whole bar")
assert(#paint() == 0, "and settles again afterwards")
-- A name wide enough to reach the memory slot is clipped, not drawn over it.
sys.setAppName(string.rep("w", 60))
local clipped
for _, label in ipairs(paint()) do
if label:sub(1, 1) == "w" then clipped = label end
end
assert(clipped and #clipped < 60, "an over-long name is clipped, got " .. #(clipped or ""))
sys.setAppName("test")
-- Leaving fullscreen is the one change draw() cannot see: the app painted over the bar
-- while nothing about the bar's own state moved.
device.theme = "light"
ui.reloadTheme()
paint()
statusbar.setFullscreen(true)
statusbar.setFullscreen(false)
assert(has(paint(), device.appName), "leaving fullscreen repaints the whole bar")
print("ok")