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
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 {
setTerm=setTerm,
@ -150,4 +161,5 @@ return {
clearFrom=clearFrom,
redraw=redraw,
updatePage=updatePage,
estimatedHeight=estimatedHeight,
}

View file

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

View file

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

View file

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

View file

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