View Single Post
02-21-24, 12:31 AM   #10
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,894
Programs are stupid. You have to tell them exactly what you want. Maybe something like: (Left buton down, shift-key down = drag. right button = hide button. left button no shift-key toggle show/hide the frame (f))

Lua Code:
  1. local addonName, addon = ...
  2.  
  3. local CELL_WIDTH = 400
  4. local CELL_HEIGHT = 80
  5. local NUM_CELLS = 2
  6.  
  7. local data = {}
  8.  
  9. local f = CreateFrame("Frame", "SimpleScrollFrameTableDemo", UIParent, "BasicFrameTemplateWithInset")
  10.  
  11. -- Create the button here
  12. local btn = CreateFrame("Button", nil, UIParent, "UIPanelButtonTemplate")
  13.  
  14. local function updateData() --commented out because addon.db hasn't been created... in the code at least
  15.     wipe(data)
  16.     for _, item in ipairs(addon.db) do
  17.         tinsert(data, {item.announce[GetLocale()], item.icon, item.name})
  18.     end
  19. end
  20.  
  21. f:SetSize(CELL_WIDTH * NUM_CELLS + 80, 600)
  22. f:SetPoint("CENTER")
  23. f:Hide()
  24. f:SetMovable(true)
  25. f:SetScript("OnMouseDown", f.StartMoving)
  26. f:SetScript("OnMouseUp", f.StopMovingOrSizing)
  27.  
  28. -- I added this OnHide script
  29. f:SetScript("OnHide", function()
  30.     btn:Show()
  31. end)
  32.  
  33. f.scrollFrame = CreateFrame("ScrollFrame", nil, f, "UIPanelScrollFrameTemplate")
  34. f.scrollFrame:SetPoint("TOPLEFT", 12, -32)
  35. f.scrollFrame:SetPoint("BOTTOMRIGHT", -34, 8)
  36.  
  37. f.scrollFrame.scrollChild = CreateFrame("Frame", nil, f.scrollFrame)
  38. f.scrollFrame.scrollChild:SetSize(100, 100)
  39. f.scrollFrame.scrollChild:SetPoint("TOPLEFT", 5, -5)
  40. f.scrollFrame:SetScrollChild(f.scrollFrame.scrollChild)
  41.  
  42. local content = f.scrollFrame.scrollChild
  43. content.rows = {}
  44.  
  45. local function updateList()
  46.     for i = 1, #data do
  47.         if not content.rows[i] then
  48.             local button = CreateFrame("Button", nil, content)
  49.             button:SetSize(CELL_WIDTH * NUM_CELLS, CELL_HEIGHT)
  50.             button:SetPoint("TOPLEFT", 0, -(i - 1) * CELL_HEIGHT)
  51.             button.columns = {}
  52.  
  53.             button.columns[1] = button:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
  54.             button.columns[1]:SetPoint("LEFT", (0) * CELL_WIDTH, 0)
  55.  
  56.             button.columns[2] = button:CreateTexture()
  57.             button.columns[2]:SetPoint("LEFT", 410, 0, (1) * CELL_WIDTH, 0)
  58.  
  59.             button.columns[3] = button:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
  60.             button.columns[3]:SetPoint("LEFT", 480, 0, (2) * CELL_WIDTH, 0)
  61.  
  62.             content.rows[i] = button
  63.         end
  64.  
  65.         content.rows[i].columns[1]:SetText(data[i][1])
  66.         content.rows[i].columns[2]:SetTexture(data[i][2])
  67.         content.rows[i].columns[3]:SetText(data[i][3])
  68.  
  69.         content.rows[i]:Show()
  70.     end
  71.  
  72.     for i = #data + 1, #content.rows do
  73.         content.rows[i]:Hide()
  74.     end
  75. end
  76.  
  77.  
  78. -- Set your button options here
  79. local btn = CreateFrame("Button", "Hubb777MovingButton", UIParent, "UIPanelButtonTemplate")
  80. btn:SetPoint("CENTER")
  81. btn:SetSize(100, 40)
  82. btn:SetText("Click me")
  83. btn:SetMovable(true)
  84. btn:RegisterForDrag('LeftButton')
  85. btn:RegisterForClicks("AnyDown", "AnyUp")
  86. btn:SetUserPlaced(true)
  87. btn:SetScript('OnDragStart', function(self, button, down)
  88.     if button == "LeftButton" and IsShiftKeyDown() then
  89.         self:StartMoving()
  90.     end
  91. end)
  92. btn:SetScript('OnDragStop', function(self)
  93.     self:StopMovingOrSizing()
  94. end)
  95. btn:SetScript("OnMouseUp", function(self, button, ...)
  96.     if (button == "RightButton" and self:IsVisible()) then
  97.         self:Hide()
  98.     elseif button == "LeftButton" and not IsShiftKeyDown() then
  99.         updateData()
  100.         updateList()
  101.         f:Show()
  102.     end
  103. end)
  104.  
  105. SLASH_HUBB1 = "/hubb"
  106. SlashCmdList["HUBB"] = function(msg)
  107.     updateData()
  108.     updateList()
  109.     f:Show()
  110. end

You possibly want a way to get the button back after it's hidden other than a /reaload but may not, it's not clear?
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 02-21-24 at 12:33 AM.
  Reply With Quote