Files
slate32/sdcard/apps/home/main.lua
T
evan b9b620ad2b feat(ui): add a home button to the status bar, rename launcher to home
Leaving an app was the app's own responsibility, so one that shipped without
an exit could only be escaped with a reset. The bar now paints a back button
into its leading square and the firmware treats that rect as home, acting on
release so a press sliding into the app cancels. The app it returns to is
/apps/home, which is what it is to the user.

Card grids in home and settings centre left to right as a unit.
2026-08-01 23:13:20 -04:00

55 lines
1.6 KiB
Lua

local ui = require("ui")
local PAD, GAP = 12, 8
local CARD_SIZE = 2 -- text scale inside a card; the name is the whole card
local screen
local function card(name, side)
return ui.button{
w = side, h = side,
justify = "center",
on_press = function() sys.launch("/apps/" .. name .. "/main.lua") end,
ui.label(name, {size = CARD_SIZE, fit = side - 16}),
}
end
function init()
local names = {}
for _, name in ipairs(fs.listDirs("/apps")) do
if name ~= "home" then names[#names + 1] = name end
end
table.sort(names)
local side, cols = ui.cardSide(math.max(#names, 1), PAD, GAP)
-- Rows are filled before ui.box() sees them: the constructor moves a spec's array part
-- into its children, so anything appended afterwards is never laid out.
local rows = {}
for _, name in ipairs(names) do
local row = rows[#rows]
if not row or #row >= cols then
row = {}
rows[#rows + 1] = row
end
row[#row + 1] = card(name, side)
end
-- Centred left to right as a unit, still top aligned: the gaps inside the grid are
-- fixed, so the leftover width belongs beside the block, not to its last column.
local items = {pad = PAD, gap = GAP, w = "fill", align = "center"}
for _, row in ipairs(rows) do
row.row, row.gap = true, GAP
row.w = #row * side + (#row - 1) * GAP
items[#items + 1] = ui.box(row)
end
if #rows == 0 then items[#items + 1] = ui.text("no apps in /apps", {color = ui.theme.muted}) end
screen = ui.screen(ui.box(items))
log.info("home ready")
end
function draw() screen:draw() end
function on_touch_down(x, y) screen:down(x, y) end
function on_touch_up(x, y) screen:up(x, y) end