Files
slate32/test/settings_busy.lua
T
evan 118e04e340 fix(settings): paint the scan and keyboard notices before the work that blocks
on_tick runs before draw in the same pass, so a screen built for a blocking call was
never painted until the call returned -- on a panel ui.screen() had already cleared.
Scanning looked like a hang on a blank screen. The notice is now painted by the tap
itself and centered on both axes.
2026-08-02 11:20:48 -04:00

50 lines
1.7 KiB
Lua

-- Run: lua test/settings_busy.lua
-- The scan and keyboard screens announce themselves before work that blocks the loop for
-- seconds. on_tick runs before draw in the same pass, so anything left for draw() to paint
-- appears only after the blocking call returns -- on a panel ui.screen() has already
-- cleared. These assert the announcement is painted by the tap itself.
package.path = "sdcard/lib/?.lua;test/?.lua;" .. package.path
local device = require("fake_device").install()
dofile("sdcard/apps/settings/main.lua")
local function tapRow(prefix)
device.painted = {}
draw()
for _, item in ipairs(device.painted) do
if item.label:sub(1, #prefix) == prefix then
device.painted = {}
on_touch_down(item.x + 2, item.y + 2)
on_touch_up(item.x + 2, item.y + 2)
return
end
end
error("no row labelled '" .. prefix .. "'")
end
local function paintedLabel(prefix)
for _, item in ipairs(device.painted) do
if item.label:sub(1, #prefix) == prefix then return item end
end
return nil
end
init()
tapRow("wifi")
tapRow("scan networks")
-- Painted by the tap, with no draw() in between.
local busy = paintedLabel("scanning")
assert(busy, "the scan screen paints its notice before scanning")
local width = #busy.label * device.charWidth
local centerX = busy.x + width / 2
local centerY = busy.y + device.fontHeight / 2
local panelW, panelH = gui.getWidth(), gui.getHeight()
assert(math.abs(centerX - panelW / 2) <= 1, "centered horizontally, got x " .. busy.x)
-- The bar is above the app's frame, so the app's own height is what it centers in.
assert(math.abs(centerY - panelH / 2) <= 1, "centered vertically, got y " .. busy.y)
print("ok")