Details | Compare with Previous | View Log
Line No. | Rev | Author | Line |
---|---|---|---|
1 | 10 | Seerah-7 | --[[descriptionData = { |
2 | Seerah-7 | type = "description", |
|
3 | Seerah-7 | title = "My Title", --(optional) |
|
4 | Seerah-7 | text = "My description text to display.", |
|
5 | Seerah-7 | width = "full", --or "half" (optional) |
|
6 | 11 | Seerah-7 | reference = "MyAddonDescription" --(optional) unique global reference to control |
7 | 10 | Seerah-7 | } ]] |
8 | Seerah-7 | ||
9 | Seerah-7 | ||
10 | 14 | Seerah-7 | local widgetVersion = 4 |
11 | 10 | Seerah-7 | local LAM = LibStub("LibAddonMenu-2.0") |
12 | Seerah-7 | if not LAM:RegisterWidget("description", widgetVersion) then return end |
|
13 | Seerah-7 | ||
14 | Seerah-7 | local wm = WINDOW_MANAGER |
|
15 | 14 | Seerah-7 | local tinsert = table.insert |
16 | 10 | Seerah-7 | |
17 | 14 | Seerah-7 | local function UpdateValue(control) |
18 | Seerah-7 | if control.title then |
|
19 | Seerah-7 | control.title:SetText(control.data.title) |
|
20 | Seerah-7 | end |
|
21 | Seerah-7 | control.desc:SetText(control.data.text) |
|
22 | Seerah-7 | end |
|
23 | Seerah-7 | ||
24 | 10 | Seerah-7 | function LAMCreateControl.description(parent, descriptionData, controlName) |
25 | 11 | Seerah-7 | local control = wm:CreateTopLevelWindow(controlName or descriptionData.reference) |
26 | 10 | Seerah-7 | control:SetResizeToFitDescendents(true) |
27 | 13 | Seerah-7 | control:SetParent(parent.scroll or parent) |
28 | 10 | Seerah-7 | local isHalfWidth = descriptionData.width == "half" |
29 | Seerah-7 | if isHalfWidth then |
|
30 | Seerah-7 | control:SetDimensionConstraints(250, 55, 250, 100) |
|
31 | Seerah-7 | control:SetDimensions(250, 55) |
|
32 | Seerah-7 | else |
|
33 | Seerah-7 | control:SetDimensionConstraints(510, 40, 510, 100) |
|
34 | Seerah-7 | control:SetDimensions(510, 30) |
|
35 | Seerah-7 | end |
|
36 | Seerah-7 | ||
37 | Seerah-7 | control.desc = wm:CreateControl(nil, control, CT_LABEL) |
|
38 | Seerah-7 | local desc = control.desc |
|
39 | Seerah-7 | desc:SetVerticalAlignment(TEXT_ALIGN_TOP) |
|
40 | Seerah-7 | desc:SetFont("ZoFontGame") |
|
41 | Seerah-7 | desc:SetText(descriptionData.text) |
|
42 | Seerah-7 | desc:SetWidth(isHalfWidth and 250 or 510) |
|
43 | Seerah-7 | ||
44 | Seerah-7 | if descriptionData.title then |
|
45 | Seerah-7 | control.title = wm:CreateControl(nil, control, CT_LABEL) |
|
46 | Seerah-7 | local title = control.title |
|
47 | Seerah-7 | title:SetWidth(isHalfWidth and 250 or 510) |
|
48 | Seerah-7 | title:SetAnchor(TOPLEFT, control, TOPLEFT) |
|
49 | Seerah-7 | title:SetFont("ZoFontWinH4") |
|
50 | Seerah-7 | title:SetText(descriptionData.title) |
|
51 | Seerah-7 | desc:SetAnchor(TOPLEFT, title, BOTTOMLEFT) |
|
52 | Seerah-7 | else |
|
53 | Seerah-7 | desc:SetAnchor(TOPLEFT) |
|
54 | Seerah-7 | end |
|
55 | Seerah-7 | ||
56 | Seerah-7 | control.panel = parent.panel or parent --if this is in a submenu, panel is its parent |
|
57 | Seerah-7 | control.data = descriptionData |
|
58 | 14 | Seerah-7 | |
59 | Seerah-7 | control.UpdateValue = UpdateValue |
|
60 | 10 | Seerah-7 | |
61 | 14 | 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 |
62 | Seerah-7 | tinsert(control.panel.controlsToRefresh, control) |
|
63 | Seerah-7 | end |
|
64 | Seerah-7 | ||
65 | 10 | Seerah-7 | return control |
66 | Seerah-7 | ||
67 | Seerah-7 | end |