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 ]]--
function ItemSearch:Find(itemLink, search)
if not search then
if not search or search == "" then
return true
end

View File

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

View File

@ -2,15 +2,9 @@
local myname, ns = ...
function ns.MakeSearchField(GVS, Refresh)
local editbox = ns.NewTextInput(GVS)
editbox:SetPoint("BOTTOMLEFT", GVS, "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)
function ns.MakeSearchField(parent)
local editbox = ns.NewTextInput(parent)
editbox:SetPoint("BOTTOMLEFT", parent, "TOPLEFT", 55, 9)
editbox.placeholder:SetText("Search...")