view ui/ScrollFrame.lua @ 51:6f1bb8fcf64d v18

AskMrRobot.toc - Added line for new SettingsTab file AskMrRobotUi.lua - Added code for new Settings menu amr-constants.lua - Added instance IDs for all WoD 6.0 5-mans and Raids. - Removed legacy SoO IDs. config.lua - Removed "Interface/Addons" options area, migrated all settings to main addon window. localization/localization.en.lua - Added new strings for new Settings tab and new Raid auto-logging ui/CombatLogTab.lua - Removed legacy SoO code - Added auto-logging settings for Highmaul and Blackrock Foundry. ui/SettingsTab.lua - new main window tab for Minimap and Auction House settings options
author TuhMuffinMan <TuhMuffinMan>
date Fri, 28 Nov 2014 13:09:52 -0600
parents ece9167c0d1c
children
line wrap: on
line source
local _, AskMrRobot = ...

-- initialize the ScrollFrame class (inherit from a dummy frame)
AskMrRobot.ScrollFrame = AskMrRobot.inheritsFrom(CreateFrame("ScrollFrame"))

function AskMrRobot.ScrollFrame:OnMouseWheel(value)
	local currentValue = self.scrollbar:GetValue()
	if value < 0 then
		currentValue = currentValue + 15
	else
		currentValue = currentValue - 15
	end
	self.scrollbar:SetValue(currentValue)
end

function AskMrRobot.ScrollFrame:RecalcScrollbar()
	self.scrollbar:SetMinMaxValues(0, self.content:GetHeight() * 100 / self:GetHeight())
end

function AskMrRobot.ScrollFrame:OnSizeChanged(width, height)
	self.content:SetWidth(width)
	self:RecalcScrollbar()
end

-- ScrollFrame contructor
function AskMrRobot.ScrollFrame:new(name, parentFrame)
	-- create a new frame (if one isn't supplied)
	local scrollframe = CreateFrame("ScrollFrame", name, parentFrame)

	-- use the ScrollFrame class
	setmetatable(scrollframe, { __index = AskMrRobot.ScrollFrame })

	scrollframe:EnableMouseWheel(true)
	scrollframe:SetScript("OnMouseWheel", AskMrRobot.ScrollFrame.OnMouseWheel)
	scrollframe:SetScript("OnSizeChanged", AskMrRobot.ScrollFrame.OnSizeChanged)

	local scrollbar = CreateFrame("Slider", nil, scrollframe, "UIPanelScrollBarTemplate" )
	scrollbar:SetPoint("TOPLEFT", scrollframe, "TOPRIGHT", 4, -16) 
	scrollbar:SetPoint("BOTTOMLEFT", scrollframe, "BOTTOMRIGHT", 4, 16)
	scrollbar:SetMinMaxValues(0, 100) 
	scrollbar:SetValueStep(10)
	scrollbar.scrollStep = 10
	scrollbar:SetValue(0) 
	scrollbar:SetWidth(16) 
	scrollbar:SetScript("OnValueChanged", 
	function (self, value) 
		self:GetParent():SetVerticalScroll(value)
	end)
	scrollbar:Enable()
	scrollbar:SetOrientation("VERTICAL");
	scrollbar:Show()
	scrollframe.scrollbar = scrollbar	

	--content frame 
	local content = AskMrRobot.Frame:new(nil, scrollframe)
	scrollframe.content = content

	scrollframe:SetScrollChild(content)

	content:SetScript('OnSizeChanged', function(a, width, height)
		scrollframe:RecalcScrollbar()
	end)

	-- return the instance of the ScrollFrame
	return scrollframe
end