move search field change logic to mainframe

This commit is contained in:
tekkub ʕ ´ᴥ` ʔ 2016-09-11 19:28:47 -06:00
parent f925cb584a
commit 35d9a4d95e
3 changed files with 9 additions and 15 deletions

View File

@ -29,7 +29,7 @@ local ItemSearch = ns.LibItemSearch
--[[ general search ]]-- --[[ general search ]]--
function ItemSearch:Find(itemLink, search) function ItemSearch:Find(itemLink, search)
if not search then if not search or search == "" then
return true return true
end end

View File

@ -12,6 +12,8 @@ local NUMROWS = 14
function ns.NewMainFrame() function ns.NewMainFrame()
local GVS = CreateFrame("frame", nil, MerchantFrame) local GVS = CreateFrame("frame", nil, MerchantFrame)
local search = ns.MakeSearchField(GVS, scrollbar.Refresh)
local rows = {} local rows = {}
for i=1,NUMROWS do for i=1,NUMROWS do
local row = ns.NewMerchantItemFrame(GVS) local row = ns.NewMerchantItemFrame(GVS)
@ -27,15 +29,15 @@ function ns.NewMainFrame()
rows[i] = row rows[i] = row
end end
local scrollbar = ns.NewScrollBar(GVS, 0, 5) local scrollbar = ns.NewScrollBar(GVS, 0, 5)
function scrollbar:Refresh() function scrollbar:Refresh()
local offset = scrollbar:GetValue() local offset = scrollbar:GetValue()
local searchstring = search:GetText()
local n = GetMerchantNumItems() local n = GetMerchantNumItems()
local row, n_searchmatch = 1, 0 local row, n_searchmatch = 1, 0
for i=1,n do for i=1,n do
local link = GetMerchantItemLink(i) local link = GetMerchantItemLink(i)
if ItemSearch:Find(link, GVS.searchstring) then if ItemSearch:Find(link, searchstring) then
if n_searchmatch >= offset and n_searchmatch < offset + NUMROWS then if n_searchmatch >= offset and n_searchmatch < offset + NUMROWS then
rows[row]:SetValue(i) rows[row]:SetValue(i)
row = row + 1 row = row + 1
@ -47,9 +49,7 @@ function ns.NewMainFrame()
for i=row,NUMROWS do rows[i]:Hide() end for i=row,NUMROWS do rows[i]:Hide() end
end end
search:SetScript("OnTextChanged", Refresh)
ns.MakeSearchField(GVS, scrollbar.Refresh)
GVS:EnableMouseWheel(true) GVS:EnableMouseWheel(true)
GVS:SetScript("OnMouseWheel", function(self, value) GVS:SetScript("OnMouseWheel", function(self, value)

View File

@ -2,15 +2,9 @@
local myname, ns = ... local myname, ns = ...
function ns.MakeSearchField(GVS, Refresh) function ns.MakeSearchField(parent)
local editbox = ns.NewTextInput(GVS) local editbox = ns.NewTextInput(parent)
editbox:SetPoint("BOTTOMLEFT", GVS, "TOPLEFT", 55, 9) editbox:SetPoint("BOTTOMLEFT", parent, "TOPLEFT", 55, 9)
editbox:SetScript("OnTextChanged", function(self)
local t = self:GetText()
GVS.searchstring = t ~= "" and t ~= "Search..." and t:lower() or nil
Refresh()
end)
editbox.placeholder:SetText("Search...") editbox.placeholder:SetText("Search...")