yellowfive@11: local _, AskMrRobot = ... yellowfive@11: yellowfive@11: -- initialize the ScrollFrame class (inherit from a dummy frame) yellowfive@11: AskMrRobot.ScrollFrame = AskMrRobot.inheritsFrom(CreateFrame("ScrollFrame")) yellowfive@11: yellowfive@11: function AskMrRobot.ScrollFrame:OnMouseWheel(value) yellowfive@11: local currentValue = self.scrollbar:GetValue() yellowfive@11: if value < 0 then yellowfive@11: currentValue = currentValue + 15 yellowfive@11: else yellowfive@11: currentValue = currentValue - 15 yellowfive@11: end yellowfive@11: self.scrollbar:SetValue(currentValue) yellowfive@11: end yellowfive@11: yellowfive@11: function AskMrRobot.ScrollFrame:RecalcScrollbar() yellowfive@11: self.scrollbar:SetMinMaxValues(0, self.content:GetHeight() * 100 / self:GetHeight()) yellowfive@11: end yellowfive@11: yellowfive@11: function AskMrRobot.ScrollFrame:OnSizeChanged(width, height) yellowfive@11: self.content:SetWidth(width) yellowfive@11: self:RecalcScrollbar() yellowfive@11: end yellowfive@11: yellowfive@11: -- ScrollFrame contructor yellowfive@11: function AskMrRobot.ScrollFrame:new(name, parentFrame) yellowfive@11: -- create a new frame (if one isn't supplied) yellowfive@11: local scrollframe = CreateFrame("ScrollFrame", name, parentFrame) yellowfive@11: yellowfive@11: -- use the ScrollFrame class yellowfive@11: setmetatable(scrollframe, { __index = AskMrRobot.ScrollFrame }) yellowfive@11: yellowfive@11: scrollframe:EnableMouseWheel(true) yellowfive@11: scrollframe:SetScript("OnMouseWheel", AskMrRobot.ScrollFrame.OnMouseWheel) yellowfive@11: scrollframe:SetScript("OnSizeChanged", AskMrRobot.ScrollFrame.OnSizeChanged) yellowfive@11: yellowfive@11: local scrollbar = CreateFrame("Slider", nil, scrollframe, "UIPanelScrollBarTemplate" ) yellowfive@11: scrollbar:SetPoint("TOPLEFT", scrollframe, "TOPRIGHT", 4, -16) yellowfive@11: scrollbar:SetPoint("BOTTOMLEFT", scrollframe, "BOTTOMRIGHT", 4, 16) yellowfive@11: scrollbar:SetMinMaxValues(0, 100) yellowfive@11: scrollbar:SetValueStep(10) yellowfive@11: scrollbar.scrollStep = 10 yellowfive@11: scrollbar:SetValue(0) yellowfive@11: scrollbar:SetWidth(16) yellowfive@11: scrollbar:SetScript("OnValueChanged", yellowfive@11: function (self, value) yellowfive@11: self:GetParent():SetVerticalScroll(value) yellowfive@11: end) yellowfive@11: scrollbar:Enable() yellowfive@11: scrollbar:SetOrientation("VERTICAL"); yellowfive@11: scrollbar:Show() yellowfive@11: scrollframe.scrollbar = scrollbar yellowfive@11: yellowfive@11: --content frame yellowfive@11: local content = AskMrRobot.Frame:new(nil, scrollframe) yellowfive@11: scrollframe.content = content yellowfive@11: yellowfive@11: scrollframe:SetScrollChild(content) yellowfive@11: yellowfive@11: content:SetScript('OnSizeChanged', function(a, width, height) yellowfive@11: scrollframe:RecalcScrollbar() yellowfive@11: end) yellowfive@11: yellowfive@11: -- return the instance of the ScrollFrame yellowfive@11: return scrollframe yellowfive@11: end