Fix pagination naming

This commit is contained in:
Ben 2024-06-02 17:39:21 +02:00
parent d990a19218
commit 17af6e2304
Signed by: ben
GPG key ID: 0F54A7ED232D3319
2 changed files with 19 additions and 19 deletions

View file

@ -4,8 +4,8 @@ local length = 0
local frame = term.current()
local drawEntry = nil
-- pagination offset in number of lines (not number of entries!)
local paginationOffset = 1
-- pagination start line (not number of entries!)
local paginationPos = 1
local function setDrawEntryFunc(drawLineFunc)
@ -58,13 +58,13 @@ local function redrawEntry(idx)
local tw, th = frame.getSize()
local xPos, yPos = entryFrame.getPosition()
local xSize, ySize = entryFrame.getSize()
entryFrame.setVisible((yPos+ySize-1) >= paginationOffset and yPos <= th)
entryFrame.setVisible((yPos+ySize-1) >= paginationPos and yPos <= th)
end
end
local function repositionOrCreateEntryFrame(idx)
local previousFrame = subFrames[idx-1]
local yPos = 1
local yPos = 2-paginationPos
if previousFrame ~= nil then
local xPos
xPos, yPos = previousFrame.getPosition()
@ -101,7 +101,7 @@ local function clearFrom(idx)
end
end
length = idx-1
for y = idx-paginationOffset+1, th, 1 do
for y = idx-paginationPos+1, th, 1 do
frame.setCursorPos(1, y)
frame.clearLine()
end
@ -110,10 +110,10 @@ end
local function redraw()
if drawEntry then
local tw, th = frame.getSize()
local yPos = 1
local yPos = 2-paginationPos
for idx = 1, length, 1 do
assert(backingList[idx] ~= nil, "nil element at idx="..idx)
if yPos < paginationOffset+th then
if yPos <= th then
repositionOrCreateEntryFrame(idx)
redrawEntry(idx)
local xSize, ySize = subFrames[idx].getSize()
@ -135,9 +135,9 @@ local function setTerm(termlike)
redraw()
end
local function updatePage(newOffset)
if newOffset ~= paginationOffset then
paginationOffset = newOffset
local function updatePage(scrollPos)
if scrollPos ~= paginationPos then
paginationPos = scrollPos
redraw()
end
end

View file

@ -1,6 +1,6 @@
local backingList = {}
local length = 0
local paginationOffset = 1
local paginationPos = 1
local frame = term.current()
local drawEntry = nil
@ -14,8 +14,8 @@ end
local function redrawEntry(idx)
local tw, th = frame.getSize()
if idx >= paginationOffset and idx-paginationOffset <= th then
frame.setCursorPos(1, idx-paginationOffset+1)
if idx >= paginationPos and idx-paginationPos <= th then
frame.setCursorPos(1, idx-paginationPos+1)
if drawEntry then
drawEntry(frame, backingList[idx])
else
@ -44,7 +44,7 @@ local function clearFrom(idx)
backingList[j] = nil
end
length = idx
for y = idx-paginationOffset+1, th, 1 do
for y = idx-paginationPos+1, th, 1 do
frame.setCursorPos(1, y)
frame.clearLine()
end
@ -53,7 +53,7 @@ end
local function redraw()
if drawEntry then
local tw, th = frame.getSize()
local backingIdx = paginationOffset
local backingIdx = paginationPos
for idx = 1, th, 1 do
frame.setCursorPos(1, idx)
if backingList[backingIdx] == nil then
@ -70,9 +70,9 @@ local function redraw()
end
end
local function updatePage(newOffset)
if newOffset ~= paginationOffset then
paginationOffset = newOffset
local function updatePage(scrollPos)
if scrollPos ~= paginationPos then
paginationPos = scrollPos
redraw()
end
end
@ -80,7 +80,7 @@ end
local function updatePartial(filter)
if drawEntry then
local tw, th = frame.getSize()
local backingIdx = paginationOffset
local backingIdx = paginationPos
for idx = 1, th, 1 do
frame.setCursorPos(1, idx)
if backingList[backingIdx] ~= nil and filter(backingList[backingIdx]) then