Files
slate32/test/toast.lua
T
evan d9bcc47772 feat(ui): show toasts above the app
main.lua mounts toast.node() over the app and ticks it from draw(), so any
app can call ui.toast.show() without wiring an animation of its own.
2026-08-06 21:32:08 -04:00

48 lines
1.3 KiB
Lua

-- Run: lua test/toast.lua
-- The toast's phase machine: it slides in, holds, slides out and drops its node. The pixels
-- are the tree's, so what is asserted here is the offset over time and the node's lifetime.
package.path = "sdcard/.lua/lib/?.lua;lib/esp32-lua-api/lua/lib/?.lua;test/?.lua;" .. package.path
local device = require("fake_device").install()
local ui = require "ui"
local toast = require "ui.toast"
local scrolled
tree.setScroll = function(_, _, y)
scrolled = y
end
ui.mount(function()
return ui.box { w = "fill", h = "fill", toast.node() }
end)
-- Nothing to advance until something is shown.
toast.draw(16)
assert(scrolled == nil)
toast.show("saved", 1000)
assert(device.labelled "saved", "the card is in the tree")
toast.draw(90)
local halfway = scrolled
assert(halfway > 0 and halfway < 44, "slides part way up: " .. tostring(halfway))
toast.draw(90)
assert(scrolled == 44, "fully up before the hold")
toast.draw(1000)
assert(scrolled == 44, "holds")
toast.draw(90)
assert(scrolled > 0 and scrolled < 44, "slides back down: " .. tostring(scrolled))
toast.draw(90)
assert(not device.labelled "saved", "the card leaves the tree")
-- A second toast reuses the machine rather than stacking.
toast.show "again"
toast.draw(180)
assert(scrolled == 44 and device.labelled "again")
print "ok"