View Single Post
07-09-13, 04:53 AM   #13
Yksrep
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 21
Thanks for all your help.

Im making Progress, been able to add more button and create them into columns. Also able to display tabels from another .lua in the same scrollframe which is the aim of what I wanted to get done when I first make this thread. In my research I found this site http://www.wowwiki.com/API_CreateFrame it mentions un parenting frames when they are hidden to avoid the maximum framelevel. I have used
Code:
	{
		text = "Button A",
		click = function(self, mouseButton)
			print("You clicked Button A!")
			MyParentFrame:Hide()
			MyParentFrame:SetParent(nil)
			MyParentFrame2:Show()
			MyParentFrame2:SetPoint("TOPLEFT", content, 0, 0)
			
		end,
	},
As mentioned to avoid the max framelevel.

TabelTest.lua
Code:
--parent frame 
local frame = CreateFrame("Frame", "MyFrame", UIParent) 
frame:SetSize(410, 300) 
frame:SetPoint("CENTER") 
local texture = frame:CreateTexture() 
texture:SetAllPoints() 
texture:SetTexture(0,0,0,0) 
frame.background = texture 

--scrollframe 
scrollframe = CreateFrame("ScrollFrame", "scrollframe", frame) 
scrollframe:SetPoint("TOPLEFT", 10, -10) 
scrollframe:SetPoint("BOTTOMRIGHT", -10, 10) 
local texture = scrollframe:CreateTexture() 
texture:SetAllPoints() 
texture:SetTexture(0,0,0,0) 
frame.scrollframe = scrollframe 

--scrollbar 
scrollbar = CreateFrame("Slider", nil, scrollframe, "UIPanelScrollBarTemplate") 
scrollbar:SetPoint("TOPLEFT", frame, "TOPRIGHT", 4, -16) 
scrollbar:SetPoint("BOTTOMLEFT", frame, "BOTTOMRIGHT", 4, 16) 
scrollbar:SetMinMaxValues(1, 20) --How Far the Bar Goes Down and Moves the Frame
scrollbar:SetValueStep(1) 
scrollbar.scrollStep = 1 
scrollbar:SetValue(0) 
scrollbar:SetWidth(16) 
scrollbar:SetScript("OnValueChanged", 
function (self, value) 
self:GetParent():SetVerticalScroll(value) 
end) 
local scrollbg = scrollbar:CreateTexture(nil, "BACKGROUND") 
scrollbg:SetAllPoints(scrollbar) 
scrollbg:SetTexture(0, 0, 0, 0.4) 
frame.scrollbar = scrollbar 

--content frame 
local content = CreateFrame("Frame", nil, scrollframe)
content:SetPoint("TOP", scrollframe) 
content:SetSize(500, 300) 
local texture = content:CreateTexture() 
--texture:SetAllPoints() 
--texture:SetTexture("Interface\\GLUES\\MainMenu\\Glues-BlizzardLogo") 
--content.texture = texture 
scrollframe.content = content 

scrollframe:SetScrollChild(content)


-- Table describing the buttons you want to create:
local buttonData = {
	{
		text = "Button A",
		click = function(self, mouseButton)
			print("You clicked Button A!")
			MyParentFrame:Hide()
			MyParentFrame:SetParent(nil)
			MyParentFrame2:Show()
			MyParentFrame2:SetPoint("TOPLEFT", content, 0, 0)
			
		end,
	},
	{
		text = "Button B",
		click = function(self, mouseButton)
			print("You clicked Button B!")
		end,
	},
	{
		text = "Button C",
		click = function(self, mouseButton)
			print("You clicked Button C!")
		end,
	},
	{
		text = "Button D",
		click = function(self, mouseButton)
			print("You clicked Button B!")
		end,
	},
	{
		text = "Button E",
		click = function(self, mouseButton)
			print("You clicked Button B!")
		end,
	},
		{
		text = "Button F",
		click = function(self, mouseButton)
			print("You clicked Button B!")
		end,
	},
	{
		text = "Button G",
		click = function(self, mouseButton)
			print("You clicked Button B!")
		end,
	},
	{
		text = "Button H",
		click = function(self, mouseButton)
			print("You clicked Button B!")
		end,
	},
}

-- Table to hold the actual button objects:
local buttons = {}

-- Create the container frame:
local frame = CreateFrame("Frame", "MyParentFrame")
frame:SetPoint("TOPLEFT", content, 0, 0)
frame:SetSize(200, 20)

-- Give it a background:
local backdrop = frame:CreateTexture(nil, "BACKDROP")
backdrop:SetAllPoints(true)
backdrop:SetTexture(0, 0, 0, 0.5)

-- Loop over the data list:
for i = 1, 4 do -- For all button data use for i = 1, #buttonData do
	-- For each entry, create a button:
	local button = CreateFrame("Button", "MyButton"..i, frame, "UIPanelButtonTemplate")
	button:SetWidth(200)

	-- Add the button to the table:
	buttons[i] = button

	-- Attach the data for later reference:
	button.data = buttonData[i]

	-- Set the button's text based on the data:
	button:SetText(button.data.text)
	-- Set the OnClick script based on the data:
	button:SetScript("OnClick", button.data.click)

	-- If this is the first button...
	if i == 1 then
		-- ...anchor the button to the container:
		button:SetPoint("TOP", frame, "BOTTOM", 0, 20)
	else
		-- ...otherwise, anchor it to the previous button:
		button:SetPoint("TOP", buttons[i-1], "BOTTOM", 0, -5)
	end
end

-- Loop over the data list:
for i = 5, 8 do -- For all button data use for i = 1, #buttonData do
	-- For each entry, create a button:
	local button = CreateFrame("Button", "MyButton"..i, frame, "UIPanelButtonTemplate")
	button:SetWidth(200)

	-- Add the button to the table:
	buttons[i] = button

	-- Attach the data for later reference:
	button.data = buttonData[i]

	-- Set the button's text based on the data:
	button:SetText(button.data.text)
	-- Set the OnClick script based on the data:
	button:SetScript("OnClick", button.data.click)

	-- If this is the first button...
	if i == 5 then
		-- ...anchor the button to the container:
		button:SetPoint("TOPLEFT", frame, "BOTTOM", 100, 20)
	else
		-- ...otherwise, anchor it to the previous button:
		button:SetPoint("TOP", buttons[i-1], "BOTTOM", 0, -5)
	end
end


-- Now your "buttons" table looks like this:
-- buttons = {
-- 	[1] = <button object named "MyButton1">,
-- 	[2] = <button object named "MyButton2">,
-- }
TabelTest2.lua
Code:
-- Table describing the buttons you want to create:
local buttonData = {
	{
		text = "Button AA",
		click = function(self, mouseButton)
			print("You clicked Button AA!")
			MyParentFrame2:Hide();
			MyParentFrame2:SetParent(nil)
			MyParentFrame:Show();

		end,
	},
	{
		text = "Button BB",
		click = function(self, mouseButton)
			print("You clicked Button BB!")
		end,
	},
	{
		text = "Button CC",
		click = function(self, mouseButton)
			print("You clicked Button CC!")
		end,
	},
	{
		text = "Button DD",
		click = function(self, mouseButton)
			print("You clicked Button DD!")
		end,
	},
	{
		text = "Button EE",
		click = function(self, mouseButton)
			print("You clicked Button EE!")
		end,
	},
		{
		text = "Button FF",
		click = function(self, mouseButton)
			print("You clicked Button FF!")
		end,
	},
	{
		text = "Button GG",
		click = function(self, mouseButton)
			print("You clicked Button GG!")
		end,
	},
	{
		text = "Button HH",
		click = function(self, mouseButton)
			print("You clicked Button HH!")
		end,
	},
}

-- Table to hold the actual button objects:
local buttons = {}

-- Create the container frame:
local frame = CreateFrame("Frame", "MyParentFrame2", UIParent)
frame:Hide()
frame:SetPoint("TOP", UIParent, 0, -300)
frame:SetSize(200, 20)

-- Give it a background:
local backdrop = frame:CreateTexture(nil, "BACKDROP")
backdrop:SetAllPoints(true)
backdrop:SetTexture(0, 0, 0, 0)

-- Loop over the data list:
for i = 1, 4 do -- For all button data use for i = 1, #buttonData do
	-- For each entry, create a button:
	local button = CreateFrame("Button", "MyButton"..i, frame, "UIPanelButtonTemplate")
	button:SetWidth(200)

	-- Add the button to the table:
	buttons[i] = button

	-- Attach the data for later reference:
	button.data = buttonData[i]

	-- Set the button's text based on the data:
	button:SetText(button.data.text)
	-- Set the OnClick script based on the data:
	button:SetScript("OnClick", button.data.click)

	-- If this is the first button...
	if i == 1 then
		-- ...anchor the button to the container:
		button:SetPoint("TOP", frame, "BOTTOM", 0, 20)
	else
		-- ...otherwise, anchor it to the previous button:
		button:SetPoint("TOP", buttons[i-1], "BOTTOM", 0, -5)
	end
end

-- Loop over the data list:
for i = 5, 8 do -- For all button data use for i = 1, #buttonData do
	-- For each entry, create a button:
	local button = CreateFrame("Button", "MyButton"..i, frame, "UIPanelButtonTemplate")
	button:SetWidth(200)

	-- Add the button to the table:
	buttons[i] = button

	-- Attach the data for later reference:
	button.data = buttonData[i]

	-- Set the button's text based on the data:
	button:SetText(button.data.text)
	-- Set the OnClick script based on the data:
	button:SetScript("OnClick", button.data.click)

	-- If this is the first button...
	if i == 5 then
		-- ...anchor the button to the container:
		button:SetPoint("TOPLEFT", frame, "BOTTOM", 100, 20)
	else
		-- ...otherwise, anchor it to the previous button:
		button:SetPoint("TOP", buttons[i-1], "BOTTOM", 0, -5)
	end
end


-- Now your "buttons" table looks like this:
-- buttons = {
-- 	[1] = <button object named "MyButton1">,
-- 	[2] = <button object named "MyButton2">,
-- }

function MyButton1_OnClick()
print("test")
end
  Reply With Quote