LibUIDropDownMenu

About

Standard UIDropDownMenu's global functions using protected frames and causing taints when used by third-party addons. But it is possible to avoid taints by using same functionality with that library.

What is it

Library is standard code from Blizzard's files EasyMenu.lua, UIDropDownMenu.lua, UIDropDownMenu.xml, UIDropDownMenuTemplates.lua and UIDropDownMenuTemplates.xml with frames, tables, variables and functions bounded to the library tables.

Global constants have been added with a prefix "L_", for example:

  • L_UIDROPDOWNMENU_MINBUTTONS

Addon Dependancy and Configuration

 

  • Embed LibUIDropDownMenu to your addon, you can specify to the subfolder of LibUIDropDownMenu if you feel this keep your addon's folder structure lighter.
  • Add LibUIDropDownMenu.xml to your toc or your embeds.xml / libs.xml.
  • Make sure your toc file has the following settings:
## Dependencies: LibStub, !LibUIDropDownMenu
  • If your addon doesn't embed LibStub, you will need it.

How to use it (for addon developer)

Initial Preparation

Assuming your addon is using all the UIDropDownMenu functions from the WoW's built in function calls, then it is suggested that you have below preparation in your lua codes:

local LibDD = LibStub:GetLibrary("LibUIDropDownMenu-4.0")

Function Call Replacement

Depends on which UIDropDownMenu's function calls you have used in your addon, you will need below similar replacement:

UIDropDownMenu_Initialize => LibDD:UIDropDownMenu_Initialize
UIDropDownMenu_CreateInfo => LibDD:UIDropDownMenu_CreateInfo
UIDropDownMenu_AddButton => LibDD:UIDropDownMenu_AddButton

UIDropDownMenu_AddSeparator => LibDD:UIDropDownMenu_AddSeparator
UIDropDownMenu_AddSpace=> LibDD:UIDropDownMenu_AddSpace

UIDropDownMenu_SetSelectedValue => LibDD:UIDropDownMenu_SetSelectedValue
UIDropDownMenu_SetSelectedName=> LibDD:UIDropDownMenu_SetSelectedName

UIDropDownMenu_SetSelectedID => LibDD:UIDropDownMenu_SetSelectedID
UIDropDownMenu_SetWidth => LibDD:UIDropDownMenu_SetWidth

CloseDropDownMenus => LibDD:CloseDropDownMenus

Creating new UIDropDownMenu

Traditionally you will either create a new frame in your lua codes or with XML by setting the frame to inherit from "UIDropDownMenuTemplate".

For example, if your lua code was something like below in the past:

local frame = CreateFrame("Frame", addon.Name.."DropDown", nil, "UIDropDownMenuTemplate")

By using this library, you will need to create your menu from like below:

local frame = LibDD:Create_UIDropDownMenu("MyDropDownMenu", parent_frame)

Constants

  • L_UIDROPDOWNMENU_MINBUTTONS
  • L_UIDROPDOWNMENU_MAXBUTTONS
  • L_UIDROPDOWNMENU_MAXLEVELS
  • L_UIDROPDOWNMENU_BUTTON_HEIGHT
  • L_UIDROPDOWNMENU_BORDER_HEIGHT
  • L_UIDROPDOWNMENU_OPEN_MENU
  • L_UIDROPDOWNMENU_INIT_MENU
  • L_UIDROPDOWNMENU_MENU_LEVEL
  • L_UIDROPDOWNMENU_MENU_VALUE
  • L_UIDROPDOWNMENU_SHOW_TIME
  • L_UIDROPDOWNMENU_DEFAULT_TEXT_HEIGHT
  • L_OPEN_DROPDOWNMENUS
  • L_DropDownList1
  • L_DropDownList2

Button Name

As you (the developers) might be aware that at some point you might need to manipulate the dropdowns by accessing the button names. For example, you have multiple levels of menus and you would like to hide or show some level's menu button. In that case, you need to make sure you also revise the button name used in your original codes when you are migrating to use LibUIDropDownMenu.

  • "L_DropDownList"..i

