Compare commits
2 commits
d990a19218
...
ce81e0a8bd
Author | SHA1 | Date | |
---|---|---|---|
Ben | ce81e0a8bd | ||
Ben | 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
|
||||||
|
|
55
test.lua
55
test.lua
|
@ -17,24 +17,47 @@ local function display()
|
||||||
term.setCursorPos(1,1)
|
term.setCursorPos(1,1)
|
||||||
term.setBackgroundColor(colors.yellow)
|
term.setBackgroundColor(colors.yellow)
|
||||||
term.setTextColor(colors.black)
|
term.setTextColor(colors.black)
|
||||||
term.clearLine()
|
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)
|
term.setCursorPos(tw-8,1)
|
||||||
if currently_working then
|
if currently_working then
|
||||||
term.write(" w ")
|
term.write(" w ")
|
||||||
|
else
|
||||||
|
term.write(" R ")
|
||||||
|
end
|
||||||
|
term.write(" ^ v ")
|
||||||
|
|
||||||
|
term.setBackgroundColor(colors.black)
|
||||||
|
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
|
else
|
||||||
term.write(" R ")
|
term.setBackgroundColor(colors.black)
|
||||||
end
|
term.clear()
|
||||||
term.write(" ^ v ")
|
term.setBackgroundColor(colors.yellow)
|
||||||
|
term.clearLine()
|
||||||
term.setBackgroundColor(colors.black)
|
term.write(" NO ACTIVE TAB ")
|
||||||
term.setTextColor(colors.white)
|
|
||||||
term.setCursorPos(1,2)
|
|
||||||
term.clearLine()
|
|
||||||
|
|
||||||
for name, tab in pairs(tabview.allTabs()) do
|
|
||||||
tab.displayTab(tab)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue