I tried to make something Atropos described here
http://www.esoui.com/downloads/info7....html#comments (couldn't find a way to link directly to the comment).
I'm doing something wrong, and I'm not sure whether it's LAM-specific or not. Here's my code:
Lua Code:
local LAM = LibStub:GetLibrary("LibAddonMenu-2.0")
local foobarPanel = nil
local foobarConf = {}
local foobarRefreshCount = 0
local function foobarRefreshPanel(control)
local panel = control.panel or control
local lastVisibleControl
if panel ~= foobarPanel then
-- ignore refresh initiated by another addon's control
return
end
if control.data and control.data.parentModule then
-- sub-module controls can't turn whole module on/off,
-- in this case we don't need to update layout
return
end
foobarRefreshCount = foobarRefreshCount + 1
panel.controlsToRefresh[1].data.name = "Refresh #" .. foobarRefreshCount
for i, control in ipairs(panel.controlsToRefresh) do
local visible = true
if control.data.parentModule then
-- hide control if it's module is disabled
visible = foobarConf[control.data.parentModule]
end
--control:ClearAnchors()
control:SetHidden(not visible)
if visible then
if lastVisibleControl then
--control:SetAnchor(TOPLEFT, lastVisibleControl, BOTTOMLEFT, 0, 15)
else
--control:SetAnchor(TOPLEFT)
end
lastVisibleControl = control
end
end
end
local function foobarCreateSettings()
local panelData = {
type = "panel",
name = "FooBar",
registerForRefresh = true,
}
local optionsData = setmetatable({}, {__index = table})
optionsData:insert{type = "header",
name = "Refresh counter"}
-- Foo module options
optionsData:insert{type = "header",
name = "Foo"}
optionsData:insert{type = "checkbox",
name = "Foo module",
tooltip = "This should show/hide the feature option",
getFunc = function() return foobarConf.Foo end,
setFunc = function(value) foobarConf.Foo = value end,
toggleModule = "Foo"}
optionsData:insert{type = "checkbox",
name = "Foo feature Alpha",
getFunc = function() return foobarConf.FooAlpha end,
setFunc = function(value) foobarConf.FooAlpha = value end,
parentModule = "Foo"}
-- Bar module options
optionsData:insert{type = "header",
name = "Bar"}
optionsData:insert{type = "checkbox",
name = "Bar module",
tooltip = "This should show/hide the feature option",
getFunc = function() return foobarConf.Bar end,
setFunc = function(value) foobarConf.Bar = value end,
toggleModule = "Bar"}
optionsData:insert{type = "checkbox",
name = "Bar feature Beta",
getFunc = function() return foobarConf.BarBeta end,
setFunc = function(value) foobarConf.BarBeta = value end,
parentModule = "Bar"}
foobarPanel = LAM:RegisterAddonPanel("FooBarSettings", panelData)
LAM:RegisterOptionControls("FooBarSettings", optionsData)
CALLBACK_MANAGER:RegisterCallback("LAM-RefreshPanel", foobarRefreshPanel)
end
It's a panel with 5 controls:
"Refresh #counter" .. only to track number of refresh calls
"Foo module" .. sets foobarConf.Foo to true/false, which should show/hide Foo feature option(s) below it
"Foo feature Alpha" .. dummy option
"Bar module" .. sets foobarConf.Bar to true/false, which should show/hide Bar feature option(s) below it
"Bar feature Beta" .. dummy option
foobarRefreshPanel() gets called properly, every time it passes tests at the top, it increases "Refresh #counter". But showing/hiding controls is somehow broken. For example if I have "Foo module ON", and turn it OFF, then when I come across "Foo feature Alpha" in controlsToRefresh loop, I call control:SetHidden(true) (because control.data.parentModule == "Foo" and foobarConf["Foo"] == false), but the control doesn't disappear, only becomes unresponsive (doesn't react to mouse over, click). If I switch to another LAM panel and back, the control is hidden properly.
It's even more weird if you uncomment ClearAnchors/SetAnchor lines. The anchors are apparently reprocessed, turning "Foo module" OFF pushes "Bar module" up as if "Foo feature Alpha" wasn't there (which it shouldn't, of course).
So, what do I need to do to make a control actually disappear after SetHidden(true), and re-appear after SetHidden(false)?