Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save merlight/0fe43ed94a4d46477f5e to your computer and use it in GitHub Desktop.
Save merlight/0fe43ed94a4d46477f5e to your computer and use it in GitHub Desktop.
LAM CreateOptionsControlsRecursively
--INTERNAL FUNCTION
--creates controls when options panel is first shown
--controls anchoring of these controls in the panel
local function CreateOptionsControlsRecursively(parent, optionsTable, maxDepth)
if not optionsTable or maxDepth < 0 then
return
end
local lastAddedControl, lacAtHalfRow
local anchorOffset = 0
for _, widgetData in ipairs(optionsTable) do
local widgetType = widgetData.type
local widget = lamcc[widgetType](parent, widgetData)
local isHalf = false
if widgetType == "submenu" then
CreateOptionsControlsRecursively(widget, widgetData.controls, maxDepth - 1)
else
isHalf = (widgetData.width == "half")
end
if lastAddedControl then
if lacAtHalfRow and isHalf then
widget:SetAnchor(TOPLEFT, lastAddedControl, TOPRIGHT, 10, 0)
anchorOffset = zo_max(0, widget:GetHeight() - lastAddedControl:GetHeight())
lacAtHalfRow = false
-- lastAddedControl intentionally LEFT unchanged
else
widget:SetAnchor(TOPLEFT, lastAddedControl, BOTTOMLEFT, 0, 15 + anchorOffset)
lacAtHalfRow = isHalf
anchorOffset = 0
lastAddedControl = widget
end
else
widget:SetAnchor(TOPLEFT)
lacAtHalfRow = isHalf
lastAddedControl = widget
end
end
end
--INTERNAL FUNCTION
--handles switching between panels
local function ToggleAddonPanels(panel) --called in OnShow of newly shown panel
local currentlySelected = lam.currentAddonPanel
if currentlySelected and currentlySelected ~= panel then
currentlySelected:SetHidden(true)
end
lam.currentAddonPanel = panel
-- refresh visible rows to reflect panel IsHidden status
ZO_ScrollList_RefreshVisible(lam.addonList)
local addonID = panel:GetName()
if not optionsCreated[addonID] then
--if this is the first time opening this panel, create these options
local optionsTable = addonToOptionsMap[addonID]
CreateOptionsControlsRecursively(panel, optionsTable, 1)
optionsCreated[addonID] = true
cm:FireCallbacks("LAM-PanelControlsCreated", panel)
end
cm:FireCallbacks("LAM-RefreshPanel", panel)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment