Originally Posted by Vrul
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:
tab.ItemScrollFrame:SetClipsChildren(true) local numButtons, lastButton = 0 for key, item in pairs(namespace.searchResult) do local buttonName = key .. "Button" local button = CreateFrame("Button", buttonName, tab.ItemScrollFrameChild, "OptionsListButtonTemplate") button:SetSize(192, 10) button:SetHighlightTexture("Interface\\BUTTONS\\UI-Listbox-Highlight2") button:SetText(item.name) if item.slot then button.tooltipText = item.itemType .. ", " .. item.slot else button.tooltipText = item.itemType end button:SetScript("OnEnter", OnEnter) button:SetScript("OnLeave", OnLeave) button:SetScript("OnClick", OnClickItemFrameButton) if lastButton then button:SetPoint("TOPLEFT", lastButton, "BOTTOMLEFT", 0, -1) else button:SetPoint("TOPLEFT", 4, -4) end numButtons, lastButton = numButtons + 1, button tab[buttonName] = button end if lastButton then local width, height = lastButton:GetSize() tab.ItemScrollFrameChild:SetSize(width, numButtons * (height + 1) - 1) 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.