From 183e05fd92962311f734331b19687515ce0ce7e5 Mon Sep 17 00:00:00 2001 From: Chev Date: Mon, 6 Nov 2023 00:24:56 -0800 Subject: [PATCH] SprayMesh Extended: Fix layout issue when first spray is added to saved sprays --- .../lua/vgui/dsprayconfiguration.lua | 49 ++++++++++++------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/addons/spraymesh_extended/lua/vgui/dsprayconfiguration.lua b/addons/spraymesh_extended/lua/vgui/dsprayconfiguration.lua index 82cd3b6..f207e7d 100644 --- a/addons/spraymesh_extended/lua/vgui/dsprayconfiguration.lua +++ b/addons/spraymesh_extended/lua/vgui/dsprayconfiguration.lua @@ -127,22 +127,7 @@ function PANEL:Init() end self.SavedSpraySearch.OnValueChange = function(panel, text) - for url, sprayPanel in pairs(self.Sprays) do - -- Since spray panels are wrapped inside a parent, we want to target visibility for the parent instead - local panelParent = sprayPanel:GetParent() - - local queryIsEmpty = string.Trim(text, " ") == "" - local textInURL = string.find(url:lower(), text:lower(), 0, true) ~= nil - local textInName = string.find(sprayPanel.Name:lower(), text:lower(), 0, true) ~= nil - - if queryIsEmpty or textInURL or textInName then - panelParent:SetVisible(true) - else - panelParent:SetVisible(false) - end - end - - self.IconLayout:Layout() + self:FilterSearch(text) end self.Scroll = self.SavedSpraysPanel:Add("DScrollPanel") @@ -436,7 +421,7 @@ function PANEL:AddSpray(url, name) "Confirmation:", "Delete", function() - self.Sprays[panel.URL] = nil + self.Sprays["https://" .. panel.URL] = nil spraylist.RemoveSpray("https://" .. panel.URL) @@ -495,6 +480,36 @@ function PANEL:AddSpray(url, name) end self.IconLayout:Layout() + + -- Gotta give time to let the newly-added entry and the IconLayout adjust their sizes, then + -- we adjust the DScrollPanel canvas size. From my tests, this is only necessary + -- when the player adds their FIRST spray to the list + timer.Simple(0, function() + if IsValid(self.Scroll) then + self.Scroll:InvalidateLayout() + end + end) +end + +function PANEL:FilterSearch(text) + for url, sprayPanel in pairs(self.Sprays) do + if not IsValid(sprayPanel) then continue end + + -- Since spray panels are wrapped inside a parent, we want to target visibility for the parent instead + local panelParent = sprayPanel:GetParent() + + local queryIsEmpty = string.Trim(text, " ") == "" + local textInURL = string.find(url:lower(), text:lower(), 0, true) ~= nil + local textInName = string.find(sprayPanel.Name:lower(), text:lower(), 0, true) ~= nil + + if queryIsEmpty or textInURL or textInName then + panelParent:SetVisible(true) + else + panelParent:SetVisible(false) + end + end + + self.IconLayout:Layout() end -- Register control