fix: Centralized ResizeFrame into UI/FrameHelpers.lua

This commit is contained in:
Salikh Gurgenidze
2025-12-28 02:56:33 +04:00
parent 7510b48684
commit 094614e9a2
2 changed files with 78 additions and 107 deletions
+1 -107
View File
@@ -923,113 +923,7 @@ end
-- Resize frame based on number of rows and columns
function BagFrame:ResizeFrame(currentRow, currentCol, columns, overrideHeight)
local buttonSize = addon.Modules.DB:GetSetting("iconSize") or addon.Constants.BUTTON_SIZE
local spacing = addon.Modules.DB:GetSetting("iconSpacing") or addon.Constants.BUTTON_SPACING
-- Calculate actual number of rows used
local totalRows = (currentRow or 0) + 1
-- Ensure at least 1 row
if totalRows < 1 then
totalRows = 1
end
-- Calculate required dimensions based on columns
local containerWidth = (columns * (buttonSize + spacing)) + 20
local containerHeight = overrideHeight or ((totalRows * (buttonSize + spacing)) + 20)
local frameWidth = containerWidth + 20
-- Check if search bar is visible
local showSearchBar = addon.Modules.DB:GetSetting("showSearchBar")
if showSearchBar == nil then
showSearchBar = true
end
-- Adjust frame height based on search bar visibility
-- Footer height varies: more space needed when search bar is visible
local titleHeight = 40
local searchBarHeight = 30
local footerHeight
local frameHeight
local hideFooter = addon.Modules.DB:GetSetting("hideFooter")
if hideFooter then
footerHeight = 10 -- Small padding at bottom
frameHeight = containerHeight + titleHeight + (showSearchBar and searchBarHeight or 0) + footerHeight
elseif showSearchBar then
footerHeight = 55 -- Increased footer height when search bar is visible (toolbar 40px + spacing 15px)
frameHeight = containerHeight + titleHeight + searchBarHeight + footerHeight -- 125 total
else
footerHeight = 45 -- Normal footer height (toolbar 40px + spacing 5px)
frameHeight = containerHeight + titleHeight + footerHeight -- 85 total
end
-- Minimum sizes
if containerWidth < 200 then
containerWidth = 200
frameWidth = 220
end
if containerHeight < 150 then
containerHeight = 150
end
if frameHeight < 250 then
frameHeight = 250
end
-- Maximum sizes
if containerWidth > 1250 then
containerWidth = 1250
frameWidth = 1270
end
if containerHeight > 1000 then
containerHeight = 1000
end
if frameHeight > 1200 then
frameHeight = 1200
end
-- Resize frames
local bagFrame = getglobal("Guda_BagFrame")
local itemContainer = getglobal("Guda_BagFrame_ItemContainer")
if bagFrame then
bagFrame:SetWidth(frameWidth)
bagFrame:SetHeight(frameHeight)
-- Always use BOTTOMRIGHT anchor to make frame grow left
bagFrame:ClearAllPoints()
if addon and addon.Modules and addon.Modules.DB then
local pos = addon.Modules.DB:GetSetting("bagFramePosition")
-- Only use saved position if it was saved as BOTTOMRIGHT
if pos and pos.point == "BOTTOMRIGHT" and pos.x and pos.y then
bagFrame:SetPoint("BOTTOMRIGHT", "UIParent", "BOTTOMRIGHT", pos.x, pos.y)
else
-- Default position: bottom right corner
bagFrame:SetPoint("BOTTOMRIGHT", UIParent, "BOTTOMRIGHT", -50, 100)
end
else
-- Fallback to default if DB not available
bagFrame:SetPoint("BOTTOMRIGHT", UIParent, "BOTTOMRIGHT", -50, 100)
end
end
if itemContainer then
itemContainer:SetWidth(containerWidth)
itemContainer:SetHeight(containerHeight)
end
-- Resize search bar and toolbar to match container width
local searchBar = getglobal("Guda_BagFrame_SearchBar")
if searchBar then
searchBar:SetWidth(containerWidth)
end
local toolbar = getglobal("Guda_BagFrame_Toolbar")
if toolbar then
toolbar:SetWidth(containerWidth)
end
return Guda_ResizeFrame("Guda_BagFrame", "Guda_BagFrame_ItemContainer", currentRow, currentCol, columns, overrideHeight)
end
-- Check if search is currently active
+77
View File
@@ -130,3 +130,80 @@ function Guda_PassesSearchFilter(itemData, searchText)
return string.find(itemName, string.lower(searchText), 1, true) ~= nil
end
-- Generic ResizeFrame for Bag/Bank frames
function Guda_ResizeFrame(frameName, containerName, currentRow, currentCol, columns, overrideHeight)
local buttonSize = addon.Modules.DB:GetSetting("iconSize") or addon.Constants.BUTTON_SIZE
local spacing = addon.Modules.DB:GetSetting("iconSpacing") or addon.Constants.BUTTON_SPACING
local totalRows = (currentRow or 0) + 1
if totalRows < 1 then totalRows = 1 end
local containerWidth = (columns * (buttonSize + spacing)) + 20
local containerHeight = overrideHeight or ((totalRows * (buttonSize + spacing)) + 20)
local frameWidth = containerWidth + 20
local showSearchBar = addon.Modules.DB:GetSetting("showSearchBar")
if showSearchBar == nil then showSearchBar = true end
local titleHeight = 40
local searchBarHeight = 30
local footerHeight = 45
local frameHeight
local hideFooter = addon.Modules.DB:GetSetting("hideFooter")
if hideFooter then
footerHeight = 10
frameHeight = containerHeight + titleHeight + (showSearchBar and searchBarHeight or 0) + footerHeight
elseif showSearchBar then
frameHeight = containerHeight + titleHeight + searchBarHeight + footerHeight
else
frameHeight = containerHeight + titleHeight + footerHeight
end
if containerWidth < 200 then
containerWidth = 200
frameWidth = 220
end
if containerHeight < 150 then containerHeight = 150 end
if frameHeight < 250 then frameHeight = 250 end
if containerWidth > 1250 then containerWidth = 1250; frameWidth = 1270 end
if containerHeight > 1000 then containerHeight = 1000 end
if frameHeight > 1200 then frameHeight = 1200 end
local frame = getglobal(frameName)
local itemContainer = getglobal(containerName)
if frame then
frame:SetWidth(frameWidth)
frame:SetHeight(frameHeight)
frame:ClearAllPoints()
-- Try to preserve saved position if present (saved only for Bag frame)
if addon and addon.Modules and addon.Modules.DB then
local settingName = (frameName == "Guda_BagFrame") and "bagFramePosition" or nil
if settingName then
local pos = addon.Modules.DB:GetSetting(settingName)
if pos and pos.point == "BOTTOMRIGHT" and pos.x and pos.y then
frame:SetPoint("BOTTOMRIGHT", "UIParent", "BOTTOMRIGHT", pos.x, pos.y)
else
frame:SetPoint("BOTTOMRIGHT", UIParent, "BOTTOMRIGHT", -50, 100)
end
else
frame:SetPoint("BOTTOMRIGHT", UIParent, "BOTTOMRIGHT", -50, 100)
end
else
frame:SetPoint("BOTTOMRIGHT", UIParent, "BOTTOMRIGHT", -50, 100)
end
end
if itemContainer then
itemContainer:SetWidth(containerWidth)
itemContainer:SetHeight(containerHeight)
end
-- Resize search bar and toolbar to match container width
local searchBar = getglobal(frameName .. "_SearchBar")
if searchBar then searchBar:SetWidth(containerWidth) end
local toolbar = getglobal(frameName .. "_Toolbar")
if toolbar then toolbar:SetWidth(containerWidth) end
end