fix(inferium-gui): missing width for centerString
This commit is contained in:
parent
8ece6948e5
commit
c0ea32bf17
@ -3,11 +3,12 @@ local CountersSelector = require('libs/ui/CountersSelector')
|
|||||||
local counterMax = 8
|
local counterMax = 8
|
||||||
|
|
||||||
local function centerString(str, width)
|
local function centerString(str, width)
|
||||||
|
width = width or term.getSize()
|
||||||
local padding = (width / 2) - (#str / 2)
|
local padding = (width / 2) - (#str / 2)
|
||||||
return string.rep(' ', padding) .. str
|
return string.rep(' ', padding) .. str
|
||||||
end
|
end
|
||||||
|
|
||||||
local titleFn = function(countersMap)
|
local titleFn = function(countersMap, _, win)
|
||||||
local total = 0;
|
local total = 0;
|
||||||
|
|
||||||
for _, counterPayload in pairs(countersMap) do
|
for _, counterPayload in pairs(countersMap) do
|
||||||
@ -16,7 +17,8 @@ local titleFn = function(countersMap)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return centerString("" .. total .. '/' .. counterMax .. ' used farmlands' .. "")
|
local width = win.getSize()
|
||||||
|
return centerString("" .. total .. '/' .. counterMax .. ' used farmlands' .. "", width)
|
||||||
end
|
end
|
||||||
|
|
||||||
local config = {
|
local config = {
|
||||||
@ -56,5 +58,5 @@ local countersMap = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
local result = CountersSelector(countersMap, config)
|
local result = CountersSelector(countersMap, config)
|
||||||
term.clear()
|
-- term.clear()
|
||||||
print(textutils.serialize(result))
|
print(textutils.serialize(result))
|
||||||
|
|||||||
@ -127,7 +127,7 @@ local function renderTitle(win, countersMap, selectedCounter, titleFn)
|
|||||||
|
|
||||||
withColor(win, colors.white, colors.green, function()
|
withColor(win, colors.white, colors.green, function()
|
||||||
win.clearLine()
|
win.clearLine()
|
||||||
win.write(titleFn(countersMap, selectedCounter))
|
win.write(titleFn(countersMap, selectedCounter, win))
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user