Example:

	for i = 1, L_UIDROPDOWNMENU_MAXLEVELS, 1 do
		dropDownList = _G["L_DropDownList"..i];
		if ( i >= L_UIDROPDOWNMENU_MENU_LEVEL or frame ~= L_UIDROPDOWNMENU_OPEN_MENU ) then
			dropDownList.numButtons = 0;
			dropDownList.maxWidth = 0;
			for j=1, L_UIDROPDOWNMENU_MAXBUTTONS, 1 do
				button = _G["L_DropDownList"..i.."Button"..j];
				button:Hide();
			end
			dropDownList:Hide();
		end
	end

 

List of button attributes

  • info.text = [STRING] -- The text of the button
  • info.value = [ANYTHING] -- The value that L_UIDROPDOWNMENU_MENU_VALUE is set to when the button is clicked
  • info.func = [function()] -- The function that is called when you click the button
  • info.checked = [nil, true, function] -- Check the button if true or function returns true
  • info.isNotRadio = [nil, true] -- Check the button uses radial image if false check box image if true
  • info.isTitle = [nil, true] -- If it's a title the button is disabled and the font color is set to yellow
  • info.disabled = [nil, true] -- Disable the button and show an invisible button that still traps the mouseover event so menu doesn't time out
  • info.tooltipWhileDisabled = [nil, 1] -- Show the tooltip, even when the button is disabled.
  • info.hasArrow = [nil, true] -- Show the expand arrow for multilevel menus
  • info.hasColorSwatch = [nil, true] -- Show color swatch or not, for color selection
  • info.r = [1 - 255] -- Red color value of the color swatch
  • info.g = [1 - 255] -- Green color value of the color swatch
  • info.b = [1 - 255] -- Blue color value of the color swatch
  • info.colorCode = [STRING] -- "|cAARRGGBB" embedded hex value of the button text color. Only used when button is enabled
  • info.swatchFunc = [function()] -- Function called by the color picker on color change
  • info.hasOpacity = [nil, 1] -- Show the opacity slider on the colorpicker frame
  • info.opacity = [0.0 - 1.0] -- Percentatge of the opacity, 1.0 is fully shown, 0 is transparent
  • info.opacityFunc = [function()] -- Function called by the opacity slider when you change its value
  • info.cancelFunc = [function(previousValues)] -- Function called by the colorpicker when you click the cancel button (it takes the previous values as its argument)
  • info.notClickable = [nil, 1] -- Disable the button and color the font white
  • info.notCheckable = [nil, 1] -- Shrink the size of the buttons and don't display a check box
  • info.owner = [Frame] -- Dropdown frame that "owns" the current dropdownlist
  • info.keepShownOnClick = [nil, 1] -- Don't hide the dropdownlist after a button is clicked
  • info.tooltipTitle = [nil, STRING] -- Title of the tooltip shown on mouseover
  • info.tooltipText = [nil, STRING] -- Text of the tooltip shown on mouseover
  • info.tooltipOnButton = [nil, 1] -- Show the tooltip attached to the button instead of as a Newbie tooltip.
  • info.justifyH = [nil, "CENTER"] -- Justify button text
  • info.arg1 = [ANYTHING] -- This is the first argument used by info.func
  • info.arg2 = [ANYTHING] -- This is the second argument used by info.func
  • info.fontObject = [FONT] -- font object replacement for Normal and Highlight
  • info.menuTable = [TABLE] -- This contains an array of info tables to be displayed as a child menu
  • info.noClickSound = [nil, 1] -- Set to 1 to suppress the sound when clicking the button. The sound only plays if .func is set.
  • info.padding = [nil, NUMBER] -- Number of pixels to pad the text on the right side
  • info.leftPadding = [nil, NUMBER] -- Number of pixels to pad the button on the left side
  • info.minWidth = [nil, NUMBER] -- Minimum width for this line
  • info.customFrame = frame -- Allows this button to be a completely custom frame, should inherit from UIDropDownCustomMenuEntryTemplate and override appropriate methods.
  • info.icon = [TEXTURE] -- An icon for the button.
  • info.mouseOverIcon = [TEXTURE] -- An override icon when a button is moused over.
  • info.ignoreAsMenuSelection [nil, true] -- Never set the menu text/icon to this, even when this button is checked.

FAQ

Please go to FAQ Pages for more details.


Comments

  • To post a comment, please or register a new account.
Posts Quoted:
Reply
Clear All Quotes

About This Project

Categories

Members