LibAddonMenu: Example how to change controls

From ESOUI Wiki

Revision as of 13:50, 30 December 2021 by Baertram (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Please read this WIKI entry first to understand that LAM controls will be nil until your addon's LAM panel wil be created: LibAddonMenu:_Example_how_to_detect_panel_controls_created

Contents

Reference your LAM controls

After your addon's LAM panel was created the controls exist with default LAM names, only provided to LAM internally and not globaly accessible!
This means: Your controls won't be accesible via addons if they were not created with a unique "reference"!

To define a reference to your LAM control provide a "reference" tag to your data table of the control. e.g. a dropdown control:

         local lamOptions = {
                        {
                            type = 'dropdown',
                            name = "Any name for your control",
                            tooltip = "Any tooltip for your control",
                            choices = {[1] = "Hello", [2] = "World", [3]= "Be", [4] = "Good"},
                            choicesValues = {[1] = 1, [2] = 2, [3]= 3, [4] = 4}, --choicesValues will use the values provided in he setFunc, instead of the strings used at the "choices" table
                            choicesTooltips = {[1] = "Hello - Tooltip1", [2] = "World - Tooltip2", [3]= "Be - Tooltip3", [4] = "Good - Tooltip4"},
                            getFunc = function() return mySavedVariables.option1 end,
                            setFunc = function(value)
                                mySavedVariables.option1 = value --will use the value of "choicesValues" if "choicesValues" is provided, else it will use the value of "choices"
                            end,
                            reference = "MYADDON_SETTINGS_DROPDOWN_OPTION1",
                            default = myDefaultSavedVariables.option1,
                        },
       }

The control will be created with the name "MYADDON_SETTINGS_DROPDOWN_OPTION1", so it will be available in the global table _G["MYADDON_SETTINGS_DROPDOWN_OPTION1"] (which is the same as GetControl(MYADDON_SETTINGS_DROPDOWN_OPTION1) or WINDOW_MANAGER:GetControlByName("MYADDON_SETTINGS_DROPDOWN_OPTION1").

After the LAM panel of your addon was created the control is given and you are able to use it and call functions of it, or update their "data" table, or other attributes.

Dropdownbox:UpdateChoices

Dropdown controls got a function called UpdateChoices where you are able to pass in new choices, values and tooltips

<referencedControl>:UpdateChoices(table choices, nilable table choicesValues, nilable table choicesTooltips)


So this would update your LAM control with new choices:

 local function updateLAMDropdown(lamDropdownRef, p_choices, p_choicesValues, p_choicesTooltips)
    if lamDropdownRef== nil then return end
    lamDropdownRef:UpdateChoices(p_choices, p_choicesValues, p_choicesTooltips)
 end
 
 --Within your LAM setFunc of another control or somewhere else:
 updateLAMDropdown(MYADDON_SETTINGS_DROPDOWN_OPTION1, {"blubb"}, {1}, {"blubb - tooltip"})


Other controls (Editbox, checkbox, colorpicker, ...):UpdateValue

Other LAM controls do not provide an UpdateChoices function but another similar one
e.g. edit/checkbox/colorpickers (but also dropdown box) controls provide

<referencedLamControl>:UpdateValue(param1, param2) 
--Please check which parameters are given by reading the code of function "UpdateValue" at the folder live/AddOns/LibAddonMenu-2.0/controls/<the type of control you want to update>.lua
--e.g. a checkbox/editbox/iconPicker got parameters "forceDefault, value", but a color picker got the parameters "forceDefault, valueR, valueG, valueB, valueA"

This will update the value of the control (if a dropdownbox get's the value updated the currently selected entry will be changed!).

Description control:UpdateValue

A description LAM control cannot pass any value to the UpdateValue function!
You need to update the data table of the description control, attribute "title", prior to the call to :UpdateValue()
The data table is the table you have created to define the name, tooltip, type, setFunc, etc. for your LAM control,
and it is stored directly at the control. So if you got the reference your can change the data table via

   <refrencedLAMControl>.data.title = "New description text"
   <refrencedLAMControl>:UpdateValue()


Header control:UpdateValue

A headerLAM control cannot pass any value to the UpdateValue function!
You need to update the data table of the header control, attribute "name" prior to the call to :UpdateValue()
The data table is the table you have created to define the name, tooltip, type, setFunc, etc. for your LAM control,
and it is stored directly at the control. So if you got the reference your can change the data table via

   <refrencedLAMControl>.data.name= "New header text"
   <refrencedLAMControl>:UpdateValue()
Personal tools
Namespaces
Variants
Actions
Menu
Wiki
Toolbox