WoWInterface - View Single Post - Colorpicker?
Thread: Colorpicker?
View Single Post
07-12-20, 04:43 PM   #4
A Cobalt Mageweaver
LudiusMaximus's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 227
Finally got back to this, and two questions arose:

function ShowColorPicker(r, g, b, a, changedCallback)
 ColorPickerFrame.hasOpacity, ColorPickerFrame.opacity = (a ~= nil), a;
 ColorPickerFrame.previousValues = {r,g,b,a};
 ColorPickerFrame.func, ColorPickerFrame.opacityFunc, ColorPickerFrame.cancelFunc = 
  changedCallback, changedCallback, changedCallback;
 ColorPickerFrame:Hide(); -- Need to run the OnShow handler.

local function myColorCallback(restore)
 local newR, newG, newB, newA;
 if restore then
  -- The user bailed, we extract the old color from the table created by ShowColorPicker.
  newR, newG, newB, newA = unpack(restore);
  -- Something changed
  newA, newR, newG, newB = OpacitySliderFrame:GetValue(), ColorPickerFrame:GetColorRGB();
 -- Update our internal storage.
 print(newR, newG, newB, newA);

ShowColorPicker(r, g, b, a, myColorCallback);

1st Question:
local myPackedColor = {1, 1, 1, 1};
ShowColorPicker(unpack(myPackedColor), myColorCallback);
When I do this, ShowColorPicker() only gets the first return value of unpack() as its first argument, the second argument is already the myColorCallback function. Is there a correct way of doing this? For other functions like e.g. SetColorTexture(unpack(myPackedColor)) it works.

2nd Question:
Is there a way to pass additional arguments to the changedCallback function? Or do I have to do this with "public" variables?
~ Be the change you want to see in the world... of warcraft interface! ~
  Reply With Quote