Thread Tools Display Modes
03-21-24, 01:11 PM   #1
Codger
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Mar 2021
Posts: 30
Post Button not showing on frame

I'm a beginner when it comes to addon development...
I created a simple addon with a frame and a button but the button is not showing up on the frame.
I've looked at a few other examples but can't see what I'm doing wrong.
I have bug sack/bug grabber enabled and not seeing any errors.
Any help is much appreciated.

Here is my lua file.

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. frame:Hide()
  12.  
  13. -- Create a button
  14. local button = AceGUI:Create("Button")
  15. button:SetText("Click Me!")
  16. button:SetWidth(200)
  17. button:SetCallback("OnClick", function() print("Button Clicked!") end)
  18.  
  19. -- Add the button to the frame
  20. frame:AddChild(button)
  21.  
  22. -- Create a minimap button
  23. local showFrame = false
  24. local icon = LibDBIcon:Register("MyAddon", {
  25.     icon = "Interface\\Icons\\Ability_Marksmanship",
  26.     OnClick = function(self, button)
  27.         if button == "LeftButton" then
  28.             frame:Show()
  29.         elseif button == "RightButton" then
  30.             frame:Hide()
  31.         end
  32.     end,
  33.     OnTooltipShow = function(tooltip)
  34.         tooltip:SetText("MyAddon")
  35.         tooltip:AddLine("Left-click to open", 1, 1, 1)
  36.         tooltip:AddLine("Right-click to close", 1, 1, 1)
  37.     end,
  38. })
  39.  
  40. -- Register the addon
  41. local addonName, addonTable = ...
  42. addonTable.frame = frame

Last edited by Codger : 03-23-24 at 02:29 PM. Reason: Add lua syntax highlighting
  Reply With Quote
03-21-24, 01:41 PM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,931
Code:
frame:Hide()
Will hide the frame until you show it (presumably with the minimap button)

If you start off commenting out the Hide() until you've finished creating the frame and getting it working properly and then worry about the mechanics of showing/hiding it might prove useful.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
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
03-21-24, 02:02 PM   #4
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,931
The game doesn't "destroy" widgets (frames, buttons etc). They remain until you /reload or logout.

I don't use Ace so I can only guess that at what releasing does, possibly some internal pool mechanaism for re-use. That said, just hiding/showing the frame to start with until you get more understanding of how Ace does things won't hurt.

Putting code blocks around code will make it more readable (the # or blue lua buttons above the edit box)
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 03-21-24 at 02:22 PM.
  Reply With Quote
03-21-24, 02:19 PM   #5
Codger
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Mar 2021
Posts: 30
Thanks again

The code looks so much better.
I really appreciate all the help you provide!!
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Button not showing on frame

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off