Mercurial > wow > askmrrobot
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 10:ef8b45e96b08 | 11:ece9167c0d1c |
|---|---|
| 1 local _, AskMrRobot = ... | |
| 2 | |
| 3 -- initialize the ScrollFrame class (inherit from a dummy frame) | |
| 4 AskMrRobot.ScrollFrame = AskMrRobot.inheritsFrom(CreateFrame("ScrollFrame")) | |
| 5 | |
| 6 function AskMrRobot.ScrollFrame:OnMouseWheel(value) | |
| 7 local currentValue = self.scrollbar:GetValue() | |
| 8 if value < 0 then | |
| 9 currentValue = currentValue + 15 | |
| 10 else | |
| 11 currentValue = currentValue - 15 | |
| 12 end | |
| 13 self.scrollbar:SetValue(currentValue) | |
| 14 end | |
| 15 | |
| 16 function AskMrRobot.ScrollFrame:RecalcScrollbar() | |
| 17 self.scrollbar:SetMinMaxValues(0, self.content:GetHeight() * 100 / self:GetHeight()) | |
| 18 end | |
| 19 | |
| 20 function AskMrRobot.ScrollFrame:OnSizeChanged(width, height) | |
| 21 self.content:SetWidth(width) | |
| 22 self:RecalcScrollbar() | |
| 23 end | |
| 24 | |
| 25 -- ScrollFrame contructor | |
| 26 function AskMrRobot.ScrollFrame:new(name, parentFrame) | |
| 27 -- create a new frame (if one isn't supplied) | |
| 28 local scrollframe = CreateFrame("ScrollFrame", name, parentFrame) | |
| 29 | |
| 30 -- use the ScrollFrame class | |
| 31 setmetatable(scrollframe, { __index = AskMrRobot.ScrollFrame }) | |
| 32 | |
| 33 scrollframe:EnableMouseWheel(true) | |
| 34 scrollframe:SetScript("OnMouseWheel", AskMrRobot.ScrollFrame.OnMouseWheel) | |
| 35 scrollframe:SetScript("OnSizeChanged", AskMrRobot.ScrollFrame.OnSizeChanged) | |
| 36 | |
| 37 local scrollbar = CreateFrame("Slider", nil, scrollframe, "UIPanelScrollBarTemplate" ) | |
| 38 scrollbar:SetPoint("TOPLEFT", scrollframe, "TOPRIGHT", 4, -16) | |
| 39 scrollbar:SetPoint("BOTTOMLEFT", scrollframe, "BOTTOMRIGHT", 4, 16) | |
| 40 scrollbar:SetMinMaxValues(0, 100) | |
| 41 scrollbar:SetValueStep(10) | |
| 42 scrollbar.scrollStep = 10 | |
| 43 scrollbar:SetValue(0) | |
| 44 scrollbar:SetWidth(16) | |
| 45 scrollbar:SetScript("OnValueChanged", | |
| 46 function (self, value) | |
| 47 self:GetParent():SetVerticalScroll(value) | |
| 48 end) | |
| 49 scrollbar:Enable() | |
| 50 scrollbar:SetOrientation("VERTICAL"); | |
| 51 scrollbar:Show() | |
| 52 scrollframe.scrollbar = scrollbar | |
| 53 | |
| 54 --content frame | |
| 55 local content = AskMrRobot.Frame:new(nil, scrollframe) | |
| 56 scrollframe.content = content | |
| 57 | |
| 58 scrollframe:SetScrollChild(content) | |
| 59 | |
| 60 content:SetScript('OnSizeChanged', function(a, width, height) | |
| 61 scrollframe:RecalcScrollbar() | |
| 62 end) | |
| 63 | |
| 64 -- return the instance of the ScrollFrame | |
| 65 return scrollframe | |
| 66 end |
