fix(inferium-gui): missing width for centerString

This commit is contained in:
Guillaume ARM 2024-05-23 23:22:40 +02:00
parent 8ece6948e5
commit c0ea32bf17
2 changed files with 6 additions and 4 deletions

View File

@ -3,11 +3,12 @@ local CountersSelector = require('libs/ui/CountersSelector')
local counterMax = 8
local function centerString(str, width)
width = width or term.getSize()
local padding = (width / 2) - (#str / 2)
return string.rep(' ', padding) .. str
end
local titleFn = function(countersMap)
local titleFn = function(countersMap, _, win)
local total = 0;
for _, counterPayload in pairs(countersMap) do
@ -16,7 +17,8 @@ local titleFn = function(countersMap)
end
end
return centerString("" .. total .. '/' .. counterMax .. ' used farmlands' .. "")
local width = win.getSize()
return centerString("" .. total .. '/' .. counterMax .. ' used farmlands' .. "", width)
end
local config = {
@ -56,5 +58,5 @@ local countersMap = {
}
local result = CountersSelector(countersMap, config)
term.clear()
-- term.clear()
print(textutils.serialize(result))

View File

@ -127,7 +127,7 @@ local function renderTitle(win, countersMap, selectedCounter, titleFn)
withColor(win, colors.white, colors.green, function()
win.clearLine()
win.write(titleFn(countersMap, selectedCounter))
win.write(titleFn(countersMap, selectedCounter, win))
end)
end