From a2140346e5680802140b606bd79681b2c84817b7 Mon Sep 17 00:00:00 2001 From: Manuel Simon Hirsig Date: Sun, 4 Dec 2016 18:20:12 +0100 Subject: [PATCH] table consistency changes --- gui/auction_listing.lua | 2 +- gui/item_listing.lua | 113 ++++++++++++++++++++++------------------ gui/listing.lua | 74 +++++++++++++------------- tabs/post/frame.lua | 39 ++++++++------ 4 files changed, 120 insertions(+), 108 deletions(-) diff --git a/gui/auction_listing.lua b/gui/auction_listing.lua index e77aac1..e03fd41 100644 --- a/gui/auction_listing.lua +++ b/gui/auction_listing.lua @@ -952,8 +952,8 @@ function M.new(parent, config) local scrollBar = _G[scrollFrame:GetName() .. 'ScrollBar'] scrollBar:ClearAllPoints() - scrollBar:SetPoint('BOTTOMRIGHT', rt, -4, 4) scrollBar:SetPoint('TOPRIGHT', rt, -4, -HEAD_HEIGHT) + scrollBar:SetPoint('BOTTOMRIGHT', rt, -4, 4) scrollBar:SetWidth(10) local thumbTex = scrollBar:GetThumbTexture() thumbTex:SetPoint('CENTER', 0, 0) diff --git a/gui/item_listing.lua b/gui/item_listing.lua index f16643e..35ac8fd 100644 --- a/gui/item_listing.lua +++ b/gui/item_listing.lua @@ -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, } diff --git a/gui/listing.lua b/gui/listing.lua index 4041f5c..271a040 100644 --- a/gui/listing.lua +++ b/gui/listing.lua @@ -5,12 +5,10 @@ include 'aux' local gui = require 'aux.gui' -local ST_COUNT = 0 - -local ST_ROW_HEIGHT = 15 -local ST_ROW_TEXT_SIZE = 14 -local ST_HEAD_HEIGHT = 27 -local ST_HEAD_SPACE = 2 +local ROW_HEIGHT = 15 +local ROW_TEXT_SIZE = 14 +local HEAD_HEIGHT = 27 +local HEAD_SPACE = 2 local DEFAULT_COL_INFO = {{width=1}} local handlers = { @@ -56,17 +54,17 @@ local handlers = { local methods = { Update = function(self) if getn(self.colInfo) > 1 or self.colInfo[1].name then - self.sizes.headHeight = ST_HEAD_HEIGHT + self.headHeight = HEAD_HEIGHT else - self.sizes.headHeight = 0 + self.headHeight = 0 end - self.sizes.numRows = max(floor((self:GetParent():GetHeight() - self.sizes.headHeight - ST_HEAD_SPACE) / ST_ROW_HEIGHT), 0) + self.numRows = max(floor((self:GetParent():GetHeight() - self.headHeight - HEAD_SPACE) / ROW_HEIGHT), 0) self.scrollBar:ClearAllPoints() self.scrollBar:SetPoint('BOTTOMRIGHT', self, -1, 1) - self.scrollBar:SetPoint('TOPRIGHT', self, -1, -self.sizes.headHeight - ST_HEAD_SPACE - 1) + self.scrollBar:SetPoint('TOPRIGHT', self, -1, -self.headHeight - HEAD_SPACE - 1) - if getn(self.rowData or empty) > self.sizes.numRows then + if getn(self.rowData or empty) > self.numRows then self.contentFrame:SetPoint('BOTTOMRIGHT', -15, 0) else self.contentFrame:SetPoint('BOTTOMRIGHT', 0, 0) @@ -82,7 +80,7 @@ local methods = { if self.colInfo[i] then col:Show() col:SetWidth(self.colInfo[i].width * width) - col:SetHeight(self.sizes.headHeight) + col:SetHeight(self.headHeight) col.text:SetText(self.colInfo[i].name or '') col.text:SetJustifyH(self.colInfo[i].headAlign or 'CENTER') else @@ -90,12 +88,12 @@ local methods = { end end - while getn(self.rows) < self.sizes.numRows do + while getn(self.rows) < self.numRows do self:AddRow() end for i, row in self.rows do - if i > self.sizes.numRows then + if i > self.numRows then row.data = nil row:Hide() else @@ -116,11 +114,11 @@ local methods = { end if not self.rowData then return end - FauxScrollFrame_Update(self.scrollFrame, getn(self.rowData), self.sizes.numRows, ST_ROW_HEIGHT) + FauxScrollFrame_Update(self.scrollFrame, getn(self.rowData), self.numRows, ROW_HEIGHT) local offset = FauxScrollFrame_GetOffset(self.scrollFrame) self.offset = offset - for i = 1, self.sizes.numRows do + for i = 1, self.numRows do self.rows[i].data = nil if i > getn(self.rowData) then self.rows[i]:Hide() @@ -227,11 +225,11 @@ local methods = { local col = CreateFrame('Frame', nil, row) local text = col:CreateFontString() col.text = text - text:SetFont(gui.font, ST_ROW_TEXT_SIZE) + text:SetFont(gui.font, ROW_TEXT_SIZE) text:SetJustifyV('CENTER') text:SetPoint('TOPLEFT', 1, -1) text:SetPoint('BOTTOMRIGHT', -1, 1) - col:SetHeight(ST_ROW_HEIGHT) + col:SetHeight(ROW_HEIGHT) col:EnableMouse(true) for name, func in handlers do col:SetScript(name, func) @@ -249,14 +247,14 @@ local methods = { AddRow = function(self) local row = CreateFrame('Frame', nil, self.contentFrame) - row:SetHeight(ST_ROW_HEIGHT) + row:SetHeight(ROW_HEIGHT) local rowNum = getn(self.rows) + 1 if rowNum == 1 then - row:SetPoint('TOPLEFT', 2, -(self.sizes.headHeight + ST_HEAD_SPACE)) - row:SetPoint('TOPRIGHT', 0, -(self.sizes.headHeight + ST_HEAD_SPACE)) + row:SetPoint('TOPLEFT', 0, -(self.headHeight + HEAD_SPACE)) + row:SetPoint('TOPRIGHT', 0, -(self.headHeight + HEAD_SPACE)) else - row:SetPoint('TOPLEFT', 2, -(self.sizes.headHeight + ST_HEAD_SPACE + (rowNum - 1) * ST_ROW_HEIGHT)) - row:SetPoint('TOPRIGHT', 0, -(self.sizes.headHeight + ST_HEAD_SPACE + (rowNum - 1) * ST_ROW_HEIGHT)) + row:SetPoint('TOPLEFT', 0, -(self.headHeight + HEAD_SPACE + (rowNum - 1) * ROW_HEIGHT)) + row:SetPoint('TOPRIGHT', 0, -(self.headHeight + HEAD_SPACE + (rowNum - 1) * ROW_HEIGHT)) end local highlight = row:CreateTexture() highlight:SetAllPoints() @@ -267,7 +265,7 @@ local methods = { row.cols = T self.rows[rowNum] = row - for i = 1, getn(self.colInfo) do + for _ = 1, getn(self.colInfo) do self:AddRowCol(rowNum) end end, @@ -284,8 +282,7 @@ local methods = { } function M.new(parent) - ST_COUNT = ST_COUNT + 1 - local st = CreateFrame('Frame', 'TSMScrollingTable' .. ST_COUNT, parent) + local st = CreateFrame('Frame', gui.unique_name, parent) st:SetAllPoints() local contentFrame = CreateFrame('Frame', nil, st) @@ -295,28 +292,29 @@ function M.new(parent) local scrollFrame = CreateFrame('ScrollFrame', st:GetName() .. 'ScrollFrame', st, 'FauxScrollFrameTemplate') scrollFrame:SetScript('OnVerticalScroll', function() - FauxScrollFrame_OnVerticalScroll(ST_ROW_HEIGHT, function() st:Update() end) + FauxScrollFrame_OnVerticalScroll(ROW_HEIGHT, function() st:Update() end) end) scrollFrame:SetAllPoints(contentFrame) st.scrollFrame = scrollFrame - local scrollBar = _G[scrollFrame:GetName() .. 'ScrollBar'] - scrollBar:SetWidth(12) - st.scrollBar = scrollBar - local thumbTex = scrollBar:GetThumbTexture() + local scroll_bar = _G[scrollFrame:GetName() .. 'ScrollBar'] + st.scrollBar = scroll_bar + scroll_bar:ClearAllPoints() + scroll_bar:SetPoint('TOPRIGHT', st, -4, -HEAD_HEIGHT) + scroll_bar:SetPoint('BOTTOMRIGHT', st, -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() for name, func in methods do st[name] = func end - - st.isTSMScrollingTable = true - st.sizes = T + st.headCols = T st.rows = T st.handlers = T diff --git a/tabs/post/frame.lua b/tabs/post/frame.lua index d61c421..c45312e 100644 --- a/tabs/post/frame.lua +++ b/tabs/post/frame.lua @@ -39,7 +39,7 @@ frame.buyout_listing:SetPoint('BOTTOMRIGHT', 0, 0) do local checkbox = gui.checkbox(frame.inventory) - checkbox:SetPoint('TOPLEFT', 49, -16) + checkbox:SetPoint('TOPLEFT', 49, -15) checkbox:SetScript('OnClick', function() refresh = true end) @@ -49,23 +49,28 @@ do show_hidden_checkbox = checkbox end -gui.horizontal_line(frame.inventory, -48) +gui.horizontal_line(frame.inventory, -46) -inventory_listing = item_listing.new( - frame.inventory, - function() - if arg1 == 'LeftButton' then - update_item(this.item_record) - elseif arg1 == 'RightButton' then - tab = 1 - search_tab.set_filter(strlower(info.item(this.item_record.item_id).name) .. '/exact') - search_tab.execute(nil, false) - end - end, - function(item_record) - return item_record == selected_item - end -) +do + local f = CreateFrame('Frame', nil, frame.inventory) + f:SetPoint('TOPLEFT', 0, -51) + f:SetPoint('BOTTOMRIGHT', 0, 0) + inventory_listing = item_listing.new( + f, + function() + if arg1 == 'LeftButton' then + update_item(this.item_record) + elseif arg1 == 'RightButton' then + tab = 1 + search_tab.set_filter(strlower(info.item(this.item_record.item_id).name) .. '/exact') + search_tab.execute(nil, false) + end + end, + function(item_record) + return item_record == selected_item + end + ) +end bid_listing = listing.new(frame.bid_listing) bid_listing:SetColInfo{