From 094614e9a25216a081194a50d8b9187559ed64ac Mon Sep 17 00:00:00 2001 From: Salikh Gurgenidze Date: Sun, 28 Dec 2025 02:56:33 +0400 Subject: [PATCH] fix: Centralized ResizeFrame into UI/FrameHelpers.lua --- UI/BagFrame.lua | 108 +------------------------------------------- UI/FrameHelpers.lua | 77 +++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 107 deletions(-) diff --git a/UI/BagFrame.lua b/UI/BagFrame.lua index 57a3ade..6ba7d05 100644 --- a/UI/BagFrame.lua +++ b/UI/BagFrame.lua @@ -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 diff --git a/UI/FrameHelpers.lua b/UI/FrameHelpers.lua index d80ffe8..91466da 100644 --- a/UI/FrameHelpers.lua +++ b/UI/FrameHelpers.lua @@ -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