fix(ui): create a window for the CountersSelector
This commit is contained in:
parent
ddea713ae4
commit
b8c83bc959
@ -57,9 +57,9 @@ end
|
|||||||
|
|
||||||
local TITLE_MARGIN = 1
|
local TITLE_MARGIN = 1
|
||||||
|
|
||||||
local function renderCountersMap(countersMap, selectedCounter, titleFn)
|
local function renderCountersMap(win, countersMap, selectedCounter, titleFn)
|
||||||
term.setCursorPos(1, 1)
|
win.setCursorPos(1, 1)
|
||||||
local _, height = term.getSize()
|
local _, height = win.getSize()
|
||||||
-- local nbCounters = utils.sizeof(countersMap)
|
-- local nbCounters = utils.sizeof(countersMap)
|
||||||
-- local totalCount = getTotalCount(countersMap)
|
-- local totalCount = getTotalCount(countersMap)
|
||||||
|
|
||||||
@ -67,8 +67,7 @@ local function renderCountersMap(countersMap, selectedCounter, titleFn)
|
|||||||
local bottomMargin = 0
|
local bottomMargin = 0
|
||||||
|
|
||||||
if titleFn ~= noTitleFn then
|
if titleFn ~= noTitleFn then
|
||||||
term.clearLine()
|
win.write('custom title: ' .. titleFn(countersMap, selectedCounter))
|
||||||
term.write('custom title: ' .. titleFn(countersMap, selectedCounter))
|
|
||||||
topMargin = TITLE_MARGIN
|
topMargin = TITLE_MARGIN
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -82,18 +81,17 @@ local function renderCountersMap(countersMap, selectedCounter, titleFn)
|
|||||||
|
|
||||||
local cursorYIndex = 1 + topMargin
|
local cursorYIndex = 1 + topMargin
|
||||||
for k,v in pairs(displayedCounters) do
|
for k,v in pairs(displayedCounters) do
|
||||||
term.setCursorPos(1, cursorYIndex)
|
win.setCursorPos(1, cursorYIndex)
|
||||||
term.clearLine()
|
|
||||||
|
|
||||||
if k == selectedCounter then
|
if k == selectedCounter then
|
||||||
term.setBackgroundColor(colors.white)
|
win.setBackgroundColor(colors.white)
|
||||||
term.setTextColor(colors.black)
|
win.setTextColor(colors.black)
|
||||||
else
|
else
|
||||||
term.setBackgroundColor(colors.black)
|
win.setBackgroundColor(colors.black)
|
||||||
term.setTextColor(colors.white)
|
win.setTextColor(colors.white)
|
||||||
end
|
end
|
||||||
|
|
||||||
term.write(tostring(v.name) .. ' ' .. tostring(v.count))
|
win.write(tostring(v.name) .. ' ' .. tostring(v.count))
|
||||||
cursorYIndex = cursorYIndex + 1
|
cursorYIndex = cursorYIndex + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -111,8 +109,7 @@ local function CountersSelector(initialCountersMap, config)
|
|||||||
error('empty countersMap provided')
|
error('empty countersMap provided')
|
||||||
end
|
end
|
||||||
|
|
||||||
saveTermConfig()
|
-- saveTermConfig()
|
||||||
term.clear()
|
|
||||||
|
|
||||||
local selectedCounter = 1
|
local selectedCounter = 1
|
||||||
local nbCounters = utils.sizeof(countersMap)
|
local nbCounters = utils.sizeof(countersMap)
|
||||||
@ -122,9 +119,18 @@ local function CountersSelector(initialCountersMap, config)
|
|||||||
error('counter cannot be greater than the counterMax')
|
error('counter cannot be greater than the counterMax')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local topHeight = 0
|
||||||
|
if titleFn ~= noTitleFn then
|
||||||
|
topHeight = 1
|
||||||
|
end
|
||||||
|
|
||||||
|
term.clear()
|
||||||
|
local mainWin = window.create(term.current(), 1, 1 + topHeight, width, height - topHeight)
|
||||||
|
|
||||||
local shouldContinue = true
|
local shouldContinue = true
|
||||||
while shouldContinue do
|
while shouldContinue do
|
||||||
renderCountersMap(countersMap, selectedCounter, titleFn)
|
mainWin.clear()
|
||||||
|
renderCountersMap(mainWin, countersMap, selectedCounter, titleFn)
|
||||||
local _, keyPressed, isHeld = os.pullEvent('key')
|
local _, keyPressed, isHeld = os.pullEvent('key')
|
||||||
|
|
||||||
if keyPressed == keys.up then
|
if keyPressed == keys.up then
|
||||||
@ -154,7 +160,7 @@ local function CountersSelector(initialCountersMap, config)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
restoreTermConfig()
|
-- restoreTermConfig()
|
||||||
|
|
||||||
return countersMap, selectedCounter
|
return countersMap, selectedCounter
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user