Woot .. got it worked out .. the main problem I was having was trying to get the menu creation element to be totally separate to the data values in as such it used a generic variable that grabbed the specific information.
Well, so that someone else could find the information useful here's what I managed to do .. in a cut down version.
Edit: Slightly adjusted so that info.func is set under certain conditions
Code:
local col = { red = 1.0, green = 1.0, blue = 0.0, alpha = 1.0 }
menuList = {
[1] = {
-- Flags
["hasColorSwatch"] = true,
["hasOpacity"] = true,
-- Values
["red"] = col.red,
["green"] = col.green,
["blue"] = col.blue,
["alpha"] = col.alpha,
-- Functions
["onColorSwatch"] = function()
col.red, col.green, col.blue = ColorPickerFrame:GetColorRGB();
return col.red,col.green,col.blue
end,
["onOpacity"] = function()
col.alpha = 1 - OpacitySliderFrame:GetValue();
return col.alpha
end,
},
}
local function buildMenuButton(data)
-- Create a black info table
local info = UIDropDownMenu_CreateInfo();
-- Create variables to transfer previous values back to current
local oldR, oldG, oldB, oldA
-- Grab Flags
info.hasColorSwatch = data["hasColorSwatch"];
info.hasOpacity = data["hasOpacity"];
-- Grab the latest values stored
if ( info.hasColorSwatch ) then
info.r = data["red"];
info.g = data["green"];
info.b = data["blue"];
end
if ( info.hasOpacity ) then
info.opacity = data["alpha"];
end
-- Set Up Functions
if ( info.hasColorSwatch or info.hasOpacity ) then
info.swatchFunc = function()
oldR,oldG,oldB,oldA = data["colorRed"],data["colorGreen"],data["colorBlue"]
data["red"],data["green"],data["blue"] = data["onColorSwatch"]()
end
info.opacityFunc = function()
data["alpha"] = data["onOpacity"]()
end
info.func = UIDropDownMenuButton_OpenColorPicker;
info.cancelFunc = function()
data["red"],data["green"],data["blue"] = ColorPicker_GetPreviousValues();
data["alpha"] = ColorPickerFrame.previousValues.opacity;
end
end
-- After setting all the required info settings then return back to the
-- calling routine
return info;
end
This seems to work exactly as I like so that I can shift the menu creation code into a separate file and have addons just call it with their own set of data.