Quantcast

editWeight now scrolls its contents

Paul Spears [10-01-09 - 01:06]
editWeight now scrolls its contents
Filename
WeightsWatcher.xml
config.lua
diff --git a/WeightsWatcher.xml b/WeightsWatcher.xml
index a9aeb56..5f19758 100644
--- a/WeightsWatcher.xml
+++ b/WeightsWatcher.xml
@@ -34,6 +34,29 @@
 				</Texture>
 			</Layer>
 		</Layers>
+		<Frames>
+			<!--Invisible frame with scroll bar that does the scrolling-->
+			<ScrollFrame name="$parentScrollFrame" parentKey="scrollFrame" inherits="FauxScrollFrameTemplate">
+				<Size>
+					<AbsDimension x="400" y="600"/>
+				</Size>
+				<Anchors>
+					<Anchor point="TOPLEFT" relativeTo="editWeight">
+						<Offset>
+							<AbsDimension x="-5"/>
+						</Offset>
+					</Anchor>
+				</Anchors>
+				<Scripts>
+					<OnShow>
+						scrollBarUpdate()
+					</OnShow>
+					<OnVerticalScroll>
+						FauxScrollFrame_OnVerticalScroll(self, offset, 20, scrollBarUpdate)
+					</OnVerticalScroll>
+				</Scripts>
+			</ScrollFrame>
+		</Frames>
 	</Frame>
 	<!--The Parent Frame Containing all configuration content-->
 	<Frame name="wwConfig" parent="UIParent" hidden="true">
diff --git a/config.lua b/config.lua
index 615231e..f005196 100644
--- a/config.lua
+++ b/config.lua
@@ -24,6 +24,33 @@ function open_config()
 	end
 end

+function scrollBarUpdate()
+	local numShown, i = 30
+	local offset = FauxScrollFrame_GetOffset(editWeight.scrollFrame)
+-- 	print(offset)
+	FauxScrollFrame_Update(editWeight.scrollFrame, #(statButtonTable), numShown, 100)
+	offset = offset / 5
+	if numShown > #(statButtonTable) then
+		numShown = #(statButtonTable)
+	end
+	if offset > #(statButtonTable) - numShown then
+		offset = #(statButtonTable) - numShown
+	end
+	statButtonTable[1]:SetPoint("TOPLEFT", 5, 20 * offset)
+	for i = 1, offset do
+		-- seems to be the only way to reliably update the positions of the buttons after these
+		statButtonTable[i]:Hide()
+		statButtonTable[i]:Show()
+		statButtonTable[i]:Hide()
+	end
+	for i = offset + 1, offset + numShown do
+		statButtonTable[i]:Show()
+	end
+	for i = offset + numShown + 1, #(statButtonTable) do
+		statButtonTable[i]:Hide()
+	end
+end
+
 --opens the right panel and loads the appropriate buttons
 function configClassSelect(classType)
 	local counter = 1
@@ -76,18 +103,28 @@ end

 --creates a list of fontStrings to display the stats
 function createStatFontStrings()
-	local xOffSet, yOffSet = 5, -5
+	local xOffset, i, newCat = 5, 1
 	for category, stats in pairs(trackedStats) do
 		--for each category print the header and then the print the list of stats
 		local newButton = CreateFrame("Button", category, editWeight, "genericButton")
-		newButton:SetPoint("TOPLEFT", xOffSet, yOffSet)
+		if i > 1 then
+			newButton:SetPoint("TOPLEFT", statButtonTable[i - 1], "BOTTOMLEFT", -2 * xOffset, 0)
+		end
 		newButton:SetText(category)
-		yOffSet = yOffSet - 20
+		table.insert(statButtonTable, newButton)
+		i = i + 1
+		newCat = true
 		for _ , stat in pairs(stats) do
 			newButton = CreateFrame("Button", stat, editWeight, "genericButton")
-			newButton:SetPoint("TOPLEFT", xOffSet * 2, yOffSet)
+			if newCat then
+				newButton:SetPoint("TOPLEFT", statButtonTable[i - 1], "BOTTOMLEFT", 2 * xOffset, 0)
+				newCat = false
+			else
+				newButton:SetPoint("TOPLEFT", statButtonTable[i - 1], "BOTTOMLEFT", 0, 0)
+			end
 			newButton:SetText(stat)
-			yOffSet = yOffSet - 20
+			table.insert(statButtonTable, newButton)
+			i = i + 1
 		end
 	end
 end