From af06f11e036cb434344c2409f6484e872f6c1b7d Mon Sep 17 00:00:00 2001 From: Benedikt Ziemons Date: Sun, 2 Jun 2024 17:51:21 +0200 Subject: [PATCH] Add estimatedHeight functions --- listframes.lua | 12 ++++++++++++ listview.lua | 5 +++++ orders.lua | 5 +++++ requests.lua | 5 +++++ test.lua | 2 +- 5 files changed, 28 insertions(+), 1 deletion(-) diff --git a/listframes.lua b/listframes.lua index 1acbaea..caef743 100644 --- a/listframes.lua +++ b/listframes.lua @@ -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, } diff --git a/listview.lua b/listview.lua index 78cda8c..9de4e5a 100644 --- a/listview.lua +++ b/listview.lua @@ -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, diff --git a/orders.lua b/orders.lua index dbd2cb7..1ac2f98 100644 --- a/orders.lua +++ b/orders.lua @@ -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, } diff --git a/requests.lua b/requests.lua index 480b451..2ea7d51 100644 --- a/requests.lua +++ b/requests.lua @@ -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, } diff --git a/test.lua b/test.lua index 6493e73..19debe1 100644 --- a/test.lua +++ b/test.lua @@ -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)