local frame_main = CreateFrame("Frame","MainFrame",UIParent)
frame_main:SetSize(5, 5)
frame_main:SetPoint("TOP", -150, 0)
frame_main.body = CreateFrame("Frame","FrameBody",frame_main,"BackdropTemplate")
frame_main.body:SetSize(670,352)
frame_main.body:SetPoint("TOPLEFT",frame_main,"TOPLEFT",15,-60)
frame_main.body:SetBackdrop(BACKDROP_DARK_DIALOG_32_32)
frame_main.body:SetFrameStrata("MEDIUM")
frame_main.body:EnableMouse(true)
frame_main.body.ScrollBox = CreateFrame("Frame", "FrameBodyScrollBox", frame_main.body, "WowScrollBoxList")
frame_main.body.ScrollBox:SetPoint("TOPLEFT", frame_main.body, "TOPLEFT",4,-5)
frame_main.body.ScrollBox:SetPoint("BOTTOMRIGHT", frame_main.body, "BOTTOMRIGHT",-4,0)
frame_main.body.ScrollBar = CreateFrame("EventFrame", "FrameBodyScrollBar", frame_main.body, "MinimalScrollBar")
frame_main.body.ScrollBar:SetPoint("TOPLEFT", frame_main.body, "TOPRIGHT",-24,-15)
frame_main.body.ScrollBar:SetPoint("BOTTOMLEFT", frame_main.body, "BOTTOMRIGHT",0,11)
frame_main.body.ScrollView = CreateScrollBoxListLinearView(7,7,7,7,0)
frame_main.body.ScrollView:SetElementExtent(30)
frame_main.body.ScrollView.builder = function(button,data)
button.id = "FrameItem"..data.info.buttonID
button:SetWidth(656)
button:RegisterForClicks( "LeftButtonUp" )
button:SetScript("OnClick",function(self,button,down)
-- Do things...
end)
button.info = CreateFrame("Frame",button.id.."Info",button)
button.info:SetAllPoints(button)
if (data.info.buttonID == 1) then
button:SetPoint("TOPLEFT",frame_main.body:GetName(),"TOPLEFT",11,-11)
else
button:SetPoint("TOP","FrameItem"..(data.info.buttonID-1).."Info","BOTTOM")
end
if (data.info.buttonID % 2 ~= 0) then
button.texture = button.info:CreateTexture(button.id.."Texture")
button.texture:SetAllPoints()
button.texture:SetColorTexture(0.2,0.2,0.2,0.5)
end
button:SetHighlightTexture("Interface\\QuestFrame\\UI-QuestTitleHighlight")
button.name = button.info:CreateFontString(button.info:GetName().."Name")
button.name:SetSize(200,12)
button.name:SetFont("Fonts\\FRIZQT__.TTF", 10)
button.name:SetPoint("TOPLEFT",button.info,"TOPLEFT",10,-2)
button.name:SetJustifyH("LEFT")
button.name:SetText(data.info.name)
button.time = button.info:CreateFontString(button.info:GetName().."Time")
button.time:SetSize(200,12)
button.time:SetFont("Fonts\\FRIZQT__.TTF", 10)
button.time:SetPoint("TOPLEFT",button.name,"BOTTOMLEFT",0,0)
button.time:SetJustifyH("LEFT")
button.time:SetText(data.info.time)
end
ScrollUtil.InitScrollBoxListWithScrollBar(frame_main.body.ScrollBox, frame_main.body.ScrollBar, frame_main.body.ScrollView)
frame_main.body.ScrollView:SetElementFactory(function(factory,data)
factory("Button", function(button,data)
frame_main.body.ScrollView.builder(button,data)
end)
end)
frame_main.body.Data = CreateDataProvider() -- create/set the data providoer once
frame_main.body.ScrollBox:SetDataProvider(frame_main.body.Data)
local NameDetails = {} -- dummy data
for i=1, 5 do
tinsert(NameDetails, { "Name"..i, GetTime()})
end
local function AppendName(index) -- function to add new lines
local name, time = unpack( NameDetails[index] );
local newData = {
info = {
name = name,
time = date( "%Y-%m-%d %H:%M:%S", time ),
buttonID = index
}
}
frame_main.body.Data:Insert(newData)
end
--Initialise the scrollbox
local ET_CurrentIndex = #NameDetails
for index=1, ET_CurrentIndex do
AppendName(index)
end
frame_main.body.ScrollBox:ScrollToBegin(ScrollBoxConstants.NoScrollInterpolation)
-- dummy slashcommand to add random extra entries
SLASH_TESTMENU1 = "/tst"
SlashCmdList.TESTMENU = function(msg)
local total = #NameDetails
local add = random(1, 4)
for i=1, add do -- add entries to the "source" table for realism
tinsert(NameDetails, { "Name"..total+i, GetTime()})
end
for i= ET_CurrentIndex+1, #NameDetails do -- insert added entries into the data provider
AppendName(i)
end
ET_CurrentIndex = #NameDetails
frame_main.body.ScrollBox:ScrollToEnd(ScrollBoxConstants.NoScrollInterpolation)
end