Add missing clearAfter to listview

This commit is contained in:
Ben 2024-06-02 01:39:01 +02:00
parent 10fda87de5
commit 5bbd42d461
Signed by: ben
GPG key ID: 0F54A7ED232D3319

View file

@ -1,4 +1,5 @@
local backingList = {} local backingList = {}
local length = 0
local paginationOffset = 1 local paginationOffset = 1
local frame = term.current() local frame = term.current()
local drawLine = nil local drawLine = nil
@ -27,9 +28,24 @@ end
local function updateItemAt(idx, item) local function updateItemAt(idx, item)
backingList[idx] = item backingList[idx] = item
if idx > length then
length = idx
end
redrawLine(idx) redrawLine(idx)
end end
local function clearAfter(idx)
local tw, th = frame.getSize()
for j = length, idx+1, -1 do
backingList[j] = nil
end
length = idx
for y = paginationOffset-idx+2, th, 1 do
frame.setCursorPos(1, y)
frame.clearLine()
end
end
local function redraw() local function redraw()
if drawLine then if drawLine then
local tw, th = frame.getSize() local tw, th = frame.getSize()
@ -56,6 +72,7 @@ return {
setDrawLineFunc=setDrawLineFunc, setDrawLineFunc=setDrawLineFunc,
itemAt=itemAt, itemAt=itemAt,
updateItemAt=updateItemAt, updateItemAt=updateItemAt,
clearAfter=clearAfter,
redraw=redraw, redraw=redraw,
updatePage=updatePage, updatePage=updatePage,
} }