Walkerbo

4 Scroll Frames Test

Dec 6th, 2020
808
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local data = {}
  2. local data2={}
  3. local data3={}
  4. local data4={}
  5. local scrollFrame,scrollFrame2,scrollFrame3,scrollFrame4 -- we'll define this later
  6. local numButtons = 15 -- number of lines to scrollFrame
  7. local buttonHeight = 16 -- height of each line
  8.  
  9. -- fill data will test data to scroll through
  10. for i=1,50 do
  11.    tinsert(data,format("||cff00ffff Data Table 1 - #%d",i))
  12.    tinsert(data2,format("||cff00ff00 Data Table 2 - #%d",i))
  13.    tinsert(data3,format("||cffff0000 Data Table 3 - #%d",i))
  14.    tinsert(data4,format("||cffff00ff Data Table 4 - #%d",i))
  15. end
  16.  
  17. -- the heart of the scrollframe that updates each
  18. local function update()
  19.    FauxScrollFrame_Update(scrollFrame,#data,numButtons,buttonHeight)
  20.    for index = 1,numButtons do
  21.       local offset = index + FauxScrollFrame_GetOffset(scrollFrame)
  22.       local button = scrollFrame.buttons[index]
  23.       if offset<=#data then
  24.          button:SetText(data[offset])
  25.          button:Show()
  26.       else
  27.          button:Hide()
  28.       end
  29.    end
  30. end
  31.  
  32. local function update2()
  33.    FauxScrollFrame_Update(scrollFrame2,#data2,numButtons,buttonHeight)
  34.    for index = 1,numButtons do
  35.       local offset = index + FauxScrollFrame_GetOffset(scrollFrame2)
  36.       local button = scrollFrame2.buttons2[index]
  37.       if offset<=#data2 then
  38.          button:SetText(data2[offset])
  39.          button:Show()
  40.       else
  41.          button:Hide()
  42.       end
  43.    end
  44. end
  45.  
  46. local function update3()
  47.    FauxScrollFrame_Update(scrollFrame3,#data3,numButtons,buttonHeight)
  48.    for index = 1,numButtons do
  49.       local offset = index + FauxScrollFrame_GetOffset(scrollFrame3)
  50.       local button = scrollFrame3.buttons3[index]
  51.       if offset<=#data3 then
  52.          button:SetText(data3[offset])
  53.          button:Show()
  54.       else
  55.          button:Hide()
  56.       end
  57.    end
  58. end
  59.  
  60. local function update4()
  61.    FauxScrollFrame_Update(scrollFrame4,#data4,numButtons,buttonHeight)
  62.    for index = 1,numButtons do
  63.       local offset = index + FauxScrollFrame_GetOffset(scrollFrame4)
  64.       local button = scrollFrame4.buttons4[index]
  65.       if offset<=#data4 then
  66.          button:SetText(data4[offset])
  67.          button:Show()
  68.       else
  69.          button:Hide()
  70.       end
  71.    end
  72. end
  73.  
  74.  
  75. --  Create Main Wrapping Frame
  76. --=====================     aaa Main Frame      ======================
  77. local mainWrappingFrame=CreateFrame("Frame","mwf",UIParent, "BackdropTemplate","TooltipBorderedFrameTemplate")
  78. mainWrappingFrame:SetBackdrop({bgFile={}, insets={}, tileSize={}, tile=false, edgeFile="Interface\\Tooltips\\UI-Tooltip-Border", edgeSize=20})
  79. mainWrappingFrame:SetBackdropBorderColor(0,1,1,1)
  80. mainWrappingFrame:SetSize(440,((((numButtons*buttonHeight)+buttonHeight)*2)+60))
  81. mainWrappingFrame:ClearAllPoints()
  82. mainWrappingFrame:SetPoint("LEFT",300,50)
  83. mainWrappingFrame:EnableMouse(true)
  84. mainWrappingFrame:SetMovable(true)
  85. mainWrappingFrame:RegisterForDrag("LeftButton")
  86. mainWrappingFrame:SetScript("OnDragStart",mainWrappingFrame.StartMoving)
  87. mainWrappingFrame:SetScript("OnDragStop",mainWrappingFrame.StopMovingOrSizing)
  88. mainWrappingFrame:SetToplevel(true)
  89.  
  90. -- create parent frame
  91. local scrollFrameParent = CreateFrame("Frame","AVK_SFP",mainWrappingFrame, "BackdropTemplate")
  92. scrollFrameParent:SetSize(196,numButtons*buttonHeight+16)
  93. scrollFrameParent:SetPoint("TOPLEFT",10,-25)
  94. scrollFrameParent:SetBackdrop( { bgFile="Interface\\DialogFrame\\UI-DialogBox-Background", insets={left=4,right=4,top=4,bottom=4}, tileSize=16, tile=true, edgeFile="Interface\\Tooltips\\UI-Tooltip-Border", edgeSize = 16 } )
  95.  
  96. -- create the scrollFrame
  97. scrollFrame = CreateFrame("ScrollFrame","AVK_SF",scrollFrameParent,"FauxScrollFrameTemplate")
  98. scrollFrame:SetPoint("TOPLEFT",0,-8)
  99. scrollFrame:SetPoint("BOTTOMRIGHT",-30,8)
  100. scrollFrame:SetScript("OnVerticalScroll",function(self,offset)
  101.       FauxScrollFrame_OnVerticalScroll(self, offset, 16, update)
  102. end)
  103.  
  104. -- create each line(button) within the scrollFrame
  105. scrollFrame.buttons = {}
  106. for i=1,numButtons do
  107.    scrollFrame.buttons[i] = CreateFrame("Button",nil,scrollFrame)
  108.    local button = scrollFrame.buttons[i]
  109.    button:SetSize(166,buttonHeight)
  110.    button:SetNormalFontObject("GameFontHighlightLeft")
  111.    button:SetPoint("TOPLEFT",8,-(i-1)*buttonHeight)
  112.    button:SetScript("OnClick",function(self)
  113.          print("||cff00ffff Test Print - Data 1 button "..data[i])
  114.    end)
  115. end
  116.  
  117. -- create parent frame 2
  118. local scrollFrameParent2 = CreateFrame("Frame","AVK_SFP2",mainWrappingFrame, "BackdropTemplate")
  119. scrollFrameParent2:SetSize(196,numButtons*buttonHeight+16)
  120. scrollFrameParent2:SetPoint("TOPRIGHT",-10,-25)
  121. scrollFrameParent2:SetBackdrop( { bgFile="Interface\\DialogFrame\\UI-DialogBox-Background", insets={left=4,right=4,top=4,bottom=4}, tileSize=16, tile=true, edgeFile="Interface\\Tooltips\\UI-Tooltip-Border", edgeSize = 16 } )
  122.  
  123. -- create the scrollFrame2
  124. scrollFrame2 = CreateFrame("scrollFrame","AVK_SF2",scrollFrameParent2,"FauxScrollFrameTemplate")
  125. scrollFrame2:SetPoint("TOPLEFT",0,-8)
  126. scrollFrame2:SetPoint("BOTTOMRIGHT",-30,8)
  127. scrollFrame2:SetScript("OnVerticalScroll",function(self,offset)
  128.       FauxScrollFrame_OnVerticalScroll(self, offset, 16, update2)
  129. end)
  130.  
  131. -- create each line(button) within the scrollFrame2
  132. scrollFrame2.buttons2 = {}
  133. for i=1,numButtons do
  134.    scrollFrame2.buttons2[i] = CreateFrame("Button",nil,scrollFrame2)
  135.    local button = scrollFrame2.buttons2[i]
  136.    button:SetSize(166,buttonHeight)
  137.    button:SetNormalFontObject("GameFontHighlightLeft")
  138.    button:SetPoint("TOPLEFT",8,-(i-1)*buttonHeight)
  139.    button:SetScript("OnClick",function(self)
  140.          print("||cff00ff00 Test Print - Data 2 button "..data2[i])
  141.    end)
  142. end
  143.  
  144.  
  145. -- create parent frame 3
  146. local scrollFrameParent3 = CreateFrame("Frame","AVK_SFP3",mainWrappingFrame, "BackdropTemplate")
  147. scrollFrameParent3:SetSize(196,numButtons*buttonHeight+16)
  148. scrollFrameParent3:SetPoint("BOTTOMLEFT",10,10)
  149. scrollFrameParent3:SetBackdrop( { bgFile="Interface\\DialogFrame\\UI-DialogBox-Background", insets={left=4,right=4,top=4,bottom=4}, tileSize=16, tile=true, edgeFile="Interface\\Tooltips\\UI-Tooltip-Border", edgeSize = 16 } )
  150.  
  151. -- create the scrollFrame3
  152. scrollFrame3 = CreateFrame("scrollFrame","AVK_SF3",scrollFrameParent3,"FauxScrollFrameTemplate")
  153. scrollFrame3:SetPoint("TOPLEFT",0,-8)
  154. scrollFrame3:SetPoint("BOTTOMRIGHT",-30,8)
  155. scrollFrame3:SetScript("OnVerticalScroll",function(self,offset)
  156.       FauxScrollFrame_OnVerticalScroll(self, offset, 16, update3)
  157. end)
  158.  
  159. -- create each line(button) within the scrollFrame3
  160. scrollFrame3.buttons3 = {}
  161. for i=1,numButtons do
  162.    scrollFrame3.buttons3[i] = CreateFrame("Button",nil,scrollFrame3)
  163.    local button = scrollFrame3.buttons3[i]
  164.    button:SetSize(166,buttonHeight)
  165.    button:SetNormalFontObject("GameFontHighlightLeft")
  166.    button:SetPoint("TOPLEFT",8,-(i-1)*buttonHeight)
  167.    button:SetScript("OnClick",function(self)
  168.          print("||cffff0000 Test Print - Data 3 button "..data3[i])
  169.    end)
  170. end
  171.  
  172.  
  173. -- create parent frame 4
  174. local scrollFrameParent4 = CreateFrame("Frame","AVK_SFP4",mainWrappingFrame, "BackdropTemplate")
  175. scrollFrameParent4:SetSize(196,numButtons*buttonHeight+16)
  176. scrollFrameParent4:SetPoint("BOTTOMRIGHT",-10,10)
  177. scrollFrameParent4:SetBackdrop( { bgFile="Interface\\DialogFrame\\UI-DialogBox-Background", insets={left=4,right=4,top=4,bottom=4}, tileSize=16, tile=true, edgeFile="Interface\\Tooltips\\UI-Tooltip-Border", edgeSize = 16 } )
  178.  
  179. -- create the scrollFrame4
  180. scrollFrame4 = CreateFrame("scrollFrame","AVK_SF4",scrollFrameParent4,"FauxScrollFrameTemplate")
  181. scrollFrame4:SetPoint("TOPLEFT",0,-8)
  182. scrollFrame4:SetPoint("BOTTOMRIGHT",-30,8)
  183. scrollFrame4:SetScript("OnVerticalScroll",function(self,offset)
  184.       FauxScrollFrame_OnVerticalScroll(self, offset, 16, update4)
  185. end)
  186.  
  187. -- create each line(button) within the scrollFrame4
  188. scrollFrame4.buttons4 = {}
  189. for i=1,numButtons do
  190.    scrollFrame4.buttons4[i] = CreateFrame("Button",nil,scrollFrame4)
  191.    local button = scrollFrame4.buttons4[i]
  192.    button:SetSize(166,buttonHeight)
  193.    button:SetNormalFontObject("GameFontHighlightLeft")
  194.    button:SetPoint("TOPLEFT",8,-(i-1)*buttonHeight)
  195.    button:SetScript("OnClick",function(self)
  196.          print("||cffff00ff Test Print - Data 2 button "..data4[i])
  197.    end)
  198. end
  199.  
  200.  
  201. update() -- always remember to kick off first update, in an OnShow usually
  202. update2()
  203. update3()
  204. update4()
  205.  
  206. SlashCmdList["ADDDATA"] = function(msg)
  207.    tinsert(data,msg) -- add msg to data
  208.    -- update scrollFrame (so bar's max value is adjusted and stuff)
  209.    FauxScrollFrame_Update(scrollFrame,#data,numButtons,buttonHeight)
  210.    -- then scroll to end (may be a better way to do this)
  211.    local scrollBar = _G[scrollFrame:GetName().."ScrollBar"]
  212.    scrollBar:SetValue(select(2,scrollBar:GetMinMaxValues()))
  213. end
  214. SLASH_ADDDATA1 = "/adddata"
RAW Paste Data