Thread Tools Display Modes
10-27-10, 05:53 PM   #1
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,960
How do you use colorSwatch in UIDropDownMenu ?

I've been working all day on one of my old addons and have been working through the usage of UIDropDownMenu.

I've got the check and click side down easily and thought I would delve into the colorswatch option but no matter how many examples I look at ( that don't include external library usage ) I can't get the colors I pick to be saved on the colorswatch.

I know you need a swatchFunc, opacityFunc, the info.r/g/b/opacity values set and I assume call OpenColorPicker from the regular info.func setting. However, despite having the swatch displayed and the ColorPicker displaying the colors aren't being kept on each use and it only colors the edges of the swatch instead of the box itself.

If anyone can shed any light on the subject it would be great

Thanks in advance.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
10-27-10, 07:45 PM   #2
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
I haven't tried it myself, but have you looked at how the default UI does it for the chat frame menu?
__________________
"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
10-28-10, 06:54 AM   #3
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,960
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.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818

Last edited by Xrystal : 10-28-10 at 07:26 AM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » How do you use colorSwatch in UIDropDownMenu ?


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