From 4accb650c6cf5a6cf319e2254abc53be44e1ae27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?tekkub=20=CA=95=20=C2=B4=E1=B4=A5=60=20=CA=94?= Date: Sun, 11 Sep 2016 19:45:02 -0600 Subject: [PATCH] Move refresh logic out of the generic frame factory --- externals/ui-scrollbar.lua | 1 - frames/MainFrame.lua | 10 ++++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/externals/ui-scrollbar.lua b/externals/ui-scrollbar.lua index e47470d..a134683 100644 --- a/externals/ui-scrollbar.lua +++ b/externals/ui-scrollbar.lua @@ -95,7 +95,6 @@ function ns.NewScrollBar(parent, offset, step) local value = self:GetValue() if value == min then up:Disable() else up:Enable() end if value == max then down:Disable() else down:Enable() end - if self.Refresh then self:Refresh() end end f:HookScript("OnMinMaxChanged", UpdateUpDown) diff --git a/frames/MainFrame.lua b/frames/MainFrame.lua index f648143..7203535 100644 --- a/frames/MainFrame.lua +++ b/frames/MainFrame.lua @@ -12,7 +12,7 @@ local NUMROWS = 14 function ns.NewMainFrame() local GVS = CreateFrame("frame", nil, MerchantFrame) - local search = ns.MakeSearchField(GVS, scrollbar.Refresh) + local search = ns.MakeSearchField(GVS) local rows = {} for i=1,NUMROWS do @@ -30,7 +30,7 @@ function ns.NewMainFrame() end local scrollbar = ns.NewScrollBar(GVS, 0, 5) - function scrollbar:Refresh() + local function Refresh() local offset = scrollbar:GetValue() local searchstring = search:GetText() local n = GetMerchantNumItems() @@ -48,6 +48,8 @@ function ns.NewMainFrame() scrollbar:SetMinMaxValues(0, math.max(0, n_searchmatch - NUMROWS)) for i=row,NUMROWS do rows[i]:Hide() end end + scrollbar:SetScript("OnValueChanged", Refresh) + search:SetScript("OnTextChanged", Refresh) @@ -59,12 +61,12 @@ function ns.NewMainFrame() scrollbar:Increment() end end) - GVS:SetScript("OnEvent", scrollbar.Refresh) + GVS:SetScript("OnEvent", Refresh) GVS:SetScript("OnShow", function(self, noreset) local max = math.max(0, GetMerchantNumItems() - NUMROWS) scrollbar:SetMinMaxValues(0, max) scrollbar:SetValue(noreset and math.min(scrollbar:GetValue(), max) or 0) - scrollbar.Refresh() + Refresh() GVS:RegisterEvent("BAG_UPDATE") GVS:RegisterEvent("MERCHANT_UPDATE")