View Single Post
05-20-21, 01:10 PM   #13
Darkonode
A Murloc Raider
 
Darkonode's Avatar
Join Date: May 2021
Posts: 8
Originally Posted by Vrul View Post
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.
the naming was probably just something that carried over from previous code. I needed it to be able to modify the buttons later once i enable search functionality but since im using a table for them anyway and a global name i dnt really need it anymore.

rn im genrally repeating a lot of code cos this is my first lua project and i just write the down the solution that comes to mind and i can implement LOL. how you handled setting size for the later buttons didnt even cross my mind. i will clean it up once i get a bit further.
  Reply With Quote