View Single Post
03-20-19, 10:29 AM   #3
wille480
A Wyrmkin Dreamwalker
Join Date: Jan 2017
Posts: 56
Originally Posted by Fizzlemizz View Post
One fairly basic approach depending on knowing the total number of buttons ahead of time and the gridFrame size being absolute.

Lua Code:
  1. local gridFrame = CreateFrame("Frame", "DragFrame2", UIParent)
  2. gridFrame:SetMovable(true)
  3. gridFrame:EnableMouse(true)
  4. gridFrame:RegisterForDrag("LeftButton")
  5. gridFrame:SetScript("OnDragStart", gridFrame.StartMoving)
  6. gridFrame:SetScript("OnDragStop", gridFrame.StopMovingOrSizing)
  7. -- The code below makes the frame visible, and is not necessary to enable dragging.
  8. gridFrame:SetPoint("CENTER"); gridFrame:SetWidth(300); gridFrame:SetHeight(300);
  9. local gridFrameTexture = gridFrame:CreateTexture("ARTWORK");
  10. gridFrameTexture:SetAllPoints();
  11. gridFrameTexture:SetColorTexture(0.89,0.44,0.1, 0.5)
  12.  
  13. local last = gridFrame
  14. local count = 8
  15. local height = gridFrame:GetHeight()/count
  16. local point = "TOPLEFT"
  17. -- SubFrame
  18. for i=1, count do
  19.     local subFrame = CreateFrame("Button", "subFrame"..i, gridFrame)
  20.     subFrame:SetSize(300, height);
  21.     subFrame:SetHighlightTexture(136477)
  22.     subFrame:SetPoint("TOPLEFT", last, point)
  23.     last = subFrame
  24.     if i == 1 then
  25.         point = "BOTTOMLEFT"
  26.     end
  27.     local texture = subFrame:CreateTexture("ARTWORK")
  28.     texture:SetAllPoints()
  29.     texture:SetColorTexture(1,0,0.1, 1)
  30.     local fontString = subFrame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  31.     fontString:SetPoint("CENTER")
  32.     fontString:SetText("hej")
  33. end

Ah okay! I do not know the amount of frames created ahead of time sadly. I posted a question about this before but all my work got deleted and i have to start all over..

I did this for now and seems to be working

Lua Code:
  1. function CreateSubFrame(window, player)
  2.     local aidsFrame = CreateFrame("Button", "subFrame", UIParent, "SecureHandlerClickTemplate")
  3.     aidsFrame:SetWidth(300)
  4.     aidsFrame:SetHeight(50)
  5.  
  6.     local count = 0
  7.     for elements in pairs(window) do
  8.         count = count + 1
  9.     end
  10.    
  11.     aidsFrame:SetPoint("TOP", mainWindow, 0, count * -50)
  12.     local aidsTexture = aidsFrame:CreateTexture("ARTWORK")
  13.     aidsTexture:SetAllPoints()
  14.     aidsTexture:SetColorTexture(1.0, 0, 0, 1)
  15.    
  16.     return aidsFrame
  17. end
  18.  
  19. mainWindow = CreateFrame("Frame", "wille480DragFrame", gridFrame)
  20. mainWindow:SetSize(300, 300)
  21. mainWindow:SetPoint("TOP")
  22. mainWindow.SubFrames = {}
  23. mainWindowTexture = mainWindow:CreateTexture("ARTWORK")
  24. mainWindowTexture:SetAllPoints();
  Reply With Quote