From d7f00c1f700b77c3a1b7dd8f073602c8b1ff26a9 Mon Sep 17 00:00:00 2001 From: Hizuro Date: Wed, 24 Jul 2024 19:10:21 +0200 Subject: [PATCH] Sync with UILibDropDownMenu from latest retail build 55818 --- LibDropDownMenu.lua | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/LibDropDownMenu.lua b/LibDropDownMenu.lua index a6f1153..10dd879 100644 --- a/LibDropDownMenu.lua +++ b/LibDropDownMenu.lua @@ -269,7 +269,7 @@ function UIDropDownMenuButton_OnEnter(self) if ( self.tooltipTitle and not self.noTooltipWhileEnabled and not UIDropDownMenuButton_ShouldShowIconTooltip(self) ) then if ( self.tooltipOnButton ) then local tooltip = GetAppropriateTooltip(); - tooltip:SetOwner(self, "ANCHOR_RIGHT"); + tooltip:SetOwner(self, self.tooltipAnchor or "ANCHOR_RIGHT"); GameTooltip_SetTitle(tooltip, self.tooltipTitle); if self.tooltipInstruction then GameTooltip_AddInstructionLine(tooltip, self.tooltipInstruction); @@ -317,7 +317,7 @@ end function UIDropDownMenuButton_ShouldShowIconTooltip(self) if self.Icon and (self.iconTooltipTitle or self.iconTooltipText) and (self.icon or self.mouseOverIcon) then - return GetMouseFocus() == self.Icon; + return self.Icon:IsMouseMotionFocus(); end return false; end @@ -400,6 +400,7 @@ info.tooltipWarning = [nil, STRING] -- Warning-style text of the tooltip shown o info.tooltipInstruction = [nil, STRING] -- Instruction-style 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.tooltipBackdropStyle = [nil, TABLE] -- Optional Backdrop style of the tooltip shown on mouseover +info.tooltipAnchor = [nil, STRING] -- Pass a custom tooltip anchor (Default is "ANCHOR_RIGHT") 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 @@ -494,6 +495,11 @@ function UIDropDownMenu_AddSpace(level) UIDropDownMenu_AddButton(spaceInfo, level); end +local function UIDropDownMenu_IsDisplayModeMenu() + local frame = UIDROPDOWNMENU_OPEN_MENU; + return frame and frame.displayMode == "MENU"; +end + function UIDropDownMenu_AddButton(info, level) --[[ Might to uncomment this if there are performance issues @@ -641,6 +647,7 @@ function UIDropDownMenu_AddButton(info, level) button.tooltipInstruction = info.tooltipInstruction; button.tooltipWarning = info.tooltipWarning; button.tooltipBackdropStyle = info.tooltipBackdropStyle; + button.tooltipAnchor = info.tooltipAnchor; button.arg1 = info.arg1; button.arg2 = info.arg2; button.hasArrow = info.hasArrow; @@ -700,15 +707,12 @@ function UIDropDownMenu_AddButton(info, level) end -- Adjust offset if displayMode is menu - local frame = UIDROPDOWNMENU_OPEN_MENU; - if ( frame and frame.displayMode == "MENU" ) then - if ( not info.notCheckable ) then - xPos = xPos - 6; - end + if (not info.notCheckable) and UIDropDownMenu_IsDisplayModeMenu() then + xPos = xPos - 6; end -- If no open frame then set the frame to the currently initialized frame - frame = frame or UIDROPDOWNMENU_INIT_MENU; + local frame = frame or UIDROPDOWNMENU_INIT_MENU; if ( info.leftPadding ) then xPos = xPos + info.leftPadding; @@ -1056,17 +1060,23 @@ function UIDropDownMenu_GetSelectedID(frame) if ( frame.selectedID ) then return frame.selectedID; else + local selectedName = UIDropDownMenu_GetSelectedName(frame); + local selectedValue = UIDropDownMenu_GetSelectedValue(frame); + if ( not selectedName and not selectedValue ) then + return nil; + end + -- If no explicit selectedID then try to send the id of a selected value or name local listFrame = _G["LibDropDownMenu_List"..UIDROPDOWNMENU_MENU_LEVEL]; for i=1, listFrame.numButtons do local button = _G["LibDropDownMenu_List"..UIDROPDOWNMENU_MENU_LEVEL.."Button"..i]; -- See if checked or not - if ( UIDropDownMenu_GetSelectedName(frame) ) then - if ( button:GetText() == UIDropDownMenu_GetSelectedName(frame) ) then + if ( selectedName ) then + if ( button:GetText() == selectedName ) then return i; end - elseif ( UIDropDownMenu_GetSelectedValue(frame) ) then - if ( button.value == UIDropDownMenu_GetSelectedValue(frame) ) then + elseif ( selectedValue ) then + if ( button.value == selectedValue ) then return i; end end @@ -1150,6 +1160,7 @@ function ToggleDropDownMenu(level, value, dropDownFrame, anchorName, xOffset, yO end if ( listFrame:IsShown() and (UIDROPDOWNMENU_OPEN_MENU == tempFrame) ) then listFrame:Hide(); + return false; else -- Set the dropdownframe scale local uiScale; @@ -1274,7 +1285,7 @@ function ToggleDropDownMenu(level, value, dropDownFrame, anchorName, xOffset, yO UIDropDownMenu_Initialize(dropDownFrame, dropDownFrame.initialize, nil, level, menuList); -- If no items in the drop down don't show it if ( listFrame.numButtons == 0 ) then - return; + return false; end listFrame.onShow = dropDownFrame.listFrameOnShow; @@ -1286,7 +1297,7 @@ function ToggleDropDownMenu(level, value, dropDownFrame, anchorName, xOffset, yO -- Hack will fix this in next revision of dropdowns if ( not x or not y ) then listFrame:Hide(); - return; + return false; end listFrame.onHide = dropDownFrame.onHide; @@ -1359,6 +1370,7 @@ function ToggleDropDownMenu(level, value, dropDownFrame, anchorName, xOffset, yO listFrame.parentID = anchorFrame:GetID(); listFrame:SetPoint(point, anchorFrame, relativePoint, xOffset, yOffset); end + return true; end end