WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   [AceConfig] Grey out options when disabled (https://www.wowinterface.com/forums/showthread.php?t=56624)

Lyak 09-01-18 07:54 AM

[AceConfig] Grey out options when disabled
 
Hi all,

I am to learn AceConfig and got a question regarding greying options out when disabled.

So, I currently have the following:
Lua Code:
  1. local enable = true
  2. local size = 15
  3.  
  4. local options = {
  5.     type = "group",
  6.     childGroups = "tab",
  7.     name = "Test " .. A.version,
  8.     arg = "Test",
  9.     args = {
  10.         enable = {
  11.             order = 1,
  12.             type = "toggle",
  13.             name = "Enable",
  14.             get = function()
  15.                 return enable;
  16.             end,
  17.             set = function(_, value)
  18.                 enable = value;
  19.             end,
  20.             disabled = function()
  21.  
  22.             end,
  23.         },
  24.         size = {
  25.             order = 2,
  26.             type = "range",
  27.             name = "Size",
  28.             min = 5,
  29.             max = 30,
  30.             step = 1,
  31.             get = function()
  32.                 return size;
  33.             end,
  34.             set = function(_, value)
  35.                 size = value;
  36.             end,
  37.         },
  38.     },
  39. }

It seems like I could grey out the size option with enable's disabled function, but I ain't not too sure :confused:

Could I please get a help?

Thank you in advance!

myrroddin 09-01-18 01:25 PM

Assuming you set up your saved variable correctly in OnInitialize, in your enable table, change your get and set functions:
Lua Code:
  1. get = function()
  2.     return self.db.profile.enable
  3. end,
  4. set = function(info, value)
  5.     self.db.profile.enable = value
  6. end
And delete lines 20-22 because that isn't going to work.

Now to disable size based on enable:
Lua Code:
  1. get = function()
  2.     return self.db.profile.size
  3. end,
  4. set = function(info, value)
  5.     self.db.profile.size = value
  6. end,
  7. disabled = function()
  8.     return not self.db.profile.enable
  9. end

Lyak 09-01-18 03:33 PM

Quote:

Originally Posted by myrroddin (Post 329960)
Assuming you set up your saved variable correctly in OnInitialize, in your enable table, change your get and set functions:
Lua Code:
  1. -- code snippet
And delete lines 20-22 because that isn't going to work.

Now to disable size based on enable:
Lua Code:
  1. -- code snippet

Oh, so the disabled function should be registered within an option that I would like to grey out, not in an enable option?

That makes sense!

One more question tho.

In case if there are more than one option (let's say ten options, maybe), should I register disabled function for all of them via for loop or something?

+ What about child groups?

Seerah 09-01-18 04:10 PM

You can disable options individually or as a whole child group.
https://www.wowace.com/projects/ace3...tables#title-2

Lyak 09-01-18 08:41 PM

Quote:

Originally Posted by Seerah (Post 329962)
You can disable options individually or as a whole child group.
https://www.wowace.com/projects/ace3...tables#title-2

Ah, you are right.

Just needed to put disabled function under the group, not under each individual options.

Thanks, Seerah :banana:!!


All times are GMT -6. The time now is 03:42 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI