big refactoring
This commit is contained in:
File diff suppressed because it is too large
Load Diff
+649
@@ -0,0 +1,649 @@
|
||||
module 'gui'
|
||||
|
||||
public.config = {
|
||||
colors = {
|
||||
text = {enabled = {255, 254, 250, 1}, disabled = {147, 151, 139, 1}},
|
||||
label = {enabled = {216, 225, 211, 1}, disabled = {150, 148, 140, 1}},
|
||||
link = {153, 255, 255, 1},
|
||||
window = {background = {24, 24, 24, .93}, border = {30, 30, 30, 1}},
|
||||
panel = {background = {24, 24, 24, 1}, border = {255, 255, 255, .03}},
|
||||
content = {background = {42, 42, 42, 1}, border = {0, 0, 0, 0}},
|
||||
state = {enabled = {70, 180, 70, 1}, disabled = {190, 70, 70, 1}},
|
||||
|
||||
blue = {41, 146, 255, 1},
|
||||
green = {22, 255, 22, 1},
|
||||
yellow = {255, 255, 0, 1},
|
||||
orange = {255, 146, 24, 1},
|
||||
red = {255, 0, 0, 1},
|
||||
gray = {187, 187, 187, 1},
|
||||
|
||||
blizzard = {0, 180, 255, 1},
|
||||
aux = {255, 255, 154, 1},
|
||||
},
|
||||
edge_size = 1.5,
|
||||
font = [[Fonts\ARIALN.TTF]],
|
||||
small_font_size = 13,
|
||||
small_font_size2 = 14,
|
||||
medium_font_size = 15,
|
||||
medium_font_size2 = 16,
|
||||
large_font_size = 17,
|
||||
large_font_size2 = 18,
|
||||
huge_font_size = 23,
|
||||
}
|
||||
|
||||
do
|
||||
local function index_handler(self, key)
|
||||
self.private.table = self.private.table[key]
|
||||
if getn(self.private.table) == 0 then
|
||||
return self.public
|
||||
else
|
||||
local color = copy(self.private.table)
|
||||
self.private.table = config.colors
|
||||
return self.private.callback(color)
|
||||
end
|
||||
end
|
||||
function color_accessor(callback)
|
||||
return function()
|
||||
return index_function({callback=callback, table=config.colors}, index_handler)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
do
|
||||
local mt = {
|
||||
__call = function(self, text)
|
||||
local r, g, b, a = unpack(self)
|
||||
if text then
|
||||
return format('|c%02X%02X%02X%02X', a, r*255, g*255, b*255)..text..FONT_COLOR_CODE_CLOSE
|
||||
else
|
||||
return r, g, b, a
|
||||
end
|
||||
end
|
||||
}
|
||||
public.accessor.color = color_accessor(function(color)
|
||||
local r, g, b, a = unpack(color)
|
||||
return setmetatable({r/255, g/255, b/255, a}, mt)
|
||||
end)
|
||||
end
|
||||
|
||||
public.accessor.inline_color = color_accessor(function(color)
|
||||
local r, g, b, a = unpack(color)
|
||||
return format('|c%02X%02X%02X%02X', a, r, g, b)
|
||||
end)
|
||||
|
||||
do
|
||||
local id = 0
|
||||
function public.accessor.name() id = id + 1; return 'aux_frame'..id end
|
||||
end
|
||||
|
||||
do
|
||||
local menu, structure
|
||||
function public.menu(menu_structure)
|
||||
structure = menu_structure
|
||||
menu:SetPoint('BOTTOMLEFT', GetCursorPosition())
|
||||
menu:Show()
|
||||
end
|
||||
function initialize_menu()
|
||||
menu = CreateFrame('Frame', name, UIParent, 'UIMenuTemplate')
|
||||
local orig = menu:GetScript 'OnShow'
|
||||
menu:SetScript('OnShow', function()
|
||||
UIMenu_Initialize()
|
||||
for i=1,getn(structure) do
|
||||
UIMenu_AddButton(
|
||||
structure[i][1],
|
||||
structure[i],
|
||||
type(structure[i]) == 'string' and structure[element[3]] or element[3]
|
||||
)
|
||||
end
|
||||
return orig()
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
function LOAD()
|
||||
import :_ 'util'
|
||||
initialize_menu()
|
||||
initialize_dropdown()
|
||||
end
|
||||
|
||||
do
|
||||
local blizzard_backdrop, aux_background, aux_border
|
||||
|
||||
function initialize_dropdown()
|
||||
aux_border = DropDownList1:CreateTexture()
|
||||
aux_border:SetTexture(1, 1, 1, .02)
|
||||
aux_border:SetPoint('TOPLEFT', DropDownList1Backdrop, 'TOPLEFT', -2, 2)
|
||||
aux_border:SetPoint('BOTTOMRIGHT', DropDownList1Backdrop, 'BOTTOMRIGHT', 1.5, -1.5)
|
||||
aux_border:SetBlendMode 'ADD'
|
||||
aux_background = DropDownList1:CreateTexture(nil, 'OVERLAY')
|
||||
aux_background:SetTexture(color.content.background())
|
||||
aux_background:SetAllPoints(DropDownList1Backdrop)
|
||||
blizzard_backdrop = DropDownList1Backdrop:GetBackdrop()
|
||||
hook('ToggleDropDownMenu', function(...)
|
||||
local ret = {orig.ToggleDropDownMenu(unpack(arg))}
|
||||
local dropdown = getglobal(arg[4] or '') or this:GetParent()
|
||||
if strfind(dropdown:GetName() or '', '^aux_frame%d+$') then
|
||||
set_aux_dropdown_style(dropdown)
|
||||
else
|
||||
set_blizzard_dropdown_style()
|
||||
end
|
||||
return unpack(ret)
|
||||
end)
|
||||
end
|
||||
|
||||
function set_aux_dropdown_style(dropdown)
|
||||
DropDownList1Backdrop:SetBackdrop{}
|
||||
aux_border:Show()
|
||||
aux_background:Show()
|
||||
DropDownList1:SetWidth(dropdown:GetWidth() * 0.9)
|
||||
DropDownList1:SetHeight(DropDownList1:GetHeight() - 10)
|
||||
DropDownList1:ClearAllPoints()
|
||||
DropDownList1:SetPoint('TOPLEFT', dropdown, 'BOTTOMLEFT', -2, -2)
|
||||
for i=1,UIDROPDOWNMENU_MAXBUTTONS do
|
||||
local button = getglobal('DropDownList1Button'..i)
|
||||
button:SetPoint('TOPLEFT', 0, -((button:GetID() - 1) * UIDROPDOWNMENU_BUTTON_HEIGHT) - 7)
|
||||
button:SetPoint('TOPRIGHT', 0, -((button:GetID() - 1) * UIDROPDOWNMENU_BUTTON_HEIGHT) - 7)
|
||||
local text = button:GetFontString()
|
||||
text:SetFont(config.font, config.small_font_size2)
|
||||
text:SetPoint('TOPLEFT', 18, 0)
|
||||
text:SetPoint('BOTTOMRIGHT', -8, 0)
|
||||
local highlight = getglobal('DropDownList1Button'..i..'Highlight')
|
||||
highlight:ClearAllPoints()
|
||||
highlight:SetDrawLayer 'OVERLAY'
|
||||
highlight:SetHeight(14)
|
||||
highlight:SetPoint('LEFT', 5, 0)
|
||||
highlight:SetPoint('RIGHT', -3, 0)
|
||||
local check = getglobal('DropDownList1Button'..i..'Check')
|
||||
check:SetWidth(16)
|
||||
check:SetHeight(16)
|
||||
check:SetPoint('LEFT', 3, -1)
|
||||
end
|
||||
end
|
||||
|
||||
function set_blizzard_dropdown_style()
|
||||
DropDownList1Backdrop:SetBackdrop(blizzard_backdrop)
|
||||
aux_border:Hide()
|
||||
aux_background:Hide()
|
||||
for i=1,UIDROPDOWNMENU_MAXBUTTONS do
|
||||
local button = getglobal('DropDownList1Button'..i)
|
||||
local text = button:GetFontString()
|
||||
text:SetFont([[Fonts\FRIZQT__.ttf]], 10)
|
||||
text:SetShadowOffset(1, -1)
|
||||
local highlight = getglobal('DropDownList1Button'..i..'Highlight')
|
||||
highlight:SetAllPoints()
|
||||
highlight:SetDrawLayer 'BACKGROUND'
|
||||
local check = getglobal('DropDownList1Button'..i..'Check')
|
||||
check:SetWidth(24)
|
||||
check:SetHeight(24)
|
||||
check:SetPoint('LEFT', 0, 0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function public.set_size(frame, width, height)
|
||||
frame:SetWidth(width)
|
||||
frame:SetHeight(height or width)
|
||||
end
|
||||
|
||||
function public.set_frame_style(frame, backdrop_color, border_color, left, right, top, bottom)
|
||||
frame:SetBackdrop{bgFile=[[Interface\Buttons\WHITE8X8]], edgeFile=[[Interface\Buttons\WHITE8X8]], edgeSize=config.edge_size, tile=true, insets={left=left, right=right, top=top, bottom=bottom}}
|
||||
frame:SetBackdropColor(backdrop_color())
|
||||
frame:SetBackdropBorderColor(border_color())
|
||||
end
|
||||
|
||||
function public.set_window_style(frame, left, right, top, bottom)
|
||||
set_frame_style(frame, color.window.background, color.window.border, left, right, top, bottom)
|
||||
end
|
||||
|
||||
function public.set_panel_style(frame, left, right, top, bottom)
|
||||
set_frame_style(frame, color.panel.background, color.panel.border, left, right, top, bottom)
|
||||
end
|
||||
|
||||
function public.set_content_style(frame, left, right, top, bottom)
|
||||
set_frame_style(frame, color.content.background, color.content.border, left, right, top, bottom)
|
||||
end
|
||||
|
||||
function public.panel(parent)
|
||||
local panel = CreateFrame('Frame', nil, parent)
|
||||
set_panel_style(panel)
|
||||
return panel
|
||||
end
|
||||
|
||||
function public.checkbutton(parent, text_height)
|
||||
local button = button(parent, text_height)
|
||||
button.state = false
|
||||
button:SetBackdropColor(color.state.disabled())
|
||||
function button:SetChecked(state)
|
||||
if state then
|
||||
self:SetBackdropColor(color.state.enabled())
|
||||
self.state = true
|
||||
else
|
||||
self:SetBackdropColor(color.state.disabled())
|
||||
self.state = false
|
||||
end
|
||||
end
|
||||
function button:GetChecked()
|
||||
return self.state
|
||||
end
|
||||
return button
|
||||
end
|
||||
|
||||
function public.button(parent, text_height)
|
||||
text_height = text_height or 16
|
||||
local button = CreateFrame('Button', nil, parent)
|
||||
set_content_style(button)
|
||||
local highlight = button:CreateTexture(nil, 'HIGHLIGHT')
|
||||
highlight:SetAllPoints()
|
||||
highlight:SetTexture(1, 1, 1, .2)
|
||||
highlight:SetBlendMode 'BLEND'
|
||||
button.highlight = highlight
|
||||
do
|
||||
local label = button:CreateFontString()
|
||||
label:SetFont(config.font, text_height)
|
||||
label:SetPoint('CENTER', 0, 0)
|
||||
label:SetJustifyH 'CENTER'
|
||||
label:SetJustifyV 'CENTER'
|
||||
label:SetHeight(text_height)
|
||||
label:SetTextColor(color.text.enabled())
|
||||
button:SetFontString(label)
|
||||
end
|
||||
button.default_Enable = button.Enable
|
||||
function button:Enable()
|
||||
self:GetFontString():SetTextColor(color.text.enabled())
|
||||
return self:default_Enable()
|
||||
end
|
||||
button.default_Disable = button.Disable
|
||||
function button:Disable()
|
||||
self:GetFontString():SetTextColor(color.text.disabled())
|
||||
return self:default_Disable()
|
||||
end
|
||||
|
||||
return button
|
||||
end
|
||||
|
||||
|
||||
function public.resize_tab(tab, width, padding)
|
||||
tab:SetWidth(width + padding + 10)
|
||||
end
|
||||
|
||||
do
|
||||
local mt = {__index={}}
|
||||
function mt.__index:create_tab(text)
|
||||
local id = getn(self._tabs) + 1
|
||||
|
||||
local tab = CreateFrame('Button', name, self._frame)
|
||||
tab.id = id
|
||||
tab.group = self
|
||||
tab:SetHeight(24)
|
||||
tab:SetBackdrop{bgFile=[[Interface\Buttons\WHITE8X8]], edgeFile=[[Interface\Buttons\WHITE8X8]], edgeSize=config.edge_size}
|
||||
tab:SetBackdropBorderColor(color.panel.border())
|
||||
local dock = tab:CreateTexture(nil, 'OVERLAY')
|
||||
dock:SetHeight(3)
|
||||
if self._orientation == 'UP' then
|
||||
dock:SetPoint('BOTTOMLEFT', 1, -1)
|
||||
dock:SetPoint('BOTTOMRIGHT', -1, -1)
|
||||
elseif self._orientation == 'DOWN' then
|
||||
dock:SetPoint('TOPLEFT', 1, 1)
|
||||
dock:SetPoint('TOPRIGHT', -1, 1)
|
||||
end
|
||||
dock:SetTexture(color.panel.background())
|
||||
tab.dock = dock
|
||||
local highlight = tab:CreateTexture(nil, 'HIGHLIGHT')
|
||||
highlight:SetAllPoints()
|
||||
highlight:SetTexture(1, 1, 1, .2)
|
||||
highlight:SetBlendMode 'BLEND'
|
||||
tab.highlight = highlight
|
||||
|
||||
tab.text = tab:CreateFontString()
|
||||
tab.text:SetPoint('LEFT', 3, -1)
|
||||
tab.text:SetPoint('RIGHT', -3, -1)
|
||||
tab.text:SetJustifyH 'CENTER'
|
||||
tab.text:SetJustifyV 'CENTER'
|
||||
tab.text:SetFont(config.font, config.large_font_size2)
|
||||
tab:SetFontString(tab.text)
|
||||
|
||||
tab:SetText(text)
|
||||
|
||||
tab:SetScript('OnClick', function()
|
||||
if this.id ~= this.group.selected then
|
||||
PlaySound 'igCharacterInfoTab'
|
||||
this.group:select(this.id)
|
||||
end
|
||||
end)
|
||||
|
||||
if getn(self._tabs) == 0 then
|
||||
if self._orientation == 'UP' then
|
||||
tab:SetPoint('BOTTOMLEFT', self._frame, 'TOPLEFT', 4, -1)
|
||||
elseif self._orientation == 'DOWN' then
|
||||
tab:SetPoint('TOPLEFT', self._frame, 'BOTTOMLEFT', 4, 1)
|
||||
end
|
||||
else
|
||||
if self._orientation == 'UP' then
|
||||
tab:SetPoint('BOTTOMLEFT', self._tabs[getn(self._tabs)], 'BOTTOMRIGHT', 4, 0)
|
||||
elseif self._orientation == 'DOWN' then
|
||||
tab:SetPoint('TOPLEFT', self._tabs[getn(self._tabs)], 'TOPRIGHT', 4, 0)
|
||||
end
|
||||
end
|
||||
|
||||
resize_tab(tab, tab:GetFontString():GetStringWidth(), 4)
|
||||
|
||||
tinsert(self._tabs, tab)
|
||||
end
|
||||
function mt.__index:select(id)
|
||||
self._selected = id
|
||||
self:update()
|
||||
call(self._on_select, id)
|
||||
end
|
||||
function mt.__index:update()
|
||||
for _, tab in self._tabs do
|
||||
if tab.group._selected == tab.id then
|
||||
tab.text:SetTextColor(color.label.enabled())
|
||||
tab:Disable()
|
||||
tab:SetBackdropColor(color.panel.background())
|
||||
tab.dock:Show()
|
||||
tab:SetHeight(29)
|
||||
else
|
||||
tab.text:SetTextColor(color.text.enabled())
|
||||
tab:Enable()
|
||||
tab:SetBackdropColor(color.content.background())
|
||||
tab.dock:Hide()
|
||||
tab:SetHeight(24)
|
||||
end
|
||||
end
|
||||
end
|
||||
function public.tabs(parent, orientation)
|
||||
local self = {
|
||||
_frame = parent,
|
||||
_orientation = orientation,
|
||||
_tabs = {},
|
||||
}
|
||||
return setmetatable(self, mt)
|
||||
end
|
||||
end
|
||||
|
||||
function public.editbox(parent)
|
||||
local editbox = CreateFrame('EditBox', nil, parent)
|
||||
editbox:SetAutoFocus(false)
|
||||
editbox:SetTextInsets(1.5, 1.5, 3, 3)
|
||||
editbox:SetMaxLetters(nil)
|
||||
editbox:SetHeight(24)
|
||||
editbox:SetTextColor(0, 0, 0, 0)
|
||||
set_content_style(editbox)
|
||||
local function colorize() this.display:SetText(call(this.colorizer, this:GetText()) or this:GetText()) end
|
||||
local function format() this.display:SetText(call(this.formatter or this.colorizer, this:GetText()) or this:GetText()) end
|
||||
editbox:SetScript('OnEscapePressed', function()
|
||||
this:ClearFocus()
|
||||
call(this.escape)
|
||||
end)
|
||||
editbox:SetScript('OnEnterPressed', function() call(this.enter) end)
|
||||
editbox:SetScript('OnEditFocusGained', function()
|
||||
colorize()
|
||||
this.focused = true
|
||||
this:HighlightText()
|
||||
this:SetScript('OnUpdate', function()
|
||||
this.cursor:SetAlpha(mod(floor((GetTime()-this.cursor.last_change) * 2 + 1), 2))
|
||||
end)
|
||||
call(this.focus_gain)
|
||||
end)
|
||||
editbox:SetScript('OnEditFocusLost', function()
|
||||
format()
|
||||
this.focused = false
|
||||
this.cursor:SetAlpha(0)
|
||||
this:HighlightText(0, 0)
|
||||
this:SetScript('OnUpdate', nil)
|
||||
call(this.focus_loss)
|
||||
end)
|
||||
editbox:SetScript('OnTextChanged', function()
|
||||
if this.focused then
|
||||
colorize()
|
||||
else
|
||||
format()
|
||||
end
|
||||
call(this.change)
|
||||
end)
|
||||
editbox:SetScript('OnCursorChanged', function()
|
||||
this.cursor.last_change = GetTime()
|
||||
this.cursor:SetPoint(this:GetJustifyH(), this, this:GetJustifyH(), call(arg1 > 0 and max or min, 0, arg1 - 1.5), 1.5)
|
||||
end)
|
||||
editbox:SetScript('OnChar', function() call(this.char) end)
|
||||
do
|
||||
local last_click
|
||||
editbox:SetScript('OnMouseDown', function()
|
||||
local x, y = GetCursorPosition()
|
||||
-- local offset = x - editbox:GetLeft()*editbox:GetEffectiveScale() TODO use a fontstring to measure getstringwidth for structural highlighting
|
||||
-- editbox:Insert'<ksejfkj>' TODO use insert with special tags to determine cursor position
|
||||
-- or use an overlay with itemlinks
|
||||
if last_click and GetTime() - last_click.t < .5 and x == last_click.x and y == last_click.y then
|
||||
thread(function() editbox:HighlightText() end)
|
||||
end
|
||||
last_click = {t=GetTime(), x=x, y=y}
|
||||
end)
|
||||
end
|
||||
function editbox:Enable()
|
||||
editbox:EnableMouse(true)
|
||||
editbox:SetTextColor(color.text.enabled())
|
||||
end
|
||||
function editbox:Disable()
|
||||
editbox:EnableMouse(false)
|
||||
editbox:SetTextColor(color.text.disabled())
|
||||
editbox:ClearFocus()
|
||||
end
|
||||
function editbox:SetAlignment(alignment)
|
||||
self:SetJustifyH(alignment)
|
||||
self.display:SetJustifyH(alignment)
|
||||
end
|
||||
function editbox:SetFontSize(size)
|
||||
self:SetFont(config.font, size)
|
||||
self.display:SetFont(config.font, size)
|
||||
end
|
||||
local display = label(editbox)
|
||||
display:SetPoint('LEFT', 1.5, 0)
|
||||
display:SetPoint('RIGHT', -1.5, 0)
|
||||
display:SetTextColor(color.text.enabled())
|
||||
editbox.display = display
|
||||
local cursor = label(editbox, config.large_font_size)
|
||||
cursor:SetText '|'
|
||||
cursor:SetTextColor(color.text.enabled())
|
||||
cursor:SetAlpha(0)
|
||||
editbox.cursor = cursor
|
||||
editbox:SetAlignment 'LEFT'
|
||||
editbox:SetFontSize(config.medium_font_size)
|
||||
return editbox
|
||||
end
|
||||
|
||||
function public.status_bar(parent)
|
||||
local self = CreateFrame('Frame', nil, parent)
|
||||
|
||||
local level = parent:GetFrameLevel()
|
||||
|
||||
self:SetFrameLevel(level + 1)
|
||||
|
||||
do
|
||||
-- minor status bar (gray one)
|
||||
local status_bar = CreateFrame('STATUSBAR', nil, self, 'TextStatusBar')
|
||||
status_bar:SetOrientation 'HORIZONTAL'
|
||||
status_bar:SetMinMaxValues(0, 100)
|
||||
status_bar:SetAllPoints()
|
||||
status_bar:SetStatusBarTexture [[Interface\Buttons\WHITE8X8]]
|
||||
status_bar:SetStatusBarColor(.42, .42, .42, .7)
|
||||
status_bar:SetFrameLevel(level + 2)
|
||||
status_bar:SetScript('OnUpdate', function()
|
||||
if this:GetValue() < 100 then
|
||||
this:SetAlpha(1 - ((math.sin(GetTime()*math.pi)+1)/2)/2)
|
||||
else
|
||||
this:SetAlpha(1)
|
||||
end
|
||||
end)
|
||||
self.minor_status_bar = status_bar
|
||||
end
|
||||
|
||||
do
|
||||
-- major status bar (main blue one)
|
||||
local status_bar = CreateFrame('STATUSBAR', nil, self, 'TextStatusBar')
|
||||
status_bar:SetOrientation 'HORIZONTAL'
|
||||
status_bar:SetMinMaxValues(0, 100)
|
||||
status_bar:SetAllPoints()
|
||||
status_bar:SetStatusBarTexture [[Interface\Buttons\WHITE8X8]]
|
||||
status_bar:SetStatusBarColor(.19, .22, .33, .9)
|
||||
status_bar:SetFrameLevel(level + 3)
|
||||
status_bar:SetScript('OnUpdate', function()
|
||||
if this:GetValue() < 100 then
|
||||
this:SetAlpha(1 - ((math.sin(GetTime()*math.pi)+1)/2)/2)
|
||||
else
|
||||
this:SetAlpha(1)
|
||||
end
|
||||
end)
|
||||
self.major_status_bar = status_bar
|
||||
end
|
||||
|
||||
do
|
||||
local text_frame = CreateFrame('Frame', nil, self)
|
||||
text_frame:SetFrameLevel(level + 4)
|
||||
text_frame:SetAllPoints(self)
|
||||
local text = label(text_frame, 15)
|
||||
text:SetTextColor(color.text.enabled())
|
||||
text:SetPoint('CENTER', 0, 0)
|
||||
self.text = text
|
||||
end
|
||||
|
||||
function self:update_status(major_status, minor_status)
|
||||
if major_status then
|
||||
self.major_status_bar:SetValue(major_status)
|
||||
end
|
||||
if minor_status then
|
||||
self.minor_status_bar:SetValue(minor_status)
|
||||
end
|
||||
end
|
||||
|
||||
function self:set_text(text)
|
||||
self.text:SetText(text)
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function public.item(parent)
|
||||
local item = CreateFrame('Frame', nil, parent)
|
||||
set_size(item, 260, 40)
|
||||
local btn = CreateFrame('CheckButton', name, item, 'ActionButtonTemplate')
|
||||
item.button = btn
|
||||
btn:SetPoint('LEFT', 2, .5)
|
||||
btn:SetHighlightTexture(nil)
|
||||
btn:RegisterForClicks()
|
||||
item.texture = getglobal(btn:GetName()..'Icon')
|
||||
item.texture:SetTexCoord(.06, .94, .06, .94)
|
||||
item.name = label(btn, 15)
|
||||
item.name:SetJustifyH 'LEFT'
|
||||
item.name:SetPoint('LEFT', btn, 'RIGHT', 10, 0)
|
||||
item.name:SetPoint('RIGHT', item, 'RIGHT', -10, .5)
|
||||
item.count = getglobal(btn:GetName()..'Count')
|
||||
item.count:SetTextHeight(17)
|
||||
return item
|
||||
end
|
||||
|
||||
function public.label(parent, size)
|
||||
local label = parent:CreateFontString()
|
||||
label:SetFont(config.font, size or config.small_font_size)
|
||||
label:SetTextColor(color.label.enabled())
|
||||
return label
|
||||
end
|
||||
|
||||
function public.horizontal_line(parent, y_offset, inverted_color)
|
||||
local texture = parent:CreateTexture()
|
||||
texture:SetPoint('TOPLEFT', parent, 'TOPLEFT', 2, y_offset)
|
||||
texture:SetPoint('TOPRIGHT', parent, 'TOPRIGHT', -2, y_offset)
|
||||
texture:SetHeight(2)
|
||||
if inverted_color then
|
||||
texture:SetTexture(color.panel.background())
|
||||
else
|
||||
texture:SetTexture(color.content.background())
|
||||
end
|
||||
return texture
|
||||
end
|
||||
|
||||
function public.vertical_line(parent, x_offset, top_offset, bottom_offset, inverted_color)
|
||||
local texture = parent:CreateTexture()
|
||||
texture:SetPoint('TOPLEFT', parent, 'TOPLEFT', x_offset, top_offset or -2)
|
||||
texture:SetPoint('BOTTOMLEFT', parent, 'BOTTOMLEFT', x_offset, bottom_offset or 2)
|
||||
texture:SetWidth(2)
|
||||
if inverted_color then
|
||||
texture:SetTexture(color.panel.background())
|
||||
else
|
||||
texture:SetTexture(color.content.background())
|
||||
end
|
||||
return texture
|
||||
end
|
||||
|
||||
function public.dropdown(parent)
|
||||
local dropdown = CreateFrame('Frame', name, parent, 'UIDropDownMenuTemplate')
|
||||
set_content_style(dropdown, 0, 0, 4, 4)
|
||||
|
||||
getglobal(dropdown:GetName()..'Left'):Hide()
|
||||
getglobal(dropdown:GetName()..'Middle'):Hide()
|
||||
getglobal(dropdown:GetName()..'Right'):Hide()
|
||||
|
||||
local button = getglobal(dropdown:GetName()..'Button')
|
||||
button:ClearAllPoints()
|
||||
button:SetScale(0.9)
|
||||
button:SetPoint('RIGHT', dropdown, 0, 0)
|
||||
dropdown.button = button
|
||||
|
||||
local text = getglobal(dropdown:GetName()..'Text')
|
||||
text:ClearAllPoints()
|
||||
text:SetPoint('RIGHT', button, 'LEFT', -2, 0)
|
||||
text:SetPoint('LEFT', 8, 0)
|
||||
text:SetFont(config.font, config.medium_font_size)
|
||||
text:SetShadowColor(0, 0, 0, 0)
|
||||
|
||||
return dropdown
|
||||
end
|
||||
|
||||
function public.slider(parent)
|
||||
|
||||
local slider = CreateFrame('Slider', nil, parent)
|
||||
slider:SetOrientation 'HORIZONTAL'
|
||||
slider:SetHeight(6)
|
||||
slider:SetHitRectInsets(0, 0, -12, -12)
|
||||
slider:SetValue(0)
|
||||
|
||||
set_panel_style(slider)
|
||||
local thumb_texture = slider:CreateTexture(nil, 'ARTWORK')
|
||||
thumb_texture:SetPoint('CENTER', 0, 0)
|
||||
thumb_texture:SetTexture(color.content.background())
|
||||
thumb_texture:SetHeight(18)
|
||||
thumb_texture:SetWidth(8)
|
||||
set_size(thumb_texture, 8, 18)
|
||||
slider:SetThumbTexture(thumb_texture)
|
||||
|
||||
local label = slider:CreateFontString(nil, 'OVERLAY')
|
||||
label:SetPoint('BOTTOMLEFT', slider, 'TOPLEFT', -3, 8)
|
||||
label:SetPoint('BOTTOMRIGHT', slider, 'TOPRIGHT', 6, 8)
|
||||
label:SetJustifyH 'LEFT'
|
||||
label:SetHeight(13)
|
||||
label:SetFont(config.font, config.small_font_size)
|
||||
label:SetTextColor(color.label.enabled())
|
||||
|
||||
local editbox = editbox(slider)
|
||||
editbox:SetPoint('LEFT', slider, 'RIGHT', 5, 0)
|
||||
set_size(editbox, 45, 18)
|
||||
editbox:SetAlignment 'CENTER'
|
||||
editbox:SetFontSize(17)
|
||||
|
||||
slider.label = label
|
||||
slider.editbox = editbox
|
||||
return slider
|
||||
end
|
||||
|
||||
function public.checkbox(parent)
|
||||
local checkbox = CreateFrame('CheckButton', nil, parent, 'UICheckButtonTemplate')
|
||||
checkbox:SetWidth(16)
|
||||
checkbox:SetHeight(16)
|
||||
set_content_style(checkbox)
|
||||
checkbox:SetNormalTexture(nil)
|
||||
checkbox:SetPushedTexture(nil)
|
||||
checkbox:GetHighlightTexture():SetAllPoints()
|
||||
checkbox:GetHighlightTexture():SetTexture(1, 1, 1, .2)
|
||||
checkbox:GetCheckedTexture():SetTexCoord(.12, .88, .12, .88)
|
||||
checkbox:GetHighlightTexture 'BLEND'
|
||||
return checkbox
|
||||
end
|
||||
@@ -0,0 +1,114 @@
|
||||
module 'item_listing'
|
||||
|
||||
local ROW_HEIGHT = 39
|
||||
|
||||
function public.render(item_listing)
|
||||
|
||||
FauxScrollFrame_Update(item_listing.scroll_frame, getn(item_listing.item_records), getn(item_listing.rows), ROW_HEIGHT)
|
||||
item_listing.scroll_frame:Show()
|
||||
local offset = FauxScrollFrame_GetOffset(item_listing.scroll_frame)
|
||||
|
||||
local rows = item_listing.rows
|
||||
|
||||
for i, row in rows do
|
||||
local item_record = item_listing.item_records[i + offset]
|
||||
|
||||
if item_record then
|
||||
row.item_record = item_record
|
||||
if item_listing.selected and item_listing.selected(item_record) then
|
||||
row.highlight:Show()
|
||||
elseif not row.mouse_over then
|
||||
row.highlight:Hide()
|
||||
end
|
||||
row.item.texture:SetTexture(item_record.texture)
|
||||
row.item.name:SetText('['..item_record.name..']')
|
||||
local color = ITEM_QUALITY_COLORS[item_record.quality]
|
||||
row.item.name:SetTextColor(color.r, color.g, color.b)
|
||||
if item_record.aux_quantity > 1 then
|
||||
row.item.count:SetText(item_record.aux_quantity)
|
||||
else
|
||||
row.item.count:SetText()
|
||||
end
|
||||
row:Show()
|
||||
else
|
||||
row:Hide()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function public.create(parent, on_click, selected)
|
||||
local content = CreateFrame('Frame', nil, parent)
|
||||
content:SetPoint('TOPLEFT', 0, -51)
|
||||
content:SetPoint('BOTTOMRIGHT', -15, 0)
|
||||
|
||||
local scroll_frame = CreateFrame('ScrollFrame', gui.name..'ScrollFrame', parent, 'FauxScrollFrameTemplate')
|
||||
scroll_frame:SetScript('OnVerticalScroll', function(self, offset)
|
||||
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)
|
||||
|
||||
local scrollBar = getglobal(scroll_frame:GetName()..'ScrollBar')
|
||||
scrollBar:SetWidth(12)
|
||||
local thumbTex = scrollBar:GetThumbTexture()
|
||||
thumbTex:SetPoint('CENTER', 0, 0)
|
||||
thumbTex:SetTexture(gui.color.content.background())
|
||||
thumbTex:SetHeight(50)
|
||||
thumbTex:SetWidth(12)
|
||||
getglobal(scrollBar:GetName()..'ScrollUpButton'):Hide()
|
||||
getglobal(scrollBar:GetName()..'ScrollDownButton'):Hide()
|
||||
|
||||
local rows = {}
|
||||
local row_index = 1
|
||||
local max_height = content:GetHeight()
|
||||
local total_height = 0
|
||||
while total_height + ROW_HEIGHT < max_height do
|
||||
local row = CreateFrame('Button', nil, content)
|
||||
row:SetHeight(ROW_HEIGHT)
|
||||
row:SetWidth(195)
|
||||
row:SetPoint('TOPLEFT', content, 2, -((row_index-1) * ROW_HEIGHT))
|
||||
row:RegisterForClicks('LeftButtonUp', 'RightButtonUp')
|
||||
row:SetScript('OnClick', on_click)
|
||||
row:SetScript('OnEnter', function()
|
||||
row.highlight:Show()
|
||||
end)
|
||||
row:SetScript('OnLeave', function()
|
||||
if not selected(row.item_record) then
|
||||
row.highlight:Hide()
|
||||
end
|
||||
end)
|
||||
|
||||
row.item = gui.item(row)
|
||||
row.item:SetScale(0.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
|
||||
|
||||
rows[row_index] = row
|
||||
row_index = row_index + 1
|
||||
total_height = total_height + ROW_HEIGHT
|
||||
end
|
||||
|
||||
local item_listing = {
|
||||
selected = selected,
|
||||
scroll_frame = scroll_frame,
|
||||
rows = rows,
|
||||
}
|
||||
scroll_frame.item_listing = item_listing
|
||||
|
||||
return item_listing
|
||||
end
|
||||
|
||||
function public.populate(item_listing, item_records)
|
||||
item_listing.item_records = item_records
|
||||
render(item_listing)
|
||||
end
|
||||
+456
@@ -0,0 +1,456 @@
|
||||
module 'listing'
|
||||
|
||||
local ST_COUNT = 0
|
||||
|
||||
local ST_ROW_HEIGHT = 15
|
||||
local ST_ROW_TEXT_SIZE = 14
|
||||
local ST_HEAD_HEIGHT = 26.3
|
||||
local ST_HEAD_SPACE = 2
|
||||
local DEFAULT_COL_INFO = {{width=1}}
|
||||
|
||||
|
||||
local function GetTableIndex(tbl, value)
|
||||
for i, v in tbl do
|
||||
if value == v then return i end
|
||||
end
|
||||
end
|
||||
|
||||
local function OnColumnClick()
|
||||
local button = arg1
|
||||
if this.st.sortInfo.enabled and button == 'LeftButton' then
|
||||
if this.st.sortInfo.col == this.colNum then
|
||||
this.st.sortInfo.ascending = not this.st.sortInfo.ascending
|
||||
else
|
||||
this.st.sortInfo.col = this.colNum
|
||||
this.st.sortInfo.ascending = true
|
||||
end
|
||||
this.st.updateSort = true
|
||||
this.st:RefreshRows()
|
||||
end
|
||||
if this.st.handlers.OnColumnClick then
|
||||
this.st.handlers.OnColumnClick(this, button)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local defaultColScripts = {
|
||||
OnEnter = function()
|
||||
this.row.mouseover = true
|
||||
if not this.row.data then return end
|
||||
if not this.st.highlightDisabled then
|
||||
this.row.highlight:Show()
|
||||
end
|
||||
|
||||
local handler = this.st.handlers.OnEnter
|
||||
if handler then
|
||||
handler(this.st, this.row.data, this)
|
||||
end
|
||||
end,
|
||||
|
||||
OnLeave = function()
|
||||
this.row.mouseover = false
|
||||
if not this.row.data then return end
|
||||
if this.st.selectionDisabled or not this.st.selected or this.st.selected ~= GetTableIndex(this.st.rowData, this.row.data) then
|
||||
this.row.highlight:Hide()
|
||||
end
|
||||
|
||||
local handler = this.st.handlers.OnLeave
|
||||
if handler then
|
||||
handler(this.st, this.row.data, this)
|
||||
end
|
||||
end,
|
||||
|
||||
OnClick = function()
|
||||
if not this.row.data then return end
|
||||
this.st:ClearSelection()
|
||||
this.st.selected = GetTableIndex(this.st.rowData, this.row.data)
|
||||
this.row.highlight:Show()
|
||||
|
||||
local handler = this.st.handlers.OnClick
|
||||
if handler then
|
||||
handler(this.st, this.row.data, this, arg1)
|
||||
end
|
||||
end,
|
||||
|
||||
OnDoubleClick = function()
|
||||
if not this.row.data then return end
|
||||
local handler = this.st.handlers.OnDoubleClick
|
||||
if handler then
|
||||
handler(this.st, this.row.data, this, arg1)
|
||||
end
|
||||
end,
|
||||
}
|
||||
|
||||
local methods = {
|
||||
RefreshRows = function(st)
|
||||
if not st.rowData then return end
|
||||
FauxScrollFrame_Update(st.scrollFrame, getn(st.rowData), st.sizes.numRows, ST_ROW_HEIGHT)
|
||||
local offset = FauxScrollFrame_GetOffset(st.scrollFrame)
|
||||
st.offset = offset
|
||||
|
||||
-- do sorting if enabled
|
||||
if st.sortInfo.enabled and st.sortInfo.col and st.updateSort then
|
||||
local function SortHelper(rowA, rowB)
|
||||
local sortArgA = rowA.cols[st.sortInfo.col].sortArg
|
||||
local sortArgB = rowB.cols[st.sortInfo.col].sortArg
|
||||
|
||||
if st.sortInfo.ascending then
|
||||
return sortArgA < sortArgB
|
||||
else
|
||||
return sortArgA > sortArgB
|
||||
end
|
||||
end
|
||||
sort(st.rowData, SortHelper)
|
||||
st.updateSort = nil
|
||||
end
|
||||
|
||||
for i=1, st.sizes.numRows do
|
||||
st.rows[i].data = nil
|
||||
if i > getn(st.rowData) then
|
||||
st.rows[i]:Hide()
|
||||
else
|
||||
st.rows[i]:Show()
|
||||
local data = st.rowData[i + offset]
|
||||
if not data then break end
|
||||
st.rows[i].data = data
|
||||
|
||||
if (st.selected == GetTableIndex(st.rowData, data) and not st.selectionDisabled)
|
||||
or (st.highlighted and st.highlighted == GetTableIndex(st.rowData, data))
|
||||
or st.rows[i].mouseover
|
||||
then
|
||||
st.rows[i].highlight:Show()
|
||||
else
|
||||
st.rows[i].highlight:Hide()
|
||||
end
|
||||
|
||||
for colNum, col in st.rows[i].cols do
|
||||
if st.colInfo[colNum] then
|
||||
local colData = data.cols[colNum]
|
||||
if type(colData.value) == 'function' then
|
||||
col:SetText(colData.value(unpack(colData.args)))
|
||||
else
|
||||
col:SetText(colData.value)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end,
|
||||
|
||||
SetData = function(st, rowData)
|
||||
st.rowData = rowData
|
||||
st.updateSort = true
|
||||
st:RefreshRows()
|
||||
end,
|
||||
|
||||
SetSelection = function(st, predicate)
|
||||
st:ClearSelection()
|
||||
for i, rowDatum in st.rowData do
|
||||
if predicate(rowDatum) then
|
||||
st.selected = i
|
||||
st:RefreshRows()
|
||||
break
|
||||
end
|
||||
end
|
||||
end,
|
||||
|
||||
GetSelection = function(st)
|
||||
return st.selected
|
||||
end,
|
||||
|
||||
ClearSelection = function(st)
|
||||
st.selected = nil
|
||||
st:RefreshRows()
|
||||
end,
|
||||
|
||||
DisableSelection = function(st, value)
|
||||
st.selectionDisabled = value
|
||||
end,
|
||||
|
||||
EnableSorting = function(st, value, defaultCol)
|
||||
st.sortInfo.enabled = value
|
||||
st.sortInfo.col = abs(defaultCol or 1)
|
||||
st.sortInfo.ascending = not defaultCol or defaultCol > 0
|
||||
st.updateSort = true
|
||||
for _, headCol in st.headCols do
|
||||
if value then
|
||||
headCol:EnableMouse(true)
|
||||
else
|
||||
headCol:EnableMouse(false)
|
||||
end
|
||||
end
|
||||
st:RefreshRows()
|
||||
end,
|
||||
|
||||
DisableHighlight = function(st, value)
|
||||
st.highlightDisabled = value
|
||||
end,
|
||||
|
||||
GetNumRows = function(st)
|
||||
return st.sizes.numRows
|
||||
end,
|
||||
|
||||
SetScrollOffset = function(st, offset)
|
||||
local maxOffset = max(getn(st.rowData) - st.sizes.numRows, 0)
|
||||
if not offset or offset < 0 or offset > maxOffset then
|
||||
return -- invalid offset
|
||||
end
|
||||
|
||||
local scrollPercent = offset / maxOffset
|
||||
local maxPixelOffset = st.scrollFrame:GetVerticalScrollRange() + ST_ROW_HEIGHT * 2
|
||||
local pixelOffset = scrollPercent * maxPixelOffset
|
||||
FauxScrollFrame_SetOffset(st.scrollFrame, offset)
|
||||
st.scrollFrame:SetVerticalScroll(pixelOffset)
|
||||
end,
|
||||
|
||||
SetHighlighted = function(st, row)
|
||||
st.highlighted = row
|
||||
st:RefreshRows()
|
||||
end,
|
||||
|
||||
Redraw = function(st)
|
||||
local width = st:GetWidth() - 14
|
||||
local height = st:GetHeight()
|
||||
|
||||
if getn(st.colInfo) > 1 or st.colInfo[1].name then
|
||||
-- there is a header row
|
||||
st.sizes.headHeight = st.sizes.headFontSize and (st.sizes.headFontSize + 4) or ST_HEAD_HEIGHT
|
||||
else
|
||||
-- no header row
|
||||
st.sizes.headHeight = 0
|
||||
end
|
||||
st.sizes.numRows = max(floor((st:GetParent():GetHeight() - st.sizes.headHeight - ST_HEAD_SPACE) / ST_ROW_HEIGHT), 0)
|
||||
|
||||
-- update the frame
|
||||
st.scrollBar:ClearAllPoints()
|
||||
st.scrollBar:SetPoint('BOTTOMRIGHT', st, -1, 1)
|
||||
st.scrollBar:SetPoint('TOPRIGHT', st, -1, -st.sizes.headHeight - ST_HEAD_SPACE - 1)
|
||||
|
||||
if st.sizes.headHeight > 0 then
|
||||
st.headLine:Show()
|
||||
st.headLine:ClearAllPoints()
|
||||
st.headLine:SetPoint('TOPLEFT', 2, -st.sizes.headHeight)
|
||||
st.headLine:SetPoint('TOPRIGHT', -2, -st.sizes.headHeight)
|
||||
else
|
||||
st.headLine:Hide()
|
||||
end
|
||||
|
||||
-- update the first row
|
||||
if st.rows and st.rows[1] then
|
||||
st.rows[1]:SetPoint('TOPLEFT', 0, -(st.sizes.headHeight + ST_HEAD_SPACE))
|
||||
st.rows[1]:SetPoint('TOPRIGHT', 0, -(st.sizes.headHeight + ST_HEAD_SPACE))
|
||||
end
|
||||
|
||||
-- add header columns if necessary
|
||||
while getn(st.headCols) < getn(st.colInfo) do
|
||||
st:AddColumn()
|
||||
end
|
||||
|
||||
-- adjust head col widths
|
||||
for colNum, col in st.headCols do
|
||||
if st.colInfo[colNum] then
|
||||
col:Show()
|
||||
col:SetWidth(st.colInfo[colNum].width * width)
|
||||
col:SetHeight(st.sizes.headHeight)
|
||||
col:SetText(st.colInfo[colNum].name or "")
|
||||
col.text:SetJustifyH(st.colInfo[colNum].headAlign or 'CENTER')
|
||||
else
|
||||
col:Hide()
|
||||
end
|
||||
end
|
||||
|
||||
-- add more rows if necessary
|
||||
while getn(st.rows) < st.sizes.numRows do
|
||||
st:AddRow()
|
||||
end
|
||||
|
||||
-- adjust rows widths
|
||||
for rowNum, row in st.rows do
|
||||
if rowNum > st.sizes.numRows then
|
||||
row.data = nil
|
||||
row:Hide()
|
||||
else
|
||||
row:Show()
|
||||
-- add any missing cols
|
||||
while getn(row.cols) < getn(st.colInfo) do
|
||||
st:AddRowCol(rowNum)
|
||||
end
|
||||
for colNum, col in row.cols do
|
||||
if st.headCols[colNum] and st.colInfo[colNum] then
|
||||
col:Show()
|
||||
col:SetWidth(st.colInfo[colNum].width * width)
|
||||
col.text:SetJustifyH(st.colInfo[colNum].align or 'LEFT')
|
||||
else
|
||||
col:Hide()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
st:RefreshRows()
|
||||
end,
|
||||
|
||||
AddColumn = function(st)
|
||||
local colNum = getn(st.headCols) + 1
|
||||
local col = CreateFrame('Button', st:GetName()..'HeadCol'..colNum, st.contentFrame)
|
||||
if colNum == 1 then
|
||||
col:SetPoint('TOPLEFT', 0, -1)
|
||||
else
|
||||
col:SetPoint('TOPLEFT', st.headCols[colNum - 1], 'TOPRIGHT')
|
||||
end
|
||||
col.st = st
|
||||
col.colNum = colNum
|
||||
col:RegisterForClicks('LeftButtonUp', 'RightButtonUp')
|
||||
col:SetScript('OnClick', OnColumnClick)
|
||||
|
||||
local text = col:CreateFontString()
|
||||
text:SetJustifyV('CENTER')
|
||||
text:SetFont(gui.config.font, 16)
|
||||
text:SetTextColor(unpack(gui.color.text.enabled))
|
||||
text:SetAllPoints()
|
||||
col.text = text
|
||||
col:SetFontString(text)
|
||||
|
||||
local tex = col:CreateTexture()
|
||||
tex:SetAllPoints()
|
||||
tex:SetTexture([[Interface\Buttons\UI-Listbox-Highlight]])
|
||||
tex:SetTexCoord(0.025, 0.957, 0.087, 0.931)
|
||||
tex:SetAlpha(0.2)
|
||||
col:SetHighlightTexture(tex)
|
||||
|
||||
tinsert(st.headCols, col)
|
||||
|
||||
-- add new cells to the rows
|
||||
for rowNum, row in st.rows do
|
||||
while getn(row.cols) < getn(st.headCols) do
|
||||
st:AddRowCol(rowNum)
|
||||
end
|
||||
end
|
||||
end,
|
||||
|
||||
AddRowCol = function(st, rowNum)
|
||||
local row = st.rows[rowNum]
|
||||
local colNum = getn(row.cols) + 1
|
||||
local col = CreateFrame('Button', nil, row)
|
||||
local text = col:CreateFontString()
|
||||
text:SetFont(gui.config.font, ST_ROW_TEXT_SIZE)
|
||||
text:SetJustifyV 'CENTER'
|
||||
text:SetPoint('TOPLEFT', 1, -1)
|
||||
text:SetPoint('BOTTOMRIGHT', -1, 1)
|
||||
col.text = text
|
||||
col:SetFontString(text)
|
||||
col:SetHeight(ST_ROW_HEIGHT)
|
||||
col:RegisterForClicks('LeftButtonUp', 'RightButtonUp')
|
||||
for name, func in defaultColScripts do
|
||||
col:SetScript(name, func)
|
||||
end
|
||||
col.st = st
|
||||
col.row = row
|
||||
|
||||
if colNum == 1 then
|
||||
col:SetPoint('TOPLEFT', 0, 0)
|
||||
else
|
||||
col:SetPoint('TOPLEFT', row.cols[colNum - 1], 'TOPRIGHT')
|
||||
end
|
||||
tinsert(row.cols, col)
|
||||
end,
|
||||
|
||||
AddRow = function(st)
|
||||
local row = CreateFrame('Frame', nil, st.contentFrame)
|
||||
row:SetHeight(ST_ROW_HEIGHT)
|
||||
local rowNum = getn(st.rows) + 1
|
||||
if rowNum == 1 then
|
||||
row:SetPoint('TOPLEFT', 2, -(st.sizes.headHeight + ST_HEAD_SPACE))
|
||||
row:SetPoint('TOPRIGHT', 0, -(st.sizes.headHeight + ST_HEAD_SPACE))
|
||||
else
|
||||
row:SetPoint('TOPLEFT', 2, -(st.sizes.headHeight + ST_HEAD_SPACE + (rowNum - 1) * ST_ROW_HEIGHT))
|
||||
row:SetPoint('TOPRIGHT', 0, -(st.sizes.headHeight + ST_HEAD_SPACE + (rowNum - 1) * ST_ROW_HEIGHT))
|
||||
end
|
||||
local highlight = row:CreateTexture()
|
||||
highlight:SetAllPoints()
|
||||
highlight:SetTexture(1, .9, .9, .1)
|
||||
highlight:Hide()
|
||||
row.highlight = highlight
|
||||
row.st = st
|
||||
|
||||
row.cols = {}
|
||||
st.rows[rowNum] = row
|
||||
for i=1, getn(st.colInfo) do
|
||||
st:AddRowCol(rowNum)
|
||||
end
|
||||
end,
|
||||
|
||||
SetHandler = function(st, event, handler)
|
||||
st.handlers[event] = handler
|
||||
end,
|
||||
|
||||
SetHeadFontSize = function(st, size)
|
||||
st.sizes.headFontSize = size
|
||||
-- update the text size of the head cols
|
||||
for _, col in st.headCols do
|
||||
if st.sizes.headFontSize then
|
||||
col.text:SetFont(gui.config.font, st.sizes.headFontSize)
|
||||
else
|
||||
col.text:SetFont(gui.config.font, gui.config.medium_font_size)
|
||||
end
|
||||
end
|
||||
st:Redraw()
|
||||
end,
|
||||
|
||||
SetColInfo = function(st, colInfo)
|
||||
colInfo = colInfo or DEFAULT_COL_INFO
|
||||
st.colInfo = colInfo
|
||||
st:Redraw()
|
||||
end,
|
||||
}
|
||||
|
||||
function public.CreateScrollingTable(parent)
|
||||
-- create the base frame
|
||||
ST_COUNT = ST_COUNT + 1
|
||||
local st = CreateFrame('Frame', 'TSMScrollingTable'..ST_COUNT, parent)
|
||||
st:SetAllPoints()
|
||||
-- st:SetScript('OnSizeChanged', function() st:Redraw() end)
|
||||
|
||||
local contentFrame = CreateFrame('Frame', nil, st)
|
||||
contentFrame:SetPoint('TOPLEFT', 0, 0)
|
||||
contentFrame:SetPoint('BOTTOMRIGHT', -15, 0)
|
||||
st.contentFrame = contentFrame
|
||||
|
||||
-- frame to hold the header columns and the rows
|
||||
local scrollFrame = CreateFrame('ScrollFrame', st:GetName()..'ScrollFrame', st, 'FauxScrollFrameTemplate')
|
||||
scrollFrame:SetScript('OnVerticalScroll', function(self, offset)
|
||||
FauxScrollFrame_OnVerticalScroll(ST_ROW_HEIGHT, function() st:RefreshRows() end)
|
||||
end)
|
||||
scrollFrame:SetAllPoints(contentFrame)
|
||||
st.scrollFrame = scrollFrame
|
||||
|
||||
local scrollBar = getglobal(scrollFrame:GetName()..'ScrollBar')
|
||||
scrollBar:SetWidth(12)
|
||||
st.scrollBar = scrollBar
|
||||
local thumbTex = scrollBar:GetThumbTexture()
|
||||
thumbTex:SetPoint('CENTER', 0, 0)
|
||||
thumbTex:SetTexture(unpack(gui.color.content.background))
|
||||
thumbTex:SetHeight(50)
|
||||
thumbTex:SetWidth(12)
|
||||
getglobal(scrollBar:GetName()..'ScrollUpButton'):Hide()
|
||||
getglobal(scrollBar:GetName()..'ScrollDownButton'):Hide()
|
||||
|
||||
-- create head line at default position
|
||||
st.headLine = gui.horizontal_line(st, 0)
|
||||
|
||||
-- add all the methods
|
||||
for name, func in methods do
|
||||
st[name] = func
|
||||
end
|
||||
|
||||
-- setup default values
|
||||
st.isTSMScrollingTable = true
|
||||
st.sizes = {}
|
||||
st.headCols = {}
|
||||
st.rows = {}
|
||||
st.handlers = {}
|
||||
st.sortInfo = {enabled=nil}
|
||||
st.colInfo = DEFAULT_COL_INFO
|
||||
|
||||
return st
|
||||
end
|
||||
Reference in New Issue
Block a user