/
local MAX_LIST_SIZE = 15 |
------------------------------------------------------------------------- |
------------------------------------------------------------------------ |
local CreateList |
local function OpenScrollingDropdown(dropdown) |
local list = dropdown.list |
if not list then |
list = CreateList(dropdown) |
dropdown.list = list |
end |
local show = not list:IsShown() |
CloseDropDownMenus() |
if show then |
list:Show() |
list:Raise() |
local selectedIndex |
local items, selected = dropdown.items, dropdown.selected |
for i = 1, #items do |
if items[i] == selected then |
selectedIndex = i |
break |
end |
end |
if selectedIndex then |
local _, maxScroll = list.scrollFrame.ScrollBar:GetMinMaxValues() |
list.scrollFrame.ScrollBar:SetValue((maxScroll / (#items - 15)) * (selectedIndex - 5)) |
-- #TODO: where does this 15 come from in BlizzBugsSuck ??? |
end |
end |
end |
local function CloseScrollingDropdowns(_, _, dropDownFrame, _, _, _, _, clickedButton) |
for i = 1, #lib.listFrames do |
lib.listFrames[i]:Hide() |
end |
end |
hooksecurefunc("CloseDropDownMenus", CloseScrollingDropdowns) |
hooksecurefunc("ToggleDropDownMenu", CloseScrollingDropdowns) |
------------------------------------------------------------------------ |
local function Frame_OnEnter(self) |
if self.OnEnter then |
self:OnEnter() |
end |
end |
------------------------------------------------------------------------- |
------------------------------------------------------------------------ |
local function ListButton_OnClick(self) |
local dropdown = self:GetParent():GetParent() |
end |
PlaySound("UChatScrollButton") |
if dropdown.keepShownOnClick then |
OpenScrollingDropdown(dropdown) |
end |
end |
local function CreateListButton(parent) |
local buttons = self.buttons |
local dropdown = self:GetParent() |
local items = dropdown.items |
if dropdown.PreUpdate then |
dropdown:PreUpdate(items) |
end |
local listSize = min(#items, MAX_LIST_SIZE) |
local scrollFrame = self.scrollFrame |
local width = 0 |
for i = 1, #items do |
local item = items[i] |
self.text:SetText(item) |
if type(item) == "table" then |
self.text:SetText(item.text or item.value) |
else |
self.text:SetText(item) |
end |
width = max(width, self.text:GetStringWidth()) |
end |
local item = items[index] |
if item then |
button.value = item |
button:SetText(item) |
if item == selected then |
button.check:Show() |
if type(item) == "table" then |
button.value = item.value |
button:SetText(item.text or item.value) |
button.check:SetShown(item.selected or item.value == selected) |
else |
button.check:Hide() |
button.value = item |
button:SetText(item) |
button.check:SetShown(item == selected) |
end |
button:SetWidth(width) |
end |
local id = 0 |
local function CreateList(parent) |
function CreateList(parent) -- local |
local dropdown = parent |
if dropdown.list then |
return dropdown.list |
button:SetPoint("TOPLEFT", 15, -15) |
end |
t[i] = button |
return button |
end }) |
return list |
end |
------------------------------------------------------------------------- |
------------------------------------------------------------------------ |
local function CloseScrollingDropdowns(_, _, dropDownFrame, _, _, _, _, clickedButton) |
for i = 1, #lib.listFrames do |
lib.listFrames[i]:Hide() |
end |
end |
hooksecurefunc("CloseDropDownMenus", CloseScrollingDropdowns) |
hooksecurefunc("ToggleDropDownMenu", CloseScrollingDropdowns) |
local function Button_OnClick(self) |
PlaySound("igMainMenuOptionCheckBoxOn") |
local dropdown = self:GetParent() |
local list = dropdown.list |
if not list then |
list = CreateList(dropdown) |
dropdown.list = list |
end |
local show = not list:IsShown() |
CloseDropDownMenus() |
if show then |
list:Show() |
list:Raise() |
local selectedIndex |
local items, selected = dropdown.items, dropdown.selected |
for i = 1, #items do |
if items[i] == selected then |
selectedIndex = i |
break |
end |
end |
if selectedIndex then |
local _, maxScroll = list.scrollFrame.ScrollBar:GetMinMaxValues() |
list.scrollFrame.ScrollBar:SetValue((maxScroll / (#items - 15)) * (selectedIndex - 5)) |
-- #TODO: where does this 15 come from in BlizzBugsSuck ??? |
end |
end |
OpenScrollingDropdown(dropdown) |
end |
local function Button_OnEnter(self) |
self.items = list |
end |
function methods:SetKeepShownOnClick(value) |
self.keepShownOnClick = value |
end |
function methods:Enable() |
self.labelText:SetFontObject(GameFontNormal) |
self.valueText:SetFontObject(GameFontHighlightSmall) |
------------------------------------------------------------------------ |
function lib:New(parent, name, tooltipText, items) |
function lib:New(parent, name, tooltipText, items, keepShownOnClick) |
assert(type(parent) == "table" and type(rawget(parent, 0)) == "userdata", "PhanxConfig-ScrollingDropdown: parent must be a frame") |
local dropdown = CreateFrame("Frame", nil, parent) |
dropdown:SetLabel(name) |
dropdown:SetTooltip(tooltipText) |
dropdown:SetList(items) |
dropdown.keepShownOnClick = keepShownOnClick |
-- backwards compat? |
dropdown.dropdown = dropdown |