Thread Tools Display Modes
05-27-09, 02:07 AM   #1
Tymesink
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Mar 2005
Posts: 22
Scroll Frames...*Sigh*

I've been reading forums and looking at code from other authors for the last couple evenings trying to wrap my brain around this.

I've look at code that uses "FauxScrollFrameTemplate" but from what I read it maybe over kill for what I need.

So I found this thread:
http://www.wowinterface.com/forums/s...ad.php?t=17814

which Mera gave a really good example.

Since I've been search for examples of how to populate the scrollframe with data. Where each line item was a button with 3 columns that fired off other methods on left and right button click.

I would like to stay with creating the scrollframe using lua script and not xml.

Help?!?
  Reply With Quote
05-27-09, 05:56 AM   #2
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
You just need to have some child buttons inside your scroll buttons.

TBH I think that this is the one situation where there's really no tenable argument against using a little XML, since you can't create templates in Lua. However, if you really wanted to you could create a function that created a frame and then three child buttons for you and just call that each time. For example, my addon GOM has a scrollframe with unclickable player names, which each have a checkbox to the left of them. It would be pretty easy to expand this template to have three buttons instead of the checkbox and/or convert this to a Lua function instead of an XML virtual button:

Code:
	<Button name="GOMaticScrollFrameCheckButtonTemplate" virtual="true">

		<Size>

			<AbsDimension x="200" y="16"/>

		</Size>

		<Frames>

			<Frame name="$parentData" setAllPoints="true">

				<Layers>

					<Layer level="BORDER">

						<FontString name="$parentLabel" inherits="GameFontNormal">

							<Anchor point="TOPLEFT">

								<AbsDimension x="5" y="-2"/>

							</Anchor>

						</FontString>

					</Layer>

				</Layers>

			</Frame>

			<CheckButton name="$parentCheck" inherits="OptionsCheckButtonTemplate">

				<Size>

					<AbsDimension x="25" y="25"/>

				</Size>

				<Anchors>

					<Anchor point="TOPLEFT" relativePoint="TOPLEFT" relativeTo="$parentData">

						<Offset>

							<AbsDimension x="0" y="2"/>

						</Offset>

					</Anchor>

				</Anchors>

				<Scripts>

					<OnClick>

						GrOM.AddOrRemoveSync(self)

					</OnClick>

				</Scripts>

			</CheckButton>

		</Frames>

	</Button>
(BTW it was originally going to have two clickable players per line, hence the weird button-for-text thing...)

Last edited by Akryn : 05-27-09 at 06:05 AM.
  Reply With Quote
05-28-09, 01:17 AM   #3
Tymesink
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Mar 2005
Posts: 22
Ok I got some where but I'm still getting an error..

Code:
local function scrollUpdate()
	local list = db.events;
	local line, lineplusoffset;
	FauxScrollFrame_Update(frames.scroll,50,#list,20)
	
	for line = 1, #list do
		lineplusoffset = line + FauxScrollFrame_GetOffset(frames.scroll)
		if lineplusoffset < 50 then
			_G[MODNAME.."ScrollButton"..line]:SetText(list[lineplusoffset].set)
			_G[MODNAME.."ScrollButton"..line]:Show()
		else
			_G[MODNAME.."ScrollButton"..line]:Hide()
		end
	end
end
 
function addon:CreateScrollFrame()
	frames.scroll = CreateFrame("ScrollFrame", MODNAME.."ScrollFrame", UIParent, "FauxScrollFrameTemplate");
	frames.scroll:SetWidth(118)
	frames.scroll:SetHeight(180)
	frames.scroll:SetPoint("CENTER", "UIParent", "CENTER", 0, 0)
	frames.scroll:SetBackdrop({
		bgFile="",
		edgeFile="Interface\\Tooltips\\UI-Tooltip-Border",
		tile="true",
		tileSize= 32,
		edgeSize=10,
		insets = {left=5, right=5, top=5, bottom=5}
	})
	frames.scroll:SetBackdropBorderColor(0,.5,0,1)
	frames.scroll:SetScript("OnVerticalScroll", function(self, offset) FauxScrollFrame_OnVerticalScroll(self, offset, 20, scrollUpdate) end)
	frames.scroll:SetScript("OnShow", scrollUpdate);
	
	for i = 1,#db.events do
		local b
		if i == 1 then
			b = CreateFrame("Button", MODNAME.."ScrollButton"..i, frames.scroll)
			b:SetPoint("TOPLEFT", 2,-5)
			b:SetText("Button 1")
		else
			b = CreateFrame("Button", MODNAME.."ScrollButton"..i, _G[MODNAME.."ScrollButton"..(i-1)])
			b:SetPoint("TOPLEFT", _G[MODNAME.."ScrollButton"..(i-1)], "BOTTOMLEFT", 0, 4)
			b:SetText("Button "..i)
		end
		
		b:SetNormalFontObject("GameFontNormalSmall")
		b:RegisterForClicks("LeftButtonUp")
		b:SetWidth(114)
		b:SetHeight(20)
			b:SetBackdrop({
			bgFile = "Interface\\CHATFRAME\\CHATFRAMEBACKGROUND",
			edgeFile = "",
			tile = "true",
			tileSize = 32,
			edgeSize = 10,
			insets = {left = 3, right = 3, top = 3, bottom = 3}
			})
		b:SetBackdropColor(1,1,1,1)
		b:SetScript("OnClick", 
			function() 
				self:Print("Button Onclick!"); 
			end
		)
	end
end
The error I'm getting is:
core.lua:242: attempt to index field '?' (a nil value)
Line 242 is _G[MODNAME.."ScrollButton"..line]:SetText(list[lineplusoffset].set)

Which probably means that its trying to get data from an index in an array that doesn't exist. And this only occurs when I'm scrolling the verticale scroll bar.

My Data set looks like this:
Code:
         ["events"] = {
				{
					["set"] = "DPS",
					["event"] = "PVP",
					["talent"] = "Primary",
				}, -- [1]
				{
					["set"] = "Lance",
					["event"] = "Mounted",
					["talent"] = "Primary",
				}, -- [2]
				{
					["set"] = "Tank",
					["event"] = "City",
					["talent"] = "Primary",
				}, -- [3]
				{
					["event"] = "Evocation",
					["set"] = "DPS",
				}, -- [4]
			},
I"m trying to output the data in each index of the "events" array to a line item/button in the scroller.

Last edited by Tymesink : 05-28-09 at 01:20 AM.
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Scroll Frames...*Sigh*


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off