View Single Post
05-20-21, 08:44 AM   #12
Vrul
A Scalebane Royal Guard
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 404
In addition to what jeruku said, you aren't parenting the entries to the scroll child to begin with. You are also repeating a lot of code when it could be avoided:
Lua Code:
  1. tab.ItemScrollFrame:SetClipsChildren(true)
  2.  
  3. local numButtons, lastButton = 0
  4. for key, item in pairs(namespace.searchResult) do
  5.     local buttonName = key .. "Button"
  6.     local button = CreateFrame("Button", buttonName, tab.ItemScrollFrameChild, "OptionsListButtonTemplate")
  7.     button:SetSize(192, 10)
  8.     button:SetHighlightTexture("Interface\\BUTTONS\\UI-Listbox-Highlight2")
  9.     button:SetText(item.name)
  10.     if item.slot then
  11.         button.tooltipText = item.itemType .. ", " .. item.slot
  12.     else
  13.         button.tooltipText = item.itemType
  14.     end
  15.     button:SetScript("OnEnter", OnEnter)
  16.     button:SetScript("OnLeave", OnLeave)
  17.     button:SetScript("OnClick", OnClickItemFrameButton)
  18.     if lastButton then
  19.         button:SetPoint("TOPLEFT", lastButton, "BOTTOMLEFT", 0, -1)
  20.     else
  21.         button:SetPoint("TOPLEFT", 4, -4)
  22.     end
  23.     numButtons, lastButton = numButtons + 1, button
  24.     tab[buttonName] = button
  25. end
  26.  
  27. if lastButton then
  28.     local width, height = lastButton:GetSize()
  29.     tab.ItemScrollFrameChild:SetSize(width, numButtons * (height + 1) - 1)
  30. end
I'm unsure what you are trying to accomplish with the "tab.buttonName" stuff unless you meant "tab[buttonName]" so that's what I changed it to, remove it if you aren't actually using it elsewhere.
  Reply With Quote