Fix pagination naming
This commit is contained in:
parent
d990a19218
commit
17af6e2304
|
@ -4,8 +4,8 @@ local length = 0
|
||||||
local frame = term.current()
|
local frame = term.current()
|
||||||
local drawEntry = nil
|
local drawEntry = nil
|
||||||
|
|
||||||
-- pagination offset in number of lines (not number of entries!)
|
-- pagination start line (not number of entries!)
|
||||||
local paginationOffset = 1
|
local paginationPos = 1
|
||||||
|
|
||||||
|
|
||||||
local function setDrawEntryFunc(drawLineFunc)
|
local function setDrawEntryFunc(drawLineFunc)
|
||||||
|
@ -58,13 +58,13 @@ local function redrawEntry(idx)
|
||||||
local tw, th = frame.getSize()
|
local tw, th = frame.getSize()
|
||||||
local xPos, yPos = entryFrame.getPosition()
|
local xPos, yPos = entryFrame.getPosition()
|
||||||
local xSize, ySize = entryFrame.getSize()
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
local function repositionOrCreateEntryFrame(idx)
|
local function repositionOrCreateEntryFrame(idx)
|
||||||
local previousFrame = subFrames[idx-1]
|
local previousFrame = subFrames[idx-1]
|
||||||
local yPos = 1
|
local yPos = 2-paginationPos
|
||||||
if previousFrame ~= nil then
|
if previousFrame ~= nil then
|
||||||
local xPos
|
local xPos
|
||||||
xPos, yPos = previousFrame.getPosition()
|
xPos, yPos = previousFrame.getPosition()
|
||||||
|
@ -101,7 +101,7 @@ local function clearFrom(idx)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
length = idx-1
|
length = idx-1
|
||||||
for y = idx-paginationOffset+1, th, 1 do
|
for y = idx-paginationPos+1, th, 1 do
|
||||||
frame.setCursorPos(1, y)
|
frame.setCursorPos(1, y)
|
||||||
frame.clearLine()
|
frame.clearLine()
|
||||||
end
|
end
|
||||||
|
@ -110,10 +110,10 @@ end
|
||||||
local function redraw()
|
local function redraw()
|
||||||
if drawEntry then
|
if drawEntry then
|
||||||
local tw, th = frame.getSize()
|
local tw, th = frame.getSize()
|
||||||
local yPos = 1
|
local yPos = 2-paginationPos
|
||||||
for idx = 1, length, 1 do
|
for idx = 1, length, 1 do
|
||||||
assert(backingList[idx] ~= nil, "nil element at idx="..idx)
|
assert(backingList[idx] ~= nil, "nil element at idx="..idx)
|
||||||
if yPos < paginationOffset+th then
|
if yPos <= th then
|
||||||
repositionOrCreateEntryFrame(idx)
|
repositionOrCreateEntryFrame(idx)
|
||||||
redrawEntry(idx)
|
redrawEntry(idx)
|
||||||
local xSize, ySize = subFrames[idx].getSize()
|
local xSize, ySize = subFrames[idx].getSize()
|
||||||
|
@ -135,9 +135,9 @@ local function setTerm(termlike)
|
||||||
redraw()
|
redraw()
|
||||||
end
|
end
|
||||||
|
|
||||||
local function updatePage(newOffset)
|
local function updatePage(scrollPos)
|
||||||
if newOffset ~= paginationOffset then
|
if scrollPos ~= paginationPos then
|
||||||
paginationOffset = newOffset
|
paginationPos = scrollPos
|
||||||
redraw()
|
redraw()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
18
listview.lua
18
listview.lua
|
@ -1,6 +1,6 @@
|
||||||
local backingList = {}
|
local backingList = {}
|
||||||
local length = 0
|
local length = 0
|
||||||
local paginationOffset = 1
|
local paginationPos = 1
|
||||||
local frame = term.current()
|
local frame = term.current()
|
||||||
local drawEntry = nil
|
local drawEntry = nil
|
||||||
|
|
||||||
|
@ -14,8 +14,8 @@ end
|
||||||
|
|
||||||
local function redrawEntry(idx)
|
local function redrawEntry(idx)
|
||||||
local tw, th = frame.getSize()
|
local tw, th = frame.getSize()
|
||||||
if idx >= paginationOffset and idx-paginationOffset <= th then
|
if idx >= paginationPos and idx-paginationPos <= th then
|
||||||
frame.setCursorPos(1, idx-paginationOffset+1)
|
frame.setCursorPos(1, idx-paginationPos+1)
|
||||||
if drawEntry then
|
if drawEntry then
|
||||||
drawEntry(frame, backingList[idx])
|
drawEntry(frame, backingList[idx])
|
||||||
else
|
else
|
||||||
|
@ -44,7 +44,7 @@ local function clearFrom(idx)
|
||||||
backingList[j] = nil
|
backingList[j] = nil
|
||||||
end
|
end
|
||||||
length = idx
|
length = idx
|
||||||
for y = idx-paginationOffset+1, th, 1 do
|
for y = idx-paginationPos+1, th, 1 do
|
||||||
frame.setCursorPos(1, y)
|
frame.setCursorPos(1, y)
|
||||||
frame.clearLine()
|
frame.clearLine()
|
||||||
end
|
end
|
||||||
|
@ -53,7 +53,7 @@ end
|
||||||
local function redraw()
|
local function redraw()
|
||||||
if drawEntry then
|
if drawEntry then
|
||||||
local tw, th = frame.getSize()
|
local tw, th = frame.getSize()
|
||||||
local backingIdx = paginationOffset
|
local backingIdx = paginationPos
|
||||||
for idx = 1, th, 1 do
|
for idx = 1, th, 1 do
|
||||||
frame.setCursorPos(1, idx)
|
frame.setCursorPos(1, idx)
|
||||||
if backingList[backingIdx] == nil then
|
if backingList[backingIdx] == nil then
|
||||||
|
@ -70,9 +70,9 @@ local function redraw()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function updatePage(newOffset)
|
local function updatePage(scrollPos)
|
||||||
if newOffset ~= paginationOffset then
|
if scrollPos ~= paginationPos then
|
||||||
paginationOffset = newOffset
|
paginationPos = scrollPos
|
||||||
redraw()
|
redraw()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -80,7 +80,7 @@ end
|
||||||
local function updatePartial(filter)
|
local function updatePartial(filter)
|
||||||
if drawEntry then
|
if drawEntry then
|
||||||
local tw, th = frame.getSize()
|
local tw, th = frame.getSize()
|
||||||
local backingIdx = paginationOffset
|
local backingIdx = paginationPos
|
||||||
for idx = 1, th, 1 do
|
for idx = 1, th, 1 do
|
||||||
frame.setCursorPos(1, idx)
|
frame.setCursorPos(1, idx)
|
||||||
if backingList[backingIdx] ~= nil and filter(backingList[backingIdx]) then
|
if backingList[backingIdx] ~= nil and filter(backingList[backingIdx]) then
|
||||||
|
|
Loading…
Reference in a new issue