Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- FFR: http://forums.wowace.com/showthread.php?t=20057
- local BUTTON_HEIGHT = 16
- MyADDON = {}
- local DataTable = {}
- for i = 1, 100 do
- table.insert(DataTable, "TestNameLong015")
- end
- function MyADDON.MakeFrame(name, width, height)
- local Frame = CreateFrame("Frame", name, UIParent)
- Frame:SetMovable(true)
- Frame:EnableMouse(true)
- Frame:RegisterForDrag("LeftButton")
- Frame:SetScript("OnDragStart", Frame.StartMoving)
- Frame:SetScript("OnDragStop", Frame.StopMovingOrSizing)
- Frame:SetScript("OnHide", Frame.StopMovingOrSizing)
- Frame:SetSize(width, height)
- Frame:SetPoint("CENTER")
- Frame.ButtonCount = math.floor((height-32)/BUTTON_HEIGHT)
- Frame:SetBackdrop({
- bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background", tile = true, tileSize = 16,
- edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", edgeSize = 16,
- insets = { left = 4, right = 4, top = 4, bottom = 4 },
- })
- function Frame:Update()
- local maxValue = #DataTable
- FauxScrollFrame_Update(self.ScrollBar, maxValue, self.ButtonCount, BUTTON_HEIGHT)
- local offset = FauxScrollFrame_GetOffset(self.ScrollBar)
- for Button = 1, self.ButtonCount do
- local value = Button + offset
- if value <= maxValue then
- local Button = self.Buttons[Button]
- Button:SetText(DataTable[value])
- Button:Show()
- else
- self.Buttons[Button]:Hide()
- end
- end
- end
- local ScrollBar = CreateFrame("ScrollFrame", "$parent_ScrollBar", Frame, "FauxScrollFrameTemplate")
- ScrollBar:SetPoint("TOPLEFT", 0, -24) -- -8
- ScrollBar:SetPoint("BOTTOMRIGHT", -30, 8)
- ScrollBar:SetScript("OnVerticalScroll", function(self, offset)
- self.offset = math.floor(offset / BUTTON_HEIGHT + 0.5)
- Frame:Update()
- end)
- ScrollBar:SetScript("OnShow", function()
- Frame:Update()
- end)
- Frame.ScrollBar = ScrollBar
- local Buttons = setmetatable({}, { __index = function(t, i)
- local Button = CreateFrame("Button", "$parent_Button"..i, Frame)
- Button:SetSize(width-55, BUTTON_HEIGHT)
- Button:SetNormalFontObject(GameFontHighlightLeft)
- if i == 1 then
- Button:SetPoint("TOPLEFT", ScrollBar, 8, 0)
- else
- Button:SetPoint("TOPLEFT", Frame.Buttons[i-1], "BOTTOMLEFT")
- end
- rawset(t, i, Button)
- return Button
- end })
- Frame.Buttons = Buttons
- Frame:Update()
- return Frame
- end
- MyADDON.MakeFrame("TestFrame", 265, 280) -- Name, width, height
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement