Add update partial method for listview

This commit is contained in:
Ben 2024-06-02 04:22:07 +02:00
parent 3269df63d6
commit 0cb62033ef
Signed by: ben
GPG key ID: 0F54A7ED232D3319
2 changed files with 24 additions and 0 deletions

View file

@ -18,6 +18,10 @@ local function redrawLine(idx)
frame.setCursorPos(1, idx-paginationOffset+1) frame.setCursorPos(1, idx-paginationOffset+1)
if drawLine then if drawLine then
drawLine(frame, backingList[idx]) drawLine(frame, backingList[idx])
else
frame.setBackgroundColor(colors.red)
frame.clearLine()
frame.setBackgroundColor(colors.black)
end end
end end
end end
@ -59,6 +63,10 @@ local function redraw()
end end
backingIdx = backingIdx + 1 backingIdx = backingIdx + 1
end end
else
frame.setBackgroundColor(colors.red)
frame.clear()
frame.setBackgroundColor(colors.black)
end end
end end
@ -69,6 +77,20 @@ local function updatePage(newOffset)
end end
end end
local function updatePartial(filter)
if drawLine then
local tw, th = frame.getSize()
local backingIdx = paginationOffset
for idx = 1, th, 1 do
frame.setCursorPos(1, idx)
if backingList[backingIdx] ~= nil and filter(backingList[backingIdx]) then
drawLine(frame, backingList[backingIdx])
end
backingIdx = backingIdx + 1
end
end
end
return { return {
setTerm=setTerm, setTerm=setTerm,
@ -78,4 +100,5 @@ return {
clearFrom=clearFrom, clearFrom=clearFrom,
redraw=redraw, redraw=redraw,
updatePage=updatePage, updatePage=updatePage,
updatePartial=updatePartial,
} }

View file

@ -101,6 +101,7 @@ local function onTouch(self, touch_x, touch_y)
else else
permset.add(allowed_items, obj.answer.name) permset.add(allowed_items, obj.answer.name)
end end
listview.updatePartial(function (item) return item.answer ~= nil and item.answer.name == obj.answer.name end)
return true return true
end end
end end