table consistency changes

This commit is contained in:
Manuel Simon Hirsig
2016-12-04 18:20:12 +01:00
parent e6a6d2da46
commit a2140346e5
4 changed files with 120 additions and 108 deletions
+61 -52
View File
@@ -8,19 +8,25 @@ local gui = require 'aux.gui'
local ROW_HEIGHT = 39
function M.render(item_listing)
function M:render()
FauxScrollFrame_Update(item_listing.scroll_frame, getn(item_listing.item_records), getn(item_listing.rows), ROW_HEIGHT)
local offset = FauxScrollFrame_GetOffset(item_listing.scroll_frame)
if getn(self.item_records or empty) > getn(self.rows) then
self.content_frame:SetPoint('BOTTOMRIGHT', -15, 0)
else
self.content_frame:SetPoint('BOTTOMRIGHT', 0, 0)
end
local rows = item_listing.rows
FauxScrollFrame_Update(self.scroll_frame, getn(self.item_records), getn(self.rows), ROW_HEIGHT)
local offset = FauxScrollFrame_GetOffset(self.scroll_frame)
local rows = self.rows
for i, row in rows do
local item_record = item_listing.item_records[i + offset]
local item_record = self.item_records[i + offset]
if item_record then
row.item_record = item_record
if item_listing.selected and item_listing.selected(item_record) or row.mouseover then
if self.selected and self.selected(item_record) or row.mouseover then
row.highlight:Show()
elseif not row.mouse_over then
row.highlight:Hide()
@@ -42,71 +48,74 @@ function M.render(item_listing)
end
function M.new(parent, on_click, selected)
local content = CreateFrame('Frame', nil, parent)
content:SetPoint('TOPLEFT', 0, -51)
content:SetPoint('BOTTOMRIGHT', -15, 0)
local content_frame = CreateFrame('Frame', nil, parent)
content_frame:SetAllPoints()
local scroll_frame = CreateFrame('ScrollFrame', gui.unique_name, parent, 'FauxScrollFrameTemplate')
scroll_frame:SetScript('OnVerticalScroll', function(self, offset)
scroll_frame:SetScript('OnVerticalScroll', function()
FauxScrollFrame_OnVerticalScroll(ROW_HEIGHT, function() render(this.item_listing) end)
end)
scroll_frame:SetPoint('TOPLEFT', content, 'TOPLEFT', 0, 15)
scroll_frame:SetPoint('BOTTOMRIGHT', content, 'BOTTOMRIGHT', -4, -15)
scroll_frame:SetPoint('TOPLEFT', content_frame, 'TOPLEFT', 0, 29)
scroll_frame:SetPoint('BOTTOMRIGHT', content_frame, 'BOTTOMRIGHT', 0, 0)
local scrollBar = _G[scroll_frame:GetName() .. 'ScrollBar']
scrollBar:SetWidth(12)
local thumbTex = scrollBar:GetThumbTexture()
local scroll_bar = _G[scroll_frame:GetName() .. 'ScrollBar']
scroll_bar:ClearAllPoints()
scroll_bar:SetPoint('TOPRIGHT', parent, -4, 2)
scroll_bar:SetPoint('BOTTOMRIGHT', parent, -4, 4)
scroll_bar:SetWidth(10)
local thumbTex = scroll_bar:GetThumbTexture()
thumbTex:SetPoint('CENTER', 0, 0)
thumbTex:SetTexture(color.content.background())
thumbTex:SetHeight(50)
thumbTex:SetWidth(12)
_G[scrollBar:GetName() .. 'ScrollUpButton']:Hide()
_G[scrollBar:GetName() .. 'ScrollDownButton']:Hide()
thumbTex:SetHeight(150)
thumbTex:SetWidth(scroll_bar:GetWidth())
_G[scroll_bar:GetName() .. 'ScrollUpButton']:Hide()
_G[scroll_bar:GetName() .. 'ScrollDownButton']:Hide()
local rows = T
local row_index = 1
local max_height = content:GetHeight()
local max_height = content_frame:GetHeight()
local total_height = 0
while total_height + ROW_HEIGHT < max_height do
local row = CreateFrame('Frame', nil, content)
row:SetHeight(ROW_HEIGHT)
row:SetWidth(195)
row:SetPoint('TOPLEFT', content, 2, -((row_index-1) * ROW_HEIGHT))
row:EnableMouse(true)
row:SetScript('OnMouseDown', on_click)
row:SetScript('OnEnter', function()
row.mouseover = true
row.highlight:Show()
end)
row:SetScript('OnLeave', function()
row.mouseover = false
if not selected(row.item_record) then
row.highlight:Hide()
end
end)
local row = CreateFrame('Frame', nil, content_frame)
row:SetHeight(ROW_HEIGHT)
row:SetPoint('TOPLEFT', content_frame, 0, -((row_index - 1) * ROW_HEIGHT))
row:SetPoint('TOPRIGHT', content_frame, 0, -((row_index - 1) * ROW_HEIGHT))
row:EnableMouse(true)
row:SetScript('OnMouseDown', on_click)
row:SetScript('OnEnter', function()
row.mouseover = true
row.highlight:Show()
end)
row:SetScript('OnLeave', function()
row.mouseover = false
if not selected(row.item_record) then
row.highlight:Hide()
end
end)
row.item = gui.item(row)
row.item:SetScale(.9)
row.item:SetPoint('LEFT', 2.5, 0)
row.item:SetPoint('RIGHT', -2.5, 0)
row.item.button:SetScript('OnEnter', function()
info.set_tooltip(row.item_record.itemstring, this, 'ANCHOR_RIGHT')
end)
row.item.button:SetScript('OnLeave', function() GameTooltip:Hide() end)
row.item = gui.item(row)
row.item:SetScale(.9)
row.item:SetPoint('LEFT', 2.5, 0)
row.item:SetPoint('RIGHT', -2.5, 0)
row.item.button:SetScript('OnEnter', function()
info.set_tooltip(row.item_record.itemstring, this, 'ANCHOR_RIGHT')
end)
row.item.button:SetScript('OnLeave', function() GameTooltip:Hide() end)
local highlight = row:CreateTexture()
highlight:SetAllPoints(row)
highlight:Hide()
highlight:SetTexture(1, .9, .9, .1)
row.highlight = highlight
local highlight = row:CreateTexture()
highlight:SetAllPoints(row)
highlight:Hide()
highlight:SetTexture(1, .9, .9, .1)
row.highlight = highlight
rows[row_index] = row
row_index = row_index + 1
total_height = total_height + ROW_HEIGHT
rows[row_index] = row
row_index = row_index + 1
total_height = total_height + ROW_HEIGHT
end
local item_listing = {
selected = selected,
content_frame = content_frame,
scroll_frame = scroll_frame,
rows = rows,
}