View Single Post
03-21-24, 01:53 PM   #3
Codger
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Mar 2021
Posts: 30
Works better but... question about when to release a widget

Thanks for the help. Moving the :hide call fixed the button issue.
I also commented out the line:
--frame:SetCallback("OnClose", function(widget) AceGUI:Release(widget) end)
and now the button shows up with when the frame is opened and closed which makes me wonder when I should be concerned about release the widgets? Do most addons leave the frame open?

Lua Code:
  1. -- Load the AceGUI and LibDBIcon libraries
  2. local AceGUI = LibStub("AceGUI-3.0")
  3. local LibDBIcon = LibStub("LibDBIcon-1.0")
  4.  
  5. -- Create a new frame
  6. local frame = AceGUI:Create("Frame")
  7. frame:SetTitle("MyAddon Frame")
  8. frame:SetStatusText("Example Status Text")
  9. --frame:SetCallback("OnClose", function(widget) AceGUI:Release(widget) end)
  10. frame:SetLayout("Flow")
  11.  
  12. -- Create a button
  13. local button = AceGUI:Create("Button")
  14. button:SetText("Click Me!")
  15. button:SetWidth(200)
  16. button:SetCallback("OnClick", function() print("Button Clicked!") end)
  17.  
  18. -- Add the button to the frame
  19. frame:AddChild(button)
  20.  
  21. --frame:Hide()
  22.  
  23. -- Create a minimap button
  24. local showFrame = false
  25. local icon = LibDBIcon:Register("MyAddon", {
  26.     icon = "Interface\\Icons\\Ability_Marksmanship",
  27.     OnClick = function(self, button)
  28.         if button == "LeftButton" then
  29.             frame:Show()
  30.         elseif button == "RightButton" then
  31.             frame:Hide()
  32.         end
  33.     end,
  34.     OnTooltipShow = function(tooltip)
  35.         tooltip:SetText("MyAddon")
  36.         tooltip:AddLine("Left-click to open", 1, 1, 1)
  37.         tooltip:AddLine("Right-click to close", 1, 1, 1)
  38.     end,
  39. })
  40.  
  41. -- Register the addon
  42. local addonName, addonTable = ...
  43. addonTable.frame = frame

Last edited by Codger : 03-23-24 at 02:31 PM. Reason: Added code
  Reply With Quote