Thread Tools Display Modes
07/27/14, 03:38 PM   #1
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
Why control:SetHidden(true) doesn't hide the control?

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:
  1. local LAM = LibStub:GetLibrary("LibAddonMenu-2.0")
  2.  
  3. local foobarPanel = nil
  4. local foobarConf = {}
  5. local foobarRefreshCount = 0
  6.  
  7.  
  8. local function foobarRefreshPanel(control)
  9.     local panel = control.panel or control
  10.     local lastVisibleControl
  11.  
  12.     if panel ~= foobarPanel then
  13.         -- ignore refresh initiated by another addon's control
  14.         return
  15.     end
  16.  
  17.     if control.data and control.data.parentModule then
  18.         -- sub-module controls can't turn whole module on/off,
  19.         -- in this case we don't need to update layout
  20.         return
  21.     end
  22.  
  23.     foobarRefreshCount = foobarRefreshCount + 1
  24.     panel.controlsToRefresh[1].data.name = "Refresh #" .. foobarRefreshCount
  25.  
  26.     for i, control in ipairs(panel.controlsToRefresh) do
  27.         local visible = true
  28.         if control.data.parentModule then
  29.             -- hide control if it's module is disabled
  30.             visible = foobarConf[control.data.parentModule]
  31.         end
  32.         --control:ClearAnchors()
  33.         control:SetHidden(not visible)
  34.         if visible then
  35.             if lastVisibleControl then
  36.                 --control:SetAnchor(TOPLEFT, lastVisibleControl, BOTTOMLEFT, 0, 15)
  37.             else
  38.                 --control:SetAnchor(TOPLEFT)
  39.             end
  40.             lastVisibleControl = control
  41.         end
  42.     end
  43. end
  44.  
  45.  
  46. local function foobarCreateSettings()
  47.     local panelData = {
  48.         type = "panel",
  49.         name = "FooBar",
  50.         registerForRefresh = true,
  51.     }
  52.     local optionsData = setmetatable({}, {__index = table})
  53.  
  54.     optionsData:insert{type = "header",
  55.                        name = "Refresh counter"}
  56.  
  57.     -- Foo module options
  58.     optionsData:insert{type = "header",
  59.                        name = "Foo"}
  60.     optionsData:insert{type = "checkbox",
  61.                        name = "Foo module",
  62.                        tooltip = "This should show/hide the feature option",
  63.                        getFunc = function() return foobarConf.Foo end,
  64.                        setFunc = function(value) foobarConf.Foo = value end,
  65.                        toggleModule = "Foo"}
  66.     optionsData:insert{type = "checkbox",
  67.                        name = "Foo feature Alpha",
  68.                        getFunc = function() return foobarConf.FooAlpha end,
  69.                        setFunc = function(value) foobarConf.FooAlpha = value end,
  70.                        parentModule = "Foo"}
  71.  
  72.     -- Bar module options
  73.     optionsData:insert{type = "header",
  74.                        name = "Bar"}
  75.     optionsData:insert{type = "checkbox",
  76.                        name = "Bar module",
  77.                        tooltip = "This should show/hide the feature option",
  78.                        getFunc = function() return foobarConf.Bar end,
  79.                        setFunc = function(value) foobarConf.Bar = value end,
  80.                        toggleModule = "Bar"}
  81.     optionsData:insert{type = "checkbox",
  82.                        name = "Bar feature Beta",
  83.                        getFunc = function() return foobarConf.BarBeta end,
  84.                        setFunc = function(value) foobarConf.BarBeta = value end,
  85.                        parentModule = "Bar"}
  86.  
  87.     foobarPanel = LAM:RegisterAddonPanel("FooBarSettings", panelData)
  88.     LAM:RegisterOptionControls("FooBarSettings", optionsData)
  89.     CALLBACK_MANAGER:RegisterCallback("LAM-RefreshPanel", foobarRefreshPanel)
  90. 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)?
  Reply With Quote
07/27/14, 04:09 PM   #2
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
Ok so it has something to do with CreateTopLevelWindow

When I change this in LAM/controls/checkbox.lua:
Lua Code:
  1. function LAMCreateControl.checkbox(parent, checkboxData, controlName)
  2.     local control = wm:CreateTopLevelWindow(controlName or checkboxData.reference)
  3.     control:SetParent(parent.scroll or parent)

to this:
Lua Code:
  1. function LAMCreateControl.checkbox(parent, checkboxData, controlName)
  2.     local control = wm:CreateControl(controlName or checkboxData.reference,
  3.                                      parent.scroll or parent,
  4.                                      CT_CONTROL)

... then my above code simply works
  Reply With Quote
07/27/14, 04:19 PM   #3
Xrystal
caritas omnia vincit
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 369
I think the idea is that the TopLevelWindow won't have a parent. By default it's parent is GuiParent. You would use Control to create controls/windows/frames that are children of other windows/controls/frames.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Why control:SetHidden(true) doesn't hide the control?


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off