annotate ui/ScrollFrame.lua @ 11:ece9167c0d1c v1.2.14.0

Localization support, combat log features (wipe command, aura/pet tracking, and realm detection).
author yellowfive
date Thu, 10 Jul 2014 12:24:59 -0700
parents
children
rev   line source
yellowfive@11 1 local _, AskMrRobot = ...
yellowfive@11 2
yellowfive@11 3 -- initialize the ScrollFrame class (inherit from a dummy frame)
yellowfive@11 4 AskMrRobot.ScrollFrame = AskMrRobot.inheritsFrom(CreateFrame("ScrollFrame"))
yellowfive@11 5
yellowfive@11 6 function AskMrRobot.ScrollFrame:OnMouseWheel(value)
yellowfive@11 7 local currentValue = self.scrollbar:GetValue()
yellowfive@11 8 if value < 0 then
yellowfive@11 9 currentValue = currentValue + 15
yellowfive@11 10 else
yellowfive@11 11 currentValue = currentValue - 15
yellowfive@11 12 end
yellowfive@11 13 self.scrollbar:SetValue(currentValue)
yellowfive@11 14 end
yellowfive@11 15
yellowfive@11 16 function AskMrRobot.ScrollFrame:RecalcScrollbar()
yellowfive@11 17 self.scrollbar:SetMinMaxValues(0, self.content:GetHeight() * 100 / self:GetHeight())
yellowfive@11 18 end
yellowfive@11 19
yellowfive@11 20 function AskMrRobot.ScrollFrame:OnSizeChanged(width, height)
yellowfive@11 21 self.content:SetWidth(width)
yellowfive@11 22 self:RecalcScrollbar()
yellowfive@11 23 end
yellowfive@11 24
yellowfive@11 25 -- ScrollFrame contructor
yellowfive@11 26 function AskMrRobot.ScrollFrame:new(name, parentFrame)
yellowfive@11 27 -- create a new frame (if one isn't supplied)
yellowfive@11 28 local scrollframe = CreateFrame("ScrollFrame", name, parentFrame)
yellowfive@11 29
yellowfive@11 30 -- use the ScrollFrame class
yellowfive@11 31 setmetatable(scrollframe, { __index = AskMrRobot.ScrollFrame })
yellowfive@11 32
yellowfive@11 33 scrollframe:EnableMouseWheel(true)
yellowfive@11 34 scrollframe:SetScript("OnMouseWheel", AskMrRobot.ScrollFrame.OnMouseWheel)
yellowfive@11 35 scrollframe:SetScript("OnSizeChanged", AskMrRobot.ScrollFrame.OnSizeChanged)
yellowfive@11 36
yellowfive@11 37 local scrollbar = CreateFrame("Slider", nil, scrollframe, "UIPanelScrollBarTemplate" )
yellowfive@11 38 scrollbar:SetPoint("TOPLEFT", scrollframe, "TOPRIGHT", 4, -16)
yellowfive@11 39 scrollbar:SetPoint("BOTTOMLEFT", scrollframe, "BOTTOMRIGHT", 4, 16)
yellowfive@11 40 scrollbar:SetMinMaxValues(0, 100)
yellowfive@11 41 scrollbar:SetValueStep(10)
yellowfive@11 42 scrollbar.scrollStep = 10
yellowfive@11 43 scrollbar:SetValue(0)
yellowfive@11 44 scrollbar:SetWidth(16)
yellowfive@11 45 scrollbar:SetScript("OnValueChanged",
yellowfive@11 46 function (self, value)
yellowfive@11 47 self:GetParent():SetVerticalScroll(value)
yellowfive@11 48 end)
yellowfive@11 49 scrollbar:Enable()
yellowfive@11 50 scrollbar:SetOrientation("VERTICAL");
yellowfive@11 51 scrollbar:Show()
yellowfive@11 52 scrollframe.scrollbar = scrollbar
yellowfive@11 53
yellowfive@11 54 --content frame
yellowfive@11 55 local content = AskMrRobot.Frame:new(nil, scrollframe)
yellowfive@11 56 scrollframe.content = content
yellowfive@11 57
yellowfive@11 58 scrollframe:SetScrollChild(content)
yellowfive@11 59
yellowfive@11 60 content:SetScript('OnSizeChanged', function(a, width, height)
yellowfive@11 61 scrollframe:RecalcScrollbar()
yellowfive@11 62 end)
yellowfive@11 63
yellowfive@11 64 -- return the instance of the ScrollFrame
yellowfive@11 65 return scrollframe
yellowfive@11 66 end