comparison Turok/Layout/Dialog.lua @ 6:a9b8b0866ece

clear out log jam
author Nenue
date Sun, 21 Feb 2016 08:32:53 -0500
parents
children
comparison
equal deleted inserted replaced
5:8a9a6637f082 6:a9b8b0866ece
1 --- Dialog Generator
2 -- @file-author@
3 -- @project-revision@ @project-hash@
4 -- @file-revision@ @file-hash@
5 -- Created: 1/1/2016 3:37 PM
6 --- Framescript template for generating intelligible dialog panels
7 --[[
8 -- Frame << TkListFrame
9 -- {
10 -- Frame <rows> << TkListItem <-- Any number of list item frames with parentArray="rows"
11 -- {
12 :GetRow(row, values, id, offset) <-- Populates the uiobjects that make up the given row, with data from values[id], on display row offset
13 <opts> <-- Any layered region of child frame with parentArray=opts"
14 }
15 Button <buttons> <-- Any frame with parentArray="buttons"
16
17 .Click (button, list) <-- Defines results of using a control button
18 .Check (button, row, list) <-- Defines results of operating a row widget
19 .Wheel (list, delta) <-- Defines response to mousewheel action over the list panel
20 }
21
22 Globals:
23 TkList_Init ( object, values, offset, numRows )
24 Takes the return from CreateFrame and a table of values and establishes a scrollable list interface.
25
26 TkPanel_Init ( object )
27 TkList_Init without the scrollable list operations. Lines up control buttons and nothing else.
28 --]]
29 local TK_LIST_SPACING = 1
30 local TK_LIST_PADDING = 3
31 local TK_LIST_HEADING_SIZE = 26
32 local TK_LIST_ITEM_HEIGHT = 24
33 local TK_LIST_DISPLAY_ITEMS = 10
34
35 local print = function(...)
36 if _G.Devian and _G.DevianDB.workspace ~= 1 then
37 _G.print('Xui', ...)
38 end
39 end
40 -- GLOBALS: TkList_SetView, TkList_Init, Turok
41 local type, error, pairs, ipairs, tonumber, max, CreateFrame = type, error, pairs, ipairs, tonumber, math.max, CreateFrame
42 local checkval = function(valtype, t, fallback)
43 return (type(t) == valtype) and t or (fallback or error('Expected table reference, got '..type(t)))
44 end
45 local tableval = function(t, fallback)
46 return checkval('table', t, fallback or {})
47 end
48 local funcval = function(f, fallback)
49 return checkval('function', f, fallback or function() end)
50 end
51
52 --- Orders list row
53 -- Does an ipairs iteration over self.opts and distributes the referenced objects along the horizontal axis of 'self'
54 -- Note that members are only aligned horizontally; no column alignment is done. Widths can be set by datafunc to accomplish that.
55 local function TkListItem_Init (listrow)
56 if not listrow.opts then
57 print('no options to enumerate')
58 return
59 end
60 local rwidth = TK_LIST_PADDING*2
61 for i, z in pairs(listrow.opts) do
62 if i > 1 then
63 z:SetPoint('LEFT', listrow.opts[i-1], 'RIGHT', TK_LIST_SPACING, 0)
64 else
65 z:SetPoint('LEFT', listrow, 'LEFT', TK_LIST_PADDING, 0)
66 end
67 rwidth = rwidth + z:GetWidth()+TK_LIST_SPACING
68 z:Show()
69 end
70 listrow:SetSize(rwidth-TK_LIST_PADDING*2,TK_LIST_ITEM_HEIGHT)
71 listrow:Show()
72 print(rwidth)
73 return rwidth
74 end
75
76
77 ---
78 local function TkControls_Init(self)
79 local buttonsize = (self._dwidth - (#self.buttons -1) * TK_LIST_SPACING - TK_LIST_PADDING*2) / #self.buttons
80 for n, b in ipairs(self.buttons) do
81 --print('Spirit', buttonsize)
82 b:SetWidth(buttonsize)
83 b:SetPoint('TOPLEFT', self, 'BOTTOMLEFT', buttonsize* (n-1) + TK_LIST_SPACING * (n-1) + TK_LIST_PADDING, -TK_LIST_PADDING)
84 end
85 self.controls:SetHeight(self.buttons[1]:GetHeight()+ TK_LIST_PADDING*2)
86 end
87
88 --- Populates the list frame with items
89 function TkList_SetView(self, start_num, num_rows)
90 print(self, start_num, num_rows)
91 if not start_num then
92 start_num = self.offset
93 end
94
95 if not num_rows then
96 num_rows = self.num_rows
97 end
98
99 if start_num > #self.info then
100 start_num = #self.info - #self.info % num_rows
101 elseif start_num < 1 then
102 start_num = 1
103 end
104
105 print(' ', self:GetName(), start_num, num_rows, #self.info)
106 self.offset = start_num
107
108 for draw_num = 1, num_rows do
109 local actual_row = draw_num + start_num - 1
110 if not self.rows[draw_num] then
111 self.rows[draw_num] = CreateFrame('Frame', self:GetName()..'_Option_'..draw_num, self, 'TurokListItem')
112 self.rows[draw_num]:SetHeight(TK_LIST_ITEM_HEIGHT)
113 self.rows[draw_num].row_num = draw_num
114 end
115 self.rows[draw_num].actual_row = actual_row
116 local row = self.rows[draw_num]
117 if self.info[actual_row] then
118 print( actual_row, draw_num)
119 self.GetRow(row, self.info, actual_row, draw_num)
120 row:Show()
121 else
122 print('|cFF888888'..actual_row, draw_num)
123 row:Hide()
124 end
125 row:SetParent(self)
126 end
127 end
128
129 --- Prime TkListFrame template-spawn for use
130 -- @param self frame object to list-ify
131 -- @param info array of list item values
132 -- @param datafunc function that takes 1) frame object 2) info table 3) index number 4) row number
133 -- @param offset starting offset for initial view
134 function TkList_Init (self, info, offset, num_rows)
135 -- error checking
136 --[[if type(info) ~= 'table' then
137 error('arg #2 info must be an associative array')
138 end
139 if type(datafunc) ~= 'function' then
140 error('arg #3 needs a funcref or method name from the frame object')
141 end
142 --]]
143 self.GetRow = funcval(self.GetRow, function() end)
144 self.info = tableval(info, {})
145 for i, v in ipairs(info) do
146 print('Main', i, '=', v.spellName, v.spellTab)
147 self.max_row = i
148 end
149 print('Main', 'last row #', self.max_row)
150
151
152 -- obtain data contents
153 self._dwidth = 0
154 self.rows = {}
155 self.offset = offset and offset or 1
156 self.num_rows = (tonumber(num_rows) ~= nil) and num_rows or TK_LIST_DISPLAY_ITEMS
157 self.name:SetHeight(TK_LIST_HEADING_SIZE)
158 TkList_SetView(self, offset)
159
160 -- sort out the proper width
161 local rwidth = 1
162 local k = 0
163 for n, item in ipairs(self.rows) do
164 print(item:GetName())
165 if item:IsShown() then
166 if n > 1 then
167 item:SetPoint('TOPLEFT', self.rows[n-1], 'BOTTOMLEFT', 0, - TK_LIST_SPACING)
168 else
169 item:SetPoint('TOPLEFT', self, 'TOPLEFT', TK_LIST_PADDING, -(TK_LIST_PADDING+TK_LIST_HEADING_SIZE+TK_LIST_SPACING))
170 end
171 k = k+1
172 self._dwidth = max(self._dwidth, TkListItem_Init(item))
173 end
174 end
175
176 TkControls_Init(self)
177
178 self:SetSize(self._dwidth , (k*TK_LIST_ITEM_HEIGHT)+(TK_LIST_PADDING*2)+(k*TK_LIST_SPACING)+TK_LIST_HEADING_SIZE)
179 end
180
181 --- Set up for a non-list-style panel, no iterative controls
182 function TkPanel_Init(self)
183 self._dwidth = self:GetWidth()
184 TkControls_Init(self)
185 --self:SetSize(self._dwidth , (k*TK_LIST_ITEM_HEIGHT)+(TK_LIST_PADDING*2)+(k*TK_LIST_SPACING)+TK_LIST_HEADING_SIZE)
186 end