From 17af6e23044928805391628b5f48f7bfa74a9ce6 Mon Sep 17 00:00:00 2001 From: Benedikt Ziemons Date: Sun, 2 Jun 2024 17:39:21 +0200 Subject: [PATCH] Fix pagination naming --- listframes.lua | 20 ++++++++++---------- listview.lua | 18 +++++++++--------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/listframes.lua b/listframes.lua index 56c4004..1acbaea 100644 --- a/listframes.lua +++ b/listframes.lua @@ -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 diff --git a/listview.lua b/listview.lua index 7136867..78cda8c 100644 --- a/listview.lua +++ b/listview.lua @@ -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