WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   AceConfig-3.0 Options: Inherit "disabled" from parent group explicitly? (https://www.wowinterface.com/forums/showthread.php?t=58502)

LudiusMaximus 12-29-20 08:47 AM

AceConfig-3.0 Options: Inherit "disabled" from parent group explicitly?
 
I want to make a "reset to default" button next to every slider in my settings.
To safe code lines and make it more maintainable, I have a function to create this reset button:

Lua Code:
  1. local function CreateSliderResetButton(order, forSituations, index1, index2)
  2.   return {
  3.     type = "execute",
  4.     name = "Reset",
  5.     order = order,
  6.       func =
  7.         function()
  8.           DynamicCam:SetSettingsDefault(forSituations, index1, index2)
  9.         end,
  10.       disabled =
  11.         function()
  12.           return DynamicCam:GetSettingsValue(forSituations, index1, index2) == DynamicCam:GetSettingsDefault(index1, index2)
  13.       end,
  14.   }
  15. end

So the button gets disabled, whenever the slider already has the default value.
But the button should also get disabled, whenever the button's parent group is disabled, as it is the case when the button does not have a "disabled" function of its own.

Is there a way to explicitly check for the parent group's disable status?

Seerah 12-29-20 12:48 PM

Is it not doing this already?

LudiusMaximus 12-29-20 12:49 PM

Quote:

Originally Posted by Seerah (Post 338107)
Is it not doing this already?

No, it seems that when you are defining a new "disabled" function, the disabled status of the parent group is ignored.

Vrul 12-29-20 05:05 PM

Assuming you are not using the passed info table in your other disabled functions (and not using handlers) then you could use:
Lua Code:
  1. local function GetInheritedDisabledStatus(info)
  2.     local option, options = info.options, { }
  3.     local disabled = option.disabled
  4.     for index = 1, #info - 1 do
  5.         option = option.args[info[index]]
  6.         options[index] = option
  7.     end
  8.     for index = #options, 1, -1 do
  9.         if options[index].disabled ~= nil then
  10.             disabled = options[index].disabled
  11.             break
  12.         end
  13.     end
  14.     if type(disabled) == "function" then
  15.         disabled = disabled()
  16.     end
  17.     return disabled
  18. end
  19.  
  20. local function CreateSliderResetButton(order, forSituations, index1, index2)
  21.   return {
  22.     type = "execute",
  23.     name = "Reset",
  24.     order = order,
  25.       func =
  26.         function()
  27.           DynamicCam:SetSettingsDefault(forSituations, index1, index2)
  28.         end,
  29.       disabled =
  30.         function(info)
  31.           return DynamicCam:GetSettingsValue(forSituations, index1, index2) == DynamicCam:GetSettingsDefault(index1, index2) or GetInheritedDisabledStatus(info)
  32.       end,
  33.   }
  34. end

LudiusMaximus 12-29-20 06:43 PM

Absolutely amazing!! Thank you so much!


All times are GMT -6. The time now is 11:44 PM.

vBulletin © 2021, Jelsoft Enterprises Ltd
© 2004 - 2020 MMOUI