diff Libs/DF/panel.lua @ 40:a960d5372b0c

- framework update from v22 to v44.
author Tercio
date Wed, 31 Aug 2016 19:55:14 -0300
parents 7944c081e5b4
children e0a8f43009ea
line wrap: on
line diff
--- a/Libs/DF/panel.lua	Tue Jul 19 13:23:40 2016 -0300
+++ b/Libs/DF/panel.lua	Wed Aug 31 19:55:14 2016 -0300
@@ -1496,7 +1496,7 @@
 
 function DF:CreateScaleBar (frame, config)
 	local scaleBar = DF:CreateSlider (frame, 120, 14, 0.6, 1.6, 0.1, config.scale, true, "ScaleBar", nil, "Scale:", DF:GetTemplate ("slider", "OPTIONS_SLIDER_TEMPLATE"), DF:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE"))
-	scaleBar:SetPoint ("right", frame.Close, "left", -2, 0)
+	scaleBar:SetPoint ("right", frame.Close, "left", -26, 0)
 	scaleBar:SetFrameLevel (DF.FRAMELEVEL_OVERLAY)
 	scaleBar.OnValueChanged = function (_, _, value)
 		config.scale = value
@@ -2523,7 +2523,7 @@
 
 	local pixel = self.Graphic:GetWidth() / self.TimeScale
 	local index = 1
-	local r, g, b = unpack (color)
+	local r, g, b = unpack (color or line_default_color)
 	
 	for i = 1, #overlayData, 2 do
 		local aura_start = overlayData [i]
@@ -3009,7 +3009,7 @@
 	
 	local timeline = f:CreateFontString (nil, "overlay", "GameFontNormal")
 	timeline:SetPoint ("bottomright", f, "bottomright", -2, 0)
-	_detalhes:SetFontSize (timeline, 8)
+	DF:SetFontSize (timeline, 8)
 	f.timeline = timeline
 	
 	return f
@@ -3050,8 +3050,11 @@
 		end
 	end
 	
+	self.MaxValue = max_value
+	
 	local o = 1
 	local lastvalue = self:GetHeight()/2
+	max_value = math.max (max_value, 0.0000001)
 	
 	for i = 1, min (amtlines, self._maxlines) do
 		
@@ -3096,6 +3099,8 @@
 	f.Reset = gframe_reset
 	f.UpdateLines = gframe_update
 	
+	f.MaxValue = 0
+	
 	f._lines = {}
 	
 	f._onenter_line = onenter
@@ -3330,10 +3335,263 @@
 
 
 
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+-- ~listbox
 
+local simple_list_box_ResetWidgets = function (self)
+	for _, widget in ipairs (self.widgets) do 
+		widget:Hide()
+	end
+	self.nextWidget = 1
+end
 
+local simple_list_box_onenter = function (self, capsule)
+	self:GetParent().options.onenter (self, capsule, capsule.value)
+end
 
+local simple_list_box_onleave = function (self, capsule)
+	self:GetParent().options.onleave (self, capsule, capsule.value)
+	GameTooltip:Hide()
+end
 
+local simple_list_box_GetOrCreateWidget = function (self)
+	local index = self.nextWidget
+	local widget = self.widgets [index]
+	if (not widget) then
+		widget = DF:CreateButton (self, function()end, self.options.width, self.options.row_height, "", nil, nil, nil, nil, nil, nil, DF:GetTemplate ("button", "OPTIONS_BUTTON_TEMPLATE"))
+		widget:SetHook ("OnEnter", simple_list_box_onenter)
+		widget:SetHook ("OnLeave", simple_list_box_onleave)
+		widget.textcolor = self.options.textcolor
+		tinsert (self.widgets, widget)
+	end
+	self.nextWidget = self.nextWidget + 1
+	return widget
+end
 
+local simple_list_box_RefreshWidgets = function (self)
+	self:ResetWidgets()
+	local amt = 0
+	for value, _ in pairs (self.list_table) do
+		local widget = self:GetOrCreateWidget()
+		widget:SetPoint ("topleft", self, "topleft", 1, -self.options.row_height * (self.nextWidget-2) - 4)
+		widget:SetPoint ("topright", self, "topright", -1, -self.options.row_height * (self.nextWidget-2) - 4)
+		widget:SetClickFunction (self.func, value)
+		widget.value = value
+		
+		if (self.options.icon) then
+			if (type (self.options.icon) == "string" or type (self.options.icon) == "number") then
+				widget:SetIcon (self.options.icon, self.options.row_height, self.options.row_height)
+			elseif (type (self.options.icon) == "function") then
+				local icon = self.options.icon (value)
+				if (icon) then
+					widget:SetIcon (icon, self.options.row_height, self.options.row_height)
+				end
+			end
+		else
+			widget:SetIcon ("", self.options.row_height, self.options.row_height)
+		end
+		
+		if (self.options.text) then
+			if (type (self.options.text) == "function") then
+				local text = self.options.text (value)
+				if (text) then
+					widget:SetText (text)
+				else
+					widget:SetText ("")
+				end
+			else
+				widget:SetText (self.options.text or "")
+			end
+		else
+			widget:SetText ("")
+		end
+		
+		widget.value = value
+		widget:Show()
+		amt = amt + 1
+	end
+	if (amt == 0) then
+		self.EmptyLabel:Show()
+	else
+		self.EmptyLabel:Hide()
+	end
+end
 
+local backdrop = {bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", tile = true, tileSize = 16, edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1}
+local default_options = {
+	height = 400, 
+	row_height = 16,
+	width = 230, 
+	icon = false, 
+	text = "",
+	textcolor = "wheat",
+	onenter = function (self, capsule)
+		if (capsule) then
+			capsule.textcolor = "white"
+		end
+	end,
+	onleave = function (self, capsule)
+		if (capsule) then
+			capsule.textcolor = self:GetParent().options.textcolor
+		end
+		GameTooltip:Hide()
+	end,
+}
 
+local simple_list_box_SetData = function (self, t)
+	self.list_table = t
+end
+
+function DF:CreateSimpleListBox (parent, name, title, empty_text, list_table, onclick, options)
+	local f = CreateFrame ("frame", name, parent)
+	
+	f.ResetWidgets = simple_list_box_ResetWidgets
+	f.GetOrCreateWidget = simple_list_box_GetOrCreateWidget
+	f.Refresh = simple_list_box_RefreshWidgets
+	f.SetData = simple_list_box_SetData
+	f.nextWidget = 1
+	f.list_table = list_table
+	f.func = function (self, button, value)
+		onclick (value)
+		f:Refresh()
+	end
+	f.widgets = {}
+	f:SetBackdrop (backdrop)
+	f:SetBackdropColor (0, 0, 0, 0.3)
+	f:SetBackdropBorderColor (0, 0, 0, 0.5)
+	f.options = options or {}
+	self.table.deploy (f.options, default_options)
+	
+	f:SetSize (f.options.width + 2, f.options.height)
+	
+	local name = DF:CreateLabel (f, title, 12, "silver")
+	name:SetTemplate (DF:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE"))
+	name:SetPoint ("bottomleft", f, "topleft", 0, 2)
+	f.Title = name
+	
+	local emptyLabel = DF:CreateLabel (f, empty_text, 12, "gray")
+	emptyLabel:SetAlpha (.6)
+	emptyLabel:SetSize (f.options.width-10, f.options.height)
+	emptyLabel:SetPoint ("center", 0, 0)
+	emptyLabel:Hide()
+	emptyLabel.align = "center"
+	f.EmptyLabel = emptyLabel
+	
+	return f
+end
+
+
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+-- ~scrollbox
+
+
+-- preciso de uma fauxscroll que seja facil de lidar
+-- ele cria scroll aqui, preciso falar a função que cria a linha e a função que atualiza
+-- precisa passsar o tamanho em height width quantas barras vai mostrar
+-- search box incluso opcionalmente
+
+
+DF.SortFunctions = {}
+
+local SortMember = ""
+local SortByMember = function (t1, t2)
+	return t1[SortMember] > t2[SortMember]
+end
+local SortByMemberReverse = function (t1, t2)
+	return t1[SortMember] < t2[SortMember]
+end
+
+DF.SortFunctions.Sort = function (self, t, by, is_reverse)
+	SortMember = by
+	if (not is_reverse) then
+		table.sort (t, SortByMember)
+	else
+		table.sort (t, SortByMemberReverse)
+	end
+end
+
+
+DF.ScrollBoxFunctions = {}
+
+DF.ScrollBoxFunctions.Refresh = function (self)
+	for _, frame in ipairs (self.Frames) do 
+		frame:Hide()
+		frame._InUse = nil
+	end
+	
+	local offset = 0
+	if (self.IsFauxScroll) then
+		FauxScrollFrame_Update (self, #self.data, self.LineAmount, self.LineHeight+1)
+		offset = FauxScrollFrame_GetOffset (self)
+	end	
+	
+	local okay, totalLines = pcall (self.refresh_func, self, self.data, offset, #self.Frames)
+	if (not okay) then
+		error ("Details! FrameWork: Refresh(): " .. totalLines)
+	end
+
+	for _, frame in ipairs (self.Frames) do 
+		if (not frame._InUse) then
+			frame:Hide()
+		else
+			frame:Show()
+		end
+	end
+	
+	self:Show()
+	
+	return self.Frames
+end
+
+DF.ScrollBoxFunctions.OnVerticalScroll = function (self, offset)
+	FauxScrollFrame_OnVerticalScroll (self, offset, self.LineHeight, self.Refresh)
+	return true
+end
+
+DF.ScrollBoxFunctions.CreateLine = function (self, func)
+	local okay, newLine = pcall (func, self, #self.Frames+1)
+	if (okay) then
+		tinsert (self.Frames, newLine)
+		return newLine
+	else
+		error ("Details! FrameWork: CreateLine(): " .. newLine)
+	end
+end
+
+DF.ScrollBoxFunctions.GetLine = function (self, line_index)
+	local line = self.Frames [line_index]
+	if (line) then
+		line._InUse = true
+	end
+	return line
+end
+
+DF.ScrollBoxFunctions.SetData = function (self, data)
+	self.data = data
+end
+DF.ScrollBoxFunctions.GetData = function (self)
+	return self.data
+end
+
+function DF:CreateScrollBox (parent, name, refresh_func, data, width, height, line_amount, line_height)
+	local scroll = CreateFrame ("scrollframe", name, parent, "FauxScrollFrameTemplate")
+	
+	scroll:SetSize (width, height)
+	scroll.LineAmount = line_amount
+	scroll.LineHeight = line_height
+	scroll.IsFauxScroll = true
+	scroll.Frames = {}
+	
+	DF:Mixin (scroll, DF.SortFunctions)
+	DF:Mixin (scroll, DF.ScrollBoxFunctions)
+	
+	scroll.refresh_func = refresh_func
+	scroll.data = data
+	
+	scroll:SetScript ("OnVerticalScroll", scroll.OnVerticalScroll)
+	
+	return scroll
+end
+
+
+