ESOUI SVN LibAddonMenu

[/] [trunk/] [LibAddonMenu-2.0/] [LibAddonMenu-2.0/] [controls/] [custom.lua] - Blame information for rev 50

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 36 Seerah-7
--[[customData = {
2 Seerah-7
        type = "custom",
3 50 Seerah-7
        reference = "MyAddonCustomControl",     --(optional) unique name for your control to use as reference
4 48 Seerah-7
        refreshFunc = function(customControl) end,      --(optional) function to call when panel/controls refresh
5 36 Seerah-7
        width = "full", --or "half" (optional)
6 Seerah-7
}       ]]
7 Seerah-7
 
8 48 Seerah-7
local widgetVersion = 4
9 36 Seerah-7
local LAM = LibStub("LibAddonMenu-2.0")
10 Seerah-7
if not LAM:RegisterWidget("custom", widgetVersion) then return end
11 Seerah-7
 
12 Seerah-7
local wm = WINDOW_MANAGER
13 49 Seerah-7
local tinsert = table.insert
14 36 Seerah-7
 
15 48 Seerah-7
local function UpdateValue(control)
16 Seerah-7
        if control.data.refreshFunc then
17 Seerah-7
                control.data.refreshFunc(control)
18 Seerah-7
        end
19 Seerah-7
end
20 Seerah-7
 
21 36 Seerah-7
function LAMCreateControl.custom(parent, customData, controlName)
22 Seerah-7
        local control = wm:CreateTopLevelWindow(controlName or customData.reference)
23 Seerah-7
        control:SetResizeToFitDescendents(true)
24 45 Seerah-7
        control:SetParent(parent.scroll or parent)
25 36 Seerah-7
 
26 Seerah-7
        local isHalfWidth = customData.width == "half"
27 Seerah-7
        if isHalfWidth then     --note these restrictions
28 Seerah-7
                control:SetDimensionConstraints(250, 55, 250, 100)
29 Seerah-7
                control:SetDimensions(250, 55)
30 Seerah-7
        else
31 Seerah-7
                control:SetDimensionConstraints(510, 30, 510, 100)
32 Seerah-7
                control:SetDimensions(510, 30)
33 Seerah-7
        end
34 Seerah-7
 
35 Seerah-7
        control.panel = parent.panel or parent  --if this is in a submenu, panel is its parent
36 Seerah-7
        control.data = customData
37 Seerah-7
 
38 48 Seerah-7
        control.UpdateValue = UpdateValue
39 Seerah-7
 
40 Seerah-7
        if control.panel.data.registerForRefresh or control.panel.data.registerForDefaults then --if our parent window wants to refresh controls, then add this to the list
41 Seerah-7
                tinsert(control.panel.controlsToRefresh, control)
42 Seerah-7
        end
43 Seerah-7
 
44 36 Seerah-7
        return control
45 Seerah-7
end