Skip to content

Commit

Permalink
Syn with UILibDropDownMenu from latest build
Browse files Browse the repository at this point in the history
  • Loading branch information
hizuro committed Jun 26, 2023
1 parent 30425c4 commit 46dce27
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
36 changes: 29 additions & 7 deletions LibDropDownMenu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ UIDROPDOWNMENU_MENU_VALUE = nil;
UIDROPDOWNMENU_SHOW_TIME = 2;
-- Default dropdown text height
UIDROPDOWNMENU_DEFAULT_TEXT_HEIGHT = nil;
-- Default dropdown width padding
UIDROPDOWNMENU_DEFAULT_WIDTH_PADDING = 25;
-- List of open menus
OPEN_DROPDOWNMENUS = {};

Expand Down Expand Up @@ -252,7 +254,7 @@ function UIDropDownMenuButton_OnEnter(self)
local level = self:GetParent():GetID() + 1;
local listFrame = _G["LibDropDownMenu_List"..level];
if ( not listFrame or not listFrame:IsShown() or select(2, listFrame:GetPoint(1)) ~= self ) then
ToggleDropDownMenu(self:GetParent():GetID() + 1, self.value, nil, nil, nil, nil, self.menuList, self);
ToggleDropDownMenu(self:GetParent():GetID() + 1, self.value, nil, nil, nil, nil, self.menuList, self, nil, self.menuListDisplayMode);
end
else
CloseDropDownMenus(self:GetParent():GetID() + 1);
Expand Down Expand Up @@ -333,6 +335,7 @@ function UIDropDownMenuButtonIcon_OnEnter(self)
local shouldShowIconTooltip = UIDropDownMenuButton_ShouldShowIconTooltip(button);

if shouldShowIconTooltip then

local tooltip = GetAppropriateTooltip();
tooltip:SetOwner(button, "ANCHOR_RIGHT");
if button.iconTooltipTitle then
Expand Down Expand Up @@ -371,6 +374,7 @@ info.isTitle = [nil, true] -- If it's a title the button is disabled and the f
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.arrowXOffset = [nil, NUMBER] -- Number of pixels to shift the button's icon to the left or right (positive numbers shift right, negative numbers shift left).
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
Expand All @@ -396,6 +400,7 @@ 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.menuList = [TABLE] -- This contains an array of info tables to be displayed as a child menu
info.menuListDisplayMode = [nil, "MENU"] -- If menuList is set, show the sub drop down with an override display mode.
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.topPadding = [nil, NUMBER] -- Extra spacing between buttons.
Expand All @@ -410,6 +415,7 @@ info.iconTooltipBackdropStyle = [nil, TABLE] -- Optional Backdrop style of the t
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
info.registerForRightClick [nil, true] -- Register dropdown buttons for right clicks
info.registerForAnyClick [nil, true] -- Register dropdown buttons for any clicks
]]

function UIDropDownMenu_CreateInfo()
Expand Down Expand Up @@ -520,7 +526,9 @@ function UIDropDownMenu_AddButton(info, level)
invisibleButton:Hide();
button:Enable();

if ( info.registerForRightClick ) then
if ( info.registerForAnyClick ) then
button:RegisterForClicks("AnyUp");
elseif ( info.registerForRightClick ) then
button:RegisterForClicks("LeftButtonUp", "RightButtonUp");
else
button:RegisterForClicks("LeftButtonUp");
Expand Down Expand Up @@ -631,9 +639,11 @@ function UIDropDownMenu_AddButton(info, level)
button.arg1 = info.arg1;
button.arg2 = info.arg2;
button.hasArrow = info.hasArrow;
button.arrowXOffset = info.arrowXOffset;
button.hasColorSwatch = info.hasColorSwatch;
button.notCheckable = info.notCheckable;
button.menuList = info.menuList;
button.menuListDisplayMode = info.menuListDisplayMode;
button.tooltipWhileDisabled = info.tooltipWhileDisabled;
button.noTooltipWhileEnabled = info.noTooltipWhileEnabled;
button.tooltipOnButton = info.tooltipOnButton;
Expand All @@ -656,6 +666,7 @@ function UIDropDownMenu_AddButton(info, level)
end

local expandArrow = _G[listFrameName.."Button"..index.."ExpandArrow"];
expandArrow:SetPoint("RIGHT", info.arrowXOffset or 0, 0);
expandArrow:SetShown(info.hasArrow);
expandArrow:SetEnabled(not info.disabled);

Expand Down Expand Up @@ -1100,7 +1111,7 @@ function HideDropDownMenu(level)
listFrame:Hide();
end

function ToggleDropDownMenu(level, value, dropDownFrame, anchorName, xOffset, yOffset, menuList, button, autoHideDelay)
function ToggleDropDownMenu(level, value, dropDownFrame, anchorName, xOffset, yOffset, menuList, button, autoHideDelay, overrideDisplayMode)
if ( not level ) then
level = 1;
end
Expand Down Expand Up @@ -1233,7 +1244,8 @@ function ToggleDropDownMenu(level, value, dropDownFrame, anchorName, xOffset, yO
_G[listFrameName.."MenuBackdrop"]:Hide();
else
-- Change list box appearance depending on display mode
if ( dropDownFrame and dropDownFrame.displayMode == "MENU" ) then
local displayMode = overrideDisplayMode or (dropDownFrame and dropDownFrame.displayMode) or nil;
if ( displayMode == "MENU" ) then
_G[listFrameName.."Backdrop"]:Hide();
_G[listFrameName.."MenuBackdrop"]:Show();
else
Expand Down Expand Up @@ -1421,19 +1433,29 @@ function UIDropDownMenu_ClearCustomFrames(self)
end
end

function UIDropDownMenu_MatchTextWidth(frame, minWidth, maxWidth)
local frameName = frame:GetName();
local newWidth = GetChild(frame, frameName, "Text"):GetUnboundedStringWidth() + UIDROPDOWNMENU_DEFAULT_WIDTH_PADDING;

if minWidth or maxWidth then
newWidth = Clamp(newWidth, minWidth or newWidth, maxWidth or newWidth);
end

UIDropDownMenu_SetWidth(frame, newWidth);
end

function UIDropDownMenu_SetWidth(frame, width, padding)
local frameName = frame:GetName();
GetChild(frame, frameName, "Middle"):SetWidth(width);
local defaultPadding = 25;
if ( padding ) then
frame:SetWidth(width + padding);
else
frame:SetWidth(width + defaultPadding + defaultPadding);
frame:SetWidth(width + UIDROPDOWNMENU_DEFAULT_WIDTH_PADDING + UIDROPDOWNMENU_DEFAULT_WIDTH_PADDING);
end
if ( padding ) then
GetChild(frame, frameName, "Text"):SetWidth(width);
else
GetChild(frame, frameName, "Text"):SetWidth(width - defaultPadding);
GetChild(frame, frameName, "Text"):SetWidth(width - UIDROPDOWNMENU_DEFAULT_WIDTH_PADDING);
end
frame.noResize = 1;
end
Expand Down
3 changes: 2 additions & 1 deletion LibDropDownMenu.toc
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
## Interface: 100100
## Interface-Wrath: 30401
## Interface-Wrath: 30402
## Interface-Classic: 11403
## Title: Lib: LibDropDownMenu
## Notes: Library providing downdown menu like blizzards DropDownMenu
## Author: Hizuro
## IconTexture: 986485
## Version: @project-version@
## OptionalDeps: LibStub, CallbackHandler-1.0

Expand Down

0 comments on commit 46dce27

Please sign in to comment.