From 94dcfb3dade84450e09ed7cb8e5fc7b9930240ce Mon Sep 17 00:00:00 2001 From: Brues <5278969+brues-code@users.noreply.github.com> Date: Thu, 29 Oct 2026 14:16:43 -0500 Subject: [PATCH] Compute bar layout options instead of tabulating pfGridmath pfGridmath listed every exact cols x rows grid per bar size; the only live use was seeding the layout dropdown, which a divisor loop now does. Everything else that read it was unreachable: every layout option is a "cols x rows" string, so ResolveBarLayout's BarLayoutFormfactor lookup never matched, and the actionbar module resets a stored layout that isn't one before BarLayoutSize/BarButtonAnchor run, so their fallbacks never fired. BarLayoutFormfactor and env/tables.lua go with it. --- api/api.lua | 69 +++++++++++++------------------------------ env/tables.lua | 15 ---------- init/env.xml | 1 - modules/actionbar.lua | 3 +- 4 files changed, 22 insertions(+), 66 deletions(-) delete mode 100644 env/tables.lua diff --git a/api/api.lua b/api/api.lua index a44edb22..91b01f0b 100644 --- a/api/api.lua +++ b/api/api.lua @@ -1353,15 +1353,18 @@ end -- [ Bar Layout Options ] -- -- 'barsize' size of bar in number of buttons --- returns: array of options as strings for pfUI.gui.bar +-- returns: array of options as strings for pfUI.gui.bar: every grid +-- that fits the bar exactly, plus common uneven ones function pfUI.api.BarLayoutOptions(barsize) assert(barsize > 0 and barsize <= NUM_ACTIONBAR_BUTTONS,"BarLayoutOptions: barsize "..tostring(barsize).." is invalid") local options, seen = {}, {} local function add(option) if not seen[option] then table.insert(options, option); seen[option] = true end end - for i,layout in ipairs(pfGridmath[barsize]) do - add(string.format("%d x %d",layout[1],layout[2])) + for cols = 1, barsize do + if barsize % cols == 0 then + add(string.format("%d x %d", cols, barsize / cols)) + end end for _, option in ipairs({ "1 x 12", "1 x 10", "2 x 10", "2 x 5", "3 x 10", "3 x 5", "3 x 3", @@ -1381,49 +1384,23 @@ function pfUI.api.BarLayoutOptions(barsize) return options end --- [ Bar Layout Formfactor ] -- --- 'option' string option as used in pfUI_config.bars[bar].option --- returns: integer formfactor -local formfactors = {} -setmetatable(formfactors, {__mode = "v"}) -- weak table so values not referenced are collected on next gc -function pfUI.api.BarLayoutFormfactor(option) - if formfactors[option] then - return formfactors[option] - else - for barsize,_ in ipairs(pfGridmath) do - local options = pfUI.api.BarLayoutOptions(barsize) - for i,opt in ipairs(options) do - if opt == option then - formfactors[option] = i - return formfactors[option] - end - end - end - end -end - +-- 'formfactor' has to be a "cols x rows" string; the actionbar module resets +-- a stored layout that isn't one before it lays out a bar local function ResolveBarLayout(barsize, formfactor, uneven) - local layout = tostring(formfactor or "") - local _, _, a, b = string.find(layout, "(%d+)%s*x%s*(%d+)") - if a and b then - local cols, rows = tonumber(a), tonumber(b) - cols = math.min(NUM_ACTIONBAR_BUTTONS, math.max(1, cols)) - rows = math.min(NUM_ACTIONBAR_BUTTONS, math.max(1, rows)) - local orientation = string.upper(uneven or "DOWN") - local mode = (orientation == "LEFT" or orientation == "RIGHT") and "cols" or "rows" - if mode == "rows" then - cols = math.max(1, math.min(cols, barsize)) - rows = math.max(1, math.ceil(barsize / cols)) - else - rows = math.max(1, math.min(rows, barsize)) - cols = math.max(1, math.ceil(barsize / rows)) - end - return cols, rows, mode, orientation + local _, _, a, b = string.find(formfactor, "(%d+)%s*x%s*(%d+)") + local cols, rows = tonumber(a), tonumber(b) + cols = math.min(NUM_ACTIONBAR_BUTTONS, math.max(1, cols)) + rows = math.min(NUM_ACTIONBAR_BUTTONS, math.max(1, rows)) + local orientation = string.upper(uneven or "DOWN") + local mode = (orientation == "LEFT" or orientation == "RIGHT") and "cols" or "rows" + if mode == "rows" then + cols = math.max(1, math.min(cols, barsize)) + rows = math.max(1, math.ceil(barsize / cols)) + else + rows = math.max(1, math.min(rows, barsize)) + cols = math.max(1, math.ceil(barsize / rows)) end - local index = pfUI.api.BarLayoutFormfactor(layout) - if not index then return nil end - local cols, rows = unpack(pfGridmath[barsize][index]) - return cols, rows, "rows", "DOWN" + return cols, rows, mode, orientation end -- [ Bar Layout Size ] -- @@ -1434,7 +1411,6 @@ end function pfUI.api.BarLayoutSize(bar,barsize,formfactor,iconsize,bordersize,padding,uneven,fillmode) assert(barsize > 0 and barsize <= NUM_ACTIONBAR_BUTTONS,"BarLayoutSize: barsize "..tostring(barsize).." is invalid") local cols, rows = ResolveBarLayout(barsize, formfactor, uneven) - if not cols or not rows then cols, rows = unpack(pfGridmath[barsize][1]) end local width = (iconsize + bordersize*2+padding) * cols + padding local height = (iconsize + bordersize*2+padding) * rows + padding bar._size = {width,height} @@ -1452,9 +1428,6 @@ end function pfUI.api.BarButtonAnchor(button,basename,buttonindex,barsize,formfactor,iconsize,bordersize,padding,uneven,fillmode) assert(barsize > 0 and barsize <= NUM_ACTIONBAR_BUTTONS,"BarButtonAnchor: barsize "..tostring(barsize).." is invalid") local cols, rows, mode, orientation = ResolveBarLayout(barsize, formfactor, uneven) - if not cols or not rows then - cols, rows, mode, orientation = unpack(pfGridmath[barsize][1]), "rows", "DOWN" - end -- fillmode: remap buttonindex to slotindex (grid position in native fill order) -- only needed when fill direction differs from layout mode diff --git a/env/tables.lua b/env/tables.lua deleted file mode 100644 index c2a7f385..00000000 --- a/env/tables.lua +++ /dev/null @@ -1,15 +0,0 @@ --- barlength = {[formfactor]={cols, rows}} -pfGridmath = { - [1] = {{1,1}}, - [2] = {{2,1},{1,2}}, - [3] = {{3,1},{1,3}}, - [4] = {{4,1},{2,2},{1,4}}, - [5] = {{5,1},{1,5}}, - [6] = {{6,1},{3,2},{2,3},{1,6}}, - [7] = {{7,1},{1,7}}, - [8] = {{8,1},{4,2},{2,4},{1,8}}, - [9] = {{9,1},{3,3},{1,9}}, - [10] = {{10,1},{5,2},{2,5},{1,10}}, - [11] = {{11,1},{1,11}}, - [12] = {{12,1},{6,2},{4,3},{3,4},{2,6},{1,12}} -} diff --git a/init/env.xml b/init/env.xml index 6e8e35ca..b8516679 100644 --- a/init/env.xml +++ b/init/env.xml @@ -7,7 +7,6 @@ - diff --git a/modules/actionbar.lua b/modules/actionbar.lua index 82e3fdc0..1dd1de95 100644 --- a/modules/actionbar.lua +++ b/modules/actionbar.lua @@ -1206,8 +1206,7 @@ pfUI:RegisterModule("actionbar", function () end -- the stored layout is invalid, temporary fallback - local _, _, fcols, frows = string.find(tostring(formfactor or ""), "(%d+)%s*x%s*(%d+)") - if not ((fcols and frows) or pfGridmath[buttons][BarLayoutFormfactor(formfactor)]) then + if not fcols2 or not frows2 then formfactor = BarLayoutOptions(buttons)[1] end