Compare commits

...

2 commits

Author SHA1 Message Date
Ben ce81e0a8bd
Add pagination info view 2024-06-02 17:40:22 +02:00
Ben 17af6e2304
Fix pagination naming 2024-06-02 17:39:21 +02:00
3 changed files with 58 additions and 35 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

View file

@ -17,9 +17,11 @@ local function display()
term.setCursorPos(1,1)
term.setBackgroundColor(colors.yellow)
term.setTextColor(colors.black)
local activeTab = tabview.currentTab()
if activeTab ~= nil then
term.clearLine()
term.write(" " .. string.upper(tabview.currentTab().name) .. " ")
term.write(" " .. string.upper(activeTab.name) .. " ")
term.setCursorPos(tw-8,1)
if currently_working then
term.write(" w ")
@ -29,13 +31,34 @@ local function display()
term.write(" ^ v ")
term.setBackgroundColor(colors.black)
term.setTextColor(colors.white)
term.setTextColor(colors.gray)
term.setCursorPos(1,2)
if tabview_window ~= nil then
local tabviewW, tabviewH = tabview_window.getSize()
local estimatedHeight = "?"
if activeTab.estimatedHeight ~= nil then
estimatedHeight = activeTab.estimatedHeight()
end
local paginationInfo = activeTab.scrollPos .. "-" .. tabviewH .. "/" .. estimatedHeight
local padding = winhlp.alignRightPadding(term, #paginationInfo)
term.write(string.format("%" .. padding-1 .. "s", " "))
term.write(paginationInfo)
term.write(" ")
else
term.clearLine()
end
term.setTextColor(colors.white)
for name, tab in pairs(tabview.allTabs()) do
tab.displayTab(tab)
end
else
term.setBackgroundColor(colors.black)
term.clear()
term.setBackgroundColor(colors.yellow)
term.clearLine()
term.write(" NO ACTIVE TAB ")
end
end