LibAddonMenu: Example how to detect panel Show/Hide

From ESOUI Wiki

Jump to: navigation, search

Prerequisites

Knowledge about Libraries within ESO, especially [LibAddonMenu2.0 https://github.com/sirinsidiator/ESO-LibAddonMenu/wiki]

Why would I need that?

Sometimes you need to register custom controls to your addon panel which should only be shown within this LAM panel, and not to others.
For example: You add a floating texture control on the UI which should be shown inside the LAM settings of your addon in order to move it around and set it's position.

In order to achieve this you need to first properly register the addon panel within LibAddonMenu-2.0.
In the example below panelData is the table containing the info about your LAM panel.

local LAM2 = LibStub("LibAddonMenu-2.0")
local myLAMAddonPanel = LAM2:RegisterAddonPanel("MyAddonOptions", panelData)

After registering the addon panel you can use the following example to register a callback functions to the
OnEffectivelyShown and
OnEffectivelyHidden
eventHandlers of your addon panel:

--Show the LibFeedback icon top right at the LAM panel
    myLAMAddonPanel:SetHandler("OnEffectivelyShown", function()
        --Put your code here: Your addon panel is shown
    end)
    --Hide the LibFeedBack icon
    myLAMAddonPanel:SetHandler("OnEffectivelyHidden", function()
        --Put your code here: Your addon panel is hidden
    end)

LibFeedback Example

You are able to combine this with other libraries like [LibFeedBack http://www.esoui.com/downloads/info2079-LibFeedback.html] in order to show/hide the small email icon of the LibFeedBack
at the top right corner of your addon panel.

The created LibFeedback button is returned (see below: myAddon.feedbackButton) so you can modify the button if needed or also add it to your addon namespace (see above in the example).
Good values for LibFeedBack's function to use for the anchoring within your LAM addonPanel are:

myAddon.feedbackButton = LibFeedback:initializeFeedbackWindow(myAddon, -- namespace/table of the addon -> LibFeedback will create a new entry ".feedbackWindow" which will reference the TopLevelControl (the box with text and buttons)
"Example Addon", -- The title string for the feedback window and the mails it sends
myLAMAddonPanel, -- The parent control where the mail button of LibFeedback will be anchored to
"@AddonAuthor", -- The destination for feedback (0 gold attachment) and donation mails
{TOPRIGHT , myLAMAddonPanel, TOPRIGHT , 0, -75}, -- The position of the mail button icon. These values will anchor it to the top right corner of your LAM panel (at the addon's name line)
{0,5000,50000, "https://www.genericexampleurl.com/somemoregenericiness"} -- The button info.
-- If 0: Will not attach any gold, and will say 'Send Note'
-- If non zero: Will auto attach that amount of gold. Button text will be 'Send amount'
-- If URL: Will show a dialog box and ask the user if they want to go to the URL. Will say 'Send $$'
-- Can theoretically do any number of options, it *should* handle them
"If you found a bug, have a request or a suggestion, or simply wish to donate, send a mail." 
-- The above will be displayed as a message below the title.

Example how to combine with the LAM panel like described above:
In your code check if myAddon.feedbackWindow and myAddon.feedbackButton are hidden (.IsHidden() ) and show/hide them via a toggle function.
Use this toggle function within the LAM callback functions for OnEffectivelShown and OnEffectivelHidden to show/hide the mail button at the addon panel.

Personal tools
Namespaces
Variants
Actions
Menu
Wiki
Toolbox