vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | -- contains all selection components |
2 | components = {}; |
||
3 | |||
4 | function Selection_Initialize(component, name, callback) |
||
5 | components[component:GetName()] = {}; |
||
6 | local c = components[component:GetName()]; |
||
7 | c["values"] = {}; |
||
8 | c["names"] = {}; |
||
9 | c["index"] = 1; |
||
10 | c["callback"] = callback; |
||
11 | Selection_SetName(component, name); |
||
12 | end |
||
13 | |||
14 | -- sets component name (visible above control) |
||
15 | function Selection_SetName(component, name) |
||
16 | local c = components[component:GetName()]; |
||
17 | c["name"] = name; |
||
18 | getglobal(component:GetName().."Name"):SetText(name); |
||
19 | end |
||
20 | |||
21 | -- updates component selected name to match current index |
||
22 | function Selection_UpdateText(component) |
||
23 | local c = components[component:GetName()]; |
||
24 | getglobal(component:GetName().."Text"):SetText(c.names[c.index]); |
||
25 | end |
||
26 | |||
27 | function Selection_GetSelectedName(component) |
||
28 | local c = components[component:GetName()]; |
||
29 | return c.names[c.index]; |
||
30 | end |
||
31 | |||
32 | function Selection_GetSelectedValue(component) |
||
33 | local c = components[component:GetName()]; |
||
34 | return c.values[c.index]; |
||
35 | end |
||
36 | |||
37 | function Selection_AddSelection(component, value, name) |
||
38 | local c = components[component:GetName()]; |
||
39 | table.insert(c.values, value); |
||
40 | table.insert(c.names, name); |
||
41 | end |
||
42 | |||
43 | function Selection_SetSelectedValue(component, value) |
||
44 | local c = components[component:GetName()]; |
||
45 | c.index = value; |
||
46 | Selection_UpdateText(component); |
||
47 | c.callback(c.index); |
||
48 | end |
||
49 | |||
50 | function Selection_Prev(component) |
||
51 | local c = components[component:GetName()]; |
||
52 | if (c.index-1 < 1) then |
||
53 | return; |
||
54 | end |
||
55 | c.index = c.index - 1; |
||
56 | Selection_UpdateText(component); |
||
57 | c.callback(c.index); |
||
58 | end |
||
59 | |||
60 | function Selection_Next(component) |
||
61 | local c = components[component:GetName()]; |
||
62 | if (c.index+1 > table.getn(c.values)) then |
||
63 | return; |
||
64 | end |
||
65 | c.index = c.index + 1; |
||
66 | Selection_UpdateText(component); |
||
67 | c.callback(c.index); |
||
68 | end |