Quantcast
AceConfig-3.0 Options: Inherit "disabled" from parent group explicitly? - WoWInterface
Thread Tools Display Modes
12-29-20, 08:47 AM   #1
LudiusMaximus
A Frostmaul Preserver
 
LudiusMaximus's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 275
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?
__________________
~ Be the change you want to see in the world... of warcraft interface! ~
  Reply With Quote
12-29-20, 12:48 PM   #2
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,817
Is it not doing this already?
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
12-29-20, 12:49 PM   #3
LudiusMaximus
A Frostmaul Preserver
 
LudiusMaximus's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 275
Originally Posted by Seerah View Post
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.
__________________
~ Be the change you want to see in the world... of warcraft interface! ~
  Reply With Quote
12-29-20, 05:05 PM   #4
Vrul
An Onyxian Warder
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 397
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
  Reply With Quote
12-29-20, 06:43 PM   #5
LudiusMaximus
A Frostmaul Preserver
 
LudiusMaximus's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 275
Absolutely amazing!! Thank you so much!
__________________
~ Be the change you want to see in the world... of warcraft interface! ~
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » AceConfig-3.0 Options: Inherit "disabled" from parent group explicitly?

Thread Tools
Display Modes

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