diff --git a/itemcontroller.lua b/itemcontroller.lua index e5b002f..9e492ba 100644 --- a/itemcontroller.lua +++ b/itemcontroller.lua @@ -241,6 +241,22 @@ end local function NOOP() end +local function getCenterPad(contentWidth, widthBudget) + if widthBudget < contentWidth then + return 0, 0 + end + + local pad = (widthBudget - contentWidth) / 2 + return math.floor(pad), math.ceil(pad) +end + +local function fitText(text, widthBudget) + if #text <= widthBudget then + return text + end + return text:sub(1, #widthBudget) +end + local PAGES = { MAIN = function(state) local pageState = state:currentPageState({}) @@ -291,23 +307,27 @@ local PAGES = { end, GROUP_DETAIL = function(state, newPage) + local paddingSide = 1 + local paddingTop = 1 + local group = state:getExtra() if group == nil then state:setPage("MAIN") return NOOP end - local title = Text:new{ - text = group:getSimpleName(), - bgColor = colors.gray - } + local itemName = fitText(group:getSimpleName(), state.width - (paddingSide * 2)) + local itemLeftPad, itemRightPad = getCenterPad(#itemName, state.width - (paddingSide * 2)) local paddedTitle = Padding:new{ top = 1, - left = 1, - right = 1, + left = itemLeftPad, + right = itemRightPad, bottom = 1, - element = title, + element = Text:new{ + text = itemName, + bgColor = colors.gray + }, bgColor = colors.gray } @@ -344,10 +364,10 @@ local PAGES = { local stuffContainer = Container:new{ [Children:getId()] = { Padding:new{ - top = 1, - left = 1, - right = 1, - bottom = 1, + top = paddingTop, + left = paddingSide, + right = paddingSide, + bottom = 0, element = infoElements, } },