Quantcast

Moved the last (!) click handler (category buttons) into xml

Kevin Lyles [10-31-09 - 05:04]
Moved the last (!) click handler (category buttons) into xml
Filename
WeightsWatcher.xml
config.lua
diff --git a/WeightsWatcher.xml b/WeightsWatcher.xml
index 307efd5..ac4e096 100644
--- a/WeightsWatcher.xml
+++ b/WeightsWatcher.xml
@@ -76,6 +76,9 @@
 						fontString:SetPoint("LEFT")
 						self:SetFontString(fontString)
 					</OnLoad>
+					<OnClick>
+						toggleCollapse(self:GetParent(), self:GetParent():GetParent():GetParent().scrollFrame)
+					</OnClick>
 				</Scripts>
 			</Button>
 		</Frames>
diff --git a/config.lua b/config.lua
index 21efe2c..b01e002 100644
--- a/config.lua
+++ b/config.lua
@@ -406,6 +406,7 @@ function createScrollableTieredList(template, scrollFrame, scrolledFrame, elemen

 	scrollFrame.categories = {}
 	scrollFrame.shown = {}
+	scrollFrame.elementHeight = elementHeight
 	for i, category in ipairs(template) do
 		--for each category print the header and then the print the list of stats
 		categoryFrame = CreateFrame("Frame", category, scrolledFrame, "ww_categoryFrame")
@@ -417,13 +418,6 @@ function createScrollableTieredList(template, scrollFrame, scrolledFrame, elemen
 		else
 			categoryFrame:SetPoint("TOPLEFT", scrollFrame.categories[i - 1], "BOTTOMLEFT")
 		end
-		categoryFrame.text:SetScript("OnClick",
-			function(self)
-				toggleCollapse(self:GetParent(), scrollFrame, elementHeight,
-					function()
-						scrollFrame:GetScript("OnShow")(scrollFrame)
-					end)
-			end)
 		table.insert(scrollFrame.categories, categoryFrame)
 		table.insert(scrollFrame.shown, categoryFrame.text)
 		categoryFrame.position = #(scrollFrame.shown)
@@ -443,7 +437,7 @@ function createScrollableTieredList(template, scrollFrame, scrolledFrame, elemen
 	end
 end

-function toggleCollapse(categoryFrame, scrollFrame, elementHeight, scrollBarUpdateFunction)
+function toggleCollapse(categoryFrame, scrollFrame)
 	if categoryFrame.length == 1 then
 		return
 	end
@@ -459,7 +453,7 @@ function toggleCollapse(categoryFrame, scrollFrame, elementHeight, scrollBarUpda
 			end
 		end
 		categoryFrame.collapsed = false
-		categoryFrame:SetHeight(20 * categoryFrame.length)
+		categoryFrame:SetHeight(scrollFrame.elementHeight * categoryFrame.length)
 	else
 		for _, stat in ipairs({categoryFrame:GetChildren()}) do
 			if stat.name then
@@ -473,9 +467,9 @@ function toggleCollapse(categoryFrame, scrollFrame, elementHeight, scrollBarUpda
 			end
 		end
 		categoryFrame.collapsed = true
-		categoryFrame:SetHeight(20)
+		categoryFrame:SetHeight(scrollFrame.elementHeight)
 	end
-	scrollBarUpdateFunction()
+	scrollFrame:GetScript("OnShow")(scrollFrame)
 end

 function ClassDropDownInitialize(dropdown)