Add estimatedHeight functions

This commit is contained in:
Ben 2024-06-02 17:51:21 +02:00
parent ce81e0a8bd
commit af06f11e03
Signed by: ben
GPG key ID: 0F54A7ED232D3319
5 changed files with 28 additions and 1 deletions

View file

@ -142,6 +142,17 @@ local function updatePage(scrollPos)
end end
end end
local function estimatedHeight()
local lastEntryFrame = subFrames[length]
if lastEntryFrame ~= nil then
local xPos, yPos = lastEntryFrame.getPosition()
local xSize, ySize = lastEntryFrame.getSize()
return yPos+ySize-1
else
return length
end
end
return { return {
setTerm=setTerm, setTerm=setTerm,
@ -150,4 +161,5 @@ return {
clearFrom=clearFrom, clearFrom=clearFrom,
redraw=redraw, redraw=redraw,
updatePage=updatePage, updatePage=updatePage,
estimatedHeight=estimatedHeight,
} }

View file

@ -38,6 +38,10 @@ local function updateItemAt(idx, item)
redrawEntry(idx) redrawEntry(idx)
end end
local function getLength()
return length
end
local function clearFrom(idx) local function clearFrom(idx)
local tw, th = frame.getSize() local tw, th = frame.getSize()
for j = length, idx, -1 do for j = length, idx, -1 do
@ -97,6 +101,7 @@ return {
setDrawEntryFunc=setDrawEntryFunc, setDrawEntryFunc=setDrawEntryFunc,
itemAt=itemAt, itemAt=itemAt,
updateItemAt=updateItemAt, updateItemAt=updateItemAt,
length=getLength,
clearFrom=clearFrom, clearFrom=clearFrom,
redraw=redraw, redraw=redraw,
updatePage=updatePage, updatePage=updatePage,

View file

@ -84,6 +84,10 @@ local function displayTab(self)
listframes.updatePage(self.scrollPos) listframes.updatePage(self.scrollPos)
end end
local function estimatedHeight()
return listframes.estimatedHeight()
end
local function onTouch(self, touch_x, touch_y) local function onTouch(self, touch_x, touch_y)
return false return false
end end
@ -94,5 +98,6 @@ return {
setTerm=setTerm, setTerm=setTerm,
fetch=fetch, fetch=fetch,
displayTab=displayTab, displayTab=displayTab,
estimatedHeight=estimatedHeight,
onTouch=onTouch, onTouch=onTouch,
} }

View file

@ -92,6 +92,10 @@ local function displayTab(self)
listview.updatePage(self.scrollPos) listview.updatePage(self.scrollPos)
end end
local function estimatedHeight()
return listview.length()
end
local function onTouch(self, touch_x, touch_y) local function onTouch(self, touch_x, touch_y)
local tw, th = self.window.getSize() local tw, th = self.window.getSize()
if touch_x > tw-5 then if touch_x > tw-5 then
@ -115,5 +119,6 @@ return {
setTerm=setTerm, setTerm=setTerm,
fetch=fetch, fetch=fetch,
displayTab=displayTab, displayTab=displayTab,
estimatedHeight=estimatedHeight,
onTouch=onTouch, onTouch=onTouch,
} }

View file

@ -39,7 +39,7 @@ local function display()
if activeTab.estimatedHeight ~= nil then if activeTab.estimatedHeight ~= nil then
estimatedHeight = activeTab.estimatedHeight() estimatedHeight = activeTab.estimatedHeight()
end end
local paginationInfo = activeTab.scrollPos .. "-" .. tabviewH .. "/" .. estimatedHeight local paginationInfo = activeTab.scrollPos .. "-" .. (activeTab.scrollPos+tabviewH-1) .. "/" .. estimatedHeight
local padding = winhlp.alignRightPadding(term, #paginationInfo) local padding = winhlp.alignRightPadding(term, #paginationInfo)
term.write(string.format("%" .. padding-1 .. "s", " ")) term.write(string.format("%" .. padding-1 .. "s", " "))
term.write(paginationInfo) term.write(paginationInfo)