View Single Post
03/04/17, 01:52 PM   #3
Phinix
 
Phinix's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 186
Managed to work around this issue with a custom framework. Might be a better way though. Still this is relatively clean and painless and allows copy-paste adding of submenus without additional code. The only minor hassle is getting the height value for the expanded menu.

Code:
local subWidgets = { -- the names here are from the reference = "" field on the submenu widget
	["SrendarrBlacklistSubmenu"]			= {height = 162, widgets = {}},
	["SrendarrAuraWhitelistSubmenu"]		= {height = 381, widgets = {}},
	["SrendarrDebuffWhitelistSubmenu"]		= {height = 237, widgets = {}},
	["SrendarrGroupWhitelistSubmenu"]		= {height = 278, widgets = {}},
	["SrendarrPlayerFilterSubmenu"]			= {height = 318, widgets = {}},
	["SrendarrTargetFilterSubmenu"]			= {height = 441, widgets = {}},
	["SrendarrDisplayGroupSubmenu"]			= {height = 532, widgets = {}},
	["SrendarrDebugSubmenu"]			= {height = 278, widgets = {}},
}

for entry, widgetData in ipairs(panelData) do
	local widgetType = widgetData.type
	local widget = LAMCreateControl[widgetType](panel, widgetData)

	local function ToggleSubmenu(clicked) -- toggle simulated sub-menus (Phinix)
		local control = clicked:GetParent()
		local subWidgetsDB = subWidgets[control.data.reference]

		if control.open then
			control.bg:SetDimensions(panel:GetWidth() + 19, 30)
			control.label:SetDimensions(panel:GetWidth(), 30)
			control.arrow:SetTexture("EsoUI\\Art\\Miscellaneous\\list_sortdown.dds")
			for s = 1, #subWidgetsDB.widgets do
				local subWidget = subWidgetsDB.widgets[s].w
				subWidget:SetHidden(true)
			end
			control.open = false
		else
			control.bg:SetDimensions(panel:GetWidth() + 19, subWidgetsDB.height)
			control.label:SetDimensions(panel:GetWidth(), subWidgetsDB.height)
			control.arrow:SetTexture("EsoUI\\Art\\Miscellaneous\\list_sortup.dds")
			for s = 1, #subWidgetsDB.widgets do
				local subWidget = subWidgetsDB.widgets[s].w
				subWidget:SetHidden(false)
			end
			control.open = true
		end
	end

	if widgetData.controls ~= nil then -- simulate sub-menu widgets for custom panels (Phinix)
		local lastSubWidget = widget.label
		local subWidgetsDB = subWidgets[widget.data.reference]
		widget.label:SetHandler("OnMouseUp", ToggleSubmenu)

		widget.scroll:SetDimensionConstraints(panel:GetWidth() + 19, 0, panel:GetWidth() + 19, 0)
		widget.label:SetDimensions(panel:GetWidth(), (widget.open) and subWidgetsDB.height or 30)
		widget.bg:SetDimensions(panel:GetWidth() + 19, (widget.open) and subWidgetsDB.height or 30)

		for subEntry, subWidgetData in ipairs(widgetData.controls) do
			local subWidgetType = subWidgetData.type
			local subWidget = LAMCreateControl[subWidgetType](panel, subWidgetData)
			subWidget:SetAnchor(TOPLEFT, lastSubWidget, (lastSubWidget == widget.label) and TOPLEFT or BOTTOMLEFT, 0, (lastSubWidget == widget.label) and 45 or 15)
			subWidgetsDB.widgets[subEntry] = {w = subWidget}
			
			...
				other code goes here
			...

			if not widget.open then
				subWidget:SetHidden(true)
			else
				subWidget:SetHidden(false)
			end
			lastSubWidget = subWidget
		end
	end
end
  Reply With Quote