[listframes] cache estimatedTotalHeight
This commit is contained in:
parent
2a8e35ad94
commit
419cb82a2d
|
@ -3,6 +3,7 @@ local subFrames = {}
|
|||
local length = 0
|
||||
local frame = term.current()
|
||||
local drawEntry = nil
|
||||
local estimatedTotalHeight = 0
|
||||
|
||||
-- pagination start line (not number of entries!)
|
||||
local paginationPos = 1
|
||||
|
@ -58,7 +59,11 @@ local function redrawEntry(idx)
|
|||
local tw, th = frame.getSize()
|
||||
local xPos, yPos = entryFrame.getPosition()
|
||||
local xSize, ySize = entryFrame.getSize()
|
||||
entryFrame.setVisible((yPos + ySize) > 1 and yPos <= th)
|
||||
local yEnd = yPos+ySize-1
|
||||
entryFrame.setVisible(yEnd > 0 and yPos <= th)
|
||||
if yEnd > estimatedTotalHeight then
|
||||
estimatedTotalHeight = yEnd
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -93,6 +98,7 @@ local function updateItemAt(idx, item)
|
|||
end
|
||||
|
||||
local function clearFrom(idx)
|
||||
estimatedTotalHeight = (idx-1).."?"
|
||||
local tw, th = frame.getSize()
|
||||
for j = length, idx, -1 do
|
||||
backingList[j] = nil
|
||||
|
@ -144,16 +150,13 @@ local function updatePage(scrollPos)
|
|||
end
|
||||
|
||||
local function estimatedHeight()
|
||||
local firstEntryFrame = subFrames[1]
|
||||
local lastEntryFrame = subFrames[length]
|
||||
if firstEntryFrame ~= nil and lastEntryFrame ~= nil then
|
||||
local firstXPos, firstYPos = firstEntryFrame.getPosition()
|
||||
if lastEntryFrame ~= nil and lastEntryFrame.isVisible() then
|
||||
local xPos, yPos = lastEntryFrame.getPosition()
|
||||
local xSize, ySize = lastEntryFrame.getSize()
|
||||
return yPos-firstYPos+ySize
|
||||
else
|
||||
return length
|
||||
estimatedTotalHeight = yPos+ySize-1
|
||||
end
|
||||
return estimatedTotalHeight
|
||||
end
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue