WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   AddOn Help/Support (https://www.wowinterface.com/forums/forumdisplay.php?f=3)
-   -   Position frames inside gridPanel (https://www.wowinterface.com/forums/showthread.php?t=57074)

wille480 03-20-19 09:27 AM

Position frames inside gridPanel
 
Hello, so i am trying to make a function that will create a frame and position it inside my grid panel. I have the code to create one frame and position it how i want, but i can't find a way to create a function that will create a frame and position it into the gridpanel below another frame that would have previous been created.

This is how it currently looks:
https://gyazo.com/205ec8741ee64a55ace2fff7a6c21653

I am pleased how it looks so far but now i need to find a way for a function like this that will position frames below eachother but still being inside the orange panel.

My current code:

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. -- SubFrame
  14. local subFrame = CreateFrame("Button", "subFrame", UIParent)
  15. local texture = subFrame:CreateTexture("ARTWORK")
  16. subFrame:SetWidth(300); subFrame:SetHeight(50);
  17. texture:SetAllPoints()
  18. texture:SetColorTexture(1,0,0.1, 1)
  19. local fontString = subFrame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  20. fontString:SetPoint("CENTER")
  21. fontString:SetText("hej")
  22. subFrame:SetPoint("TOP", gridFrame, "TOP", 0,0)

How would i go about this?

Fizzlemizz 03-20-19 10:05 AM

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

wille480 03-20-19 10:29 AM

Quote:

Originally Posted by Fizzlemizz (Post 331740)
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();


All times are GMT -6. The time now is 11:54 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI