Advertisement
Rochet2

Faux Scrollbox wow addon interface

Sep 9th, 2012
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.37 KB | None | 0 0
  1. -- FFR: http://forums.wowace.com/showthread.php?t=20057
  2. local BUTTON_HEIGHT = 16
  3. MyADDON = {}
  4.  
  5. local DataTable = {}
  6. for i = 1, 100 do
  7.     table.insert(DataTable, "TestNameLong015")
  8. end
  9.  
  10. function MyADDON.MakeFrame(name, width, height)
  11.     local Frame = CreateFrame("Frame", name, UIParent)
  12.     Frame:SetMovable(true)
  13.     Frame:EnableMouse(true)
  14.     Frame:RegisterForDrag("LeftButton")
  15.     Frame:SetScript("OnDragStart", Frame.StartMoving)
  16.     Frame:SetScript("OnDragStop", Frame.StopMovingOrSizing)
  17.     Frame:SetScript("OnHide", Frame.StopMovingOrSizing)
  18.     Frame:SetSize(width, height)
  19.     Frame:SetPoint("CENTER")
  20.     Frame.ButtonCount = math.floor((height-32)/BUTTON_HEIGHT)
  21.     Frame:SetBackdrop({
  22.         bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background", tile = true, tileSize = 16,
  23.         edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", edgeSize = 16,
  24.         insets = { left = 4, right = 4, top = 4, bottom = 4 },
  25.     })
  26.  
  27.         function Frame:Update()
  28.             local maxValue = #DataTable
  29.             FauxScrollFrame_Update(self.ScrollBar, maxValue, self.ButtonCount, BUTTON_HEIGHT)
  30.             local offset = FauxScrollFrame_GetOffset(self.ScrollBar)
  31.             for Button = 1, self.ButtonCount do
  32.                 local value = Button + offset
  33.                 if value <= maxValue then
  34.                     local Button = self.Buttons[Button]
  35.                     Button:SetText(DataTable[value])
  36.                     Button:Show()
  37.                 else
  38.                     self.Buttons[Button]:Hide()
  39.                 end
  40.             end
  41.         end
  42.        
  43.         local ScrollBar = CreateFrame("ScrollFrame", "$parent_ScrollBar", Frame, "FauxScrollFrameTemplate")
  44.         ScrollBar:SetPoint("TOPLEFT", 0, -24) -- -8
  45.         ScrollBar:SetPoint("BOTTOMRIGHT", -30, 8)
  46.        
  47.         ScrollBar:SetScript("OnVerticalScroll", function(self, offset)
  48.             self.offset = math.floor(offset / BUTTON_HEIGHT + 0.5)
  49.             Frame:Update()
  50.         end)
  51.  
  52.         ScrollBar:SetScript("OnShow", function()
  53.             Frame:Update()
  54.         end)
  55.  
  56.         Frame.ScrollBar = ScrollBar
  57.        
  58.         local Buttons = setmetatable({}, { __index = function(t, i)
  59.             local Button = CreateFrame("Button", "$parent_Button"..i, Frame)
  60.             Button:SetSize(width-55, BUTTON_HEIGHT)
  61.             Button:SetNormalFontObject(GameFontHighlightLeft)
  62.             if i == 1 then
  63.                 Button:SetPoint("TOPLEFT", ScrollBar, 8, 0)
  64.             else
  65.                 Button:SetPoint("TOPLEFT", Frame.Buttons[i-1], "BOTTOMLEFT")
  66.             end
  67.             rawset(t, i, Button)
  68.             return Button
  69.         end })
  70.  
  71.         Frame.Buttons = Buttons
  72.         Frame:Update()
  73.     return Frame
  74. end
  75.  
  76. MyADDON.MakeFrame("TestFrame", 265, 280) -- Name, width, height
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement