Framework update

This commit is contained in:
Tercio Jose
2022-08-18 10:11:27 -03:00
parent 145233f9c5
commit 0551c6ea62
2 changed files with 114 additions and 81 deletions
+108 -78
View File
@@ -6066,131 +6066,151 @@ local default_radiogroup_options = {
}
DF.RadioGroupCoreFunctions = {
RadioOnClick = function (self, fixedParam, value)
--turn off all checkboxes
local frameList = {self:GetParent():GetChildren()}
for _, checkbox in ipairs (frameList) do
checkbox = checkbox.GetCapsule and checkbox:GetCapsule() or checkbox
checkbox:SetValue (false)
end
--turn on the clicked checkbox
self:SetValue (true)
--callback
DF:QuickDispatch (self._set, fixedParam)
end,
Disable = function (self)
local frameList = {self:GetChildren()}
for _, checkbox in ipairs (frameList) do
local frameList = self:GetAllCheckboxes()
for _, checkbox in ipairs(frameList) do
checkbox = checkbox.GetCapsule and checkbox:GetCapsule() or checkbox
checkbox:Disable()
end
end,
Enable = function (self)
local frameList = {self:GetChildren()}
for _, checkbox in ipairs (frameList) do
local frameList = self:GetAllCheckboxes()
for _, checkbox in ipairs(frameList) do
checkbox = checkbox.GetCapsule and checkbox:GetCapsule() or checkbox
checkbox:Enable()
end
end,
DeselectAll = function (self)
local frameList = {self:GetChildren()}
for _, checkbox in ipairs (frameList) do
DeselectAll = function(self)
local frameList = self:GetAllCheckboxes()
for _, checkbox in ipairs(frameList) do
checkbox = checkbox.GetCapsule and checkbox:GetCapsule() or checkbox
checkbox:SetValue (false)
checkbox:SetValue(false)
end
end,
FadeIn = function (self)
local frameList = {self:GetChildren()}
for _, checkbox in ipairs (frameList) do
checkbox:SetAlpha (1)
FadeIn = function(self)
local frameList = self:GetAllCheckboxes()
for _, checkbox in ipairs(frameList) do
checkbox:SetAlpha(1)
end
end,
FadeOut = function (self)
local frameList = {self:GetChildren()}
for _, checkbox in ipairs (frameList) do
checkbox:SetAlpha (.7)
FadeOut = function(self)
local frameList = self:GetAllCheckboxes()
for _, checkbox in ipairs(frameList) do
checkbox:SetAlpha(.7)
end
end,
SetFadeState = function (self, state)
SetFadeState = function(self, state)
if (state) then
self:FadeIn()
else
self:FadeOut()
end
end,
CreateCheckbox = function (self)
local checkbox = DF:CreateSwitch (self, function()end, false, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, DF:GetTemplate ("switch", "OPTIONS_CHECKBOX_BRIGHT_TEMPLATE"))
checkbox:SetAsCheckBox()
checkbox.Icon = DF:CreateImage (checkbox, "", 16, 16)
checkbox.Label = DF:CreateLabel (checkbox, "")
GetAllCheckboxes = function(self)
return {self:GetChildren()}
end,
GetCheckbox = function(self, checkboxId)
local allCheckboxes = self:GetAllCheckboxes()
local checkbox = allCheckboxes[checkboxId]
if (not checkbox) then
checkbox = self:CreateCheckbox()
end
return checkbox
end,
RefreshCheckbox = function (self, checkbox, optionTable)
checkbox = checkbox.GetCapsule and checkbox:GetCapsule() or checkbox
CreateCheckbox = function(self)
local checkbox = DF:CreateSwitch(self, function()end, false, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, DF:GetTemplate ("switch", "OPTIONS_CHECKBOX_BRIGHT_TEMPLATE"))
checkbox:SetAsCheckBox()
checkbox.Icon = DF:CreateImage(checkbox, "", 16, 16)
checkbox.Label = DF:CreateLabel(checkbox, "")
local setFunc = self.options.is_radio and self.RadioOnClick or optionTable.set
checkbox:SetSwitchFunction (setFunc)
checkbox._set = setFunc
checkbox:SetFixedParameter (optionTable.param)
local isChecked = DF:Dispatch (optionTable.get)
checkbox:SetValue (isChecked)
checkbox.Label:SetText (optionTable.name)
if (optionTable.texture) then
checkbox.Icon:SetTexture (optionTable.texture)
checkbox.Icon:SetPoint ("left", checkbox, "right", 2, 0)
checkbox.Label:SetPoint ("left", checkbox.Icon, "right", 2, 0)
if (optionTable.texcoord) then
checkbox.Icon:SetTexCoord (unpack (optionTable.texcoord))
else
checkbox.Icon:SetTexCoord (0, 1, 0, 1)
end
else
checkbox.Icon:SetTexture ("")
checkbox.Label:SetPoint ("left", checkbox, "right", 2, 0)
return checkbox
end,
ResetAllCheckboxes = function(self)
local radioCheckboxes = self:GetAllCheckboxes()
for i = 1, #radioCheckboxes do
local checkBox = radioCheckboxes[i]
checkBox:Hide()
end
end,
Refresh = function (self)
local radioOptions = self.RadioOptionsTable
local radioCheckboxes = {self:GetChildren()}
--if the list of checkboxes are a radio group
RadioOnClick = function(checkbox, fixedParam, value)
--turn off all checkboxes
checkbox:GetParent():DeselectAll()
for _, checkbox in ipairs (radioCheckboxes) do
checkbox:Hide()
--turn on the clicked checkbox
checkbox:SetValue(true)
--callback
if (checkbox._callback) then
DF:QuickDispatch(checkbox._callback, fixedParam, checkbox._optionid)
end
end,
RefreshCheckbox = function(self, checkbox, optionTable, optionId)
checkbox = checkbox.GetCapsule and checkbox:GetCapsule() or checkbox
for radioIndex, optionsTable in ipairs (radioOptions) do
local checkbox = radioCheckboxes [radioIndex]
if (not checkbox) then
checkbox = self:CreateCheckbox()
local setFunc = self.options.is_radio and self.RadioOnClick or optionTable.set
checkbox:SetSwitchFunction(setFunc)
checkbox._callback = optionTable.callback
checkbox._set = self.options.is_radio and optionTable.callback or optionTable.set
checkbox._optionid = optionId
checkbox:SetFixedParameter(optionTable.param or optionId)
local isChecked = type(optionTable.get) == "function" and DF:Dispatch(optionTable.get) or false
checkbox:SetValue(isChecked)
checkbox.Label:SetText(optionTable.name)
if (optionTable.texture) then
checkbox.Icon:SetTexture(optionTable.texture)
checkbox.Icon:SetPoint("left", checkbox, "right", 2, 0)
checkbox.Label:SetPoint("left", checkbox.Icon, "right", 2, 0)
if (optionTable.texcoord) then
checkbox.Icon:SetTexCoord(unpack(optionTable.texcoord))
else
checkbox.Icon:SetTexCoord(0, 1, 0, 1)
end
checkbox.OptionID = radioIndex
else
checkbox.Icon:SetTexture("")
checkbox.Label:SetPoint("left", checkbox, "right", 2, 0)
end
end,
Refresh = function(self)
self:ResetAllCheckboxes()
local radioOptions = self:GetOptions()
local radioCheckboxes = self:GetAllCheckboxes()
for optionId, optionsTable in ipairs(radioOptions) do
local checkbox = self:GetCheckbox(optionId)
checkbox.OptionID = optionId
checkbox:Show()
self:RefreshCheckbox (checkbox, optionsTable)
self:RefreshCheckbox(checkbox, optionsTable, optionId)
end
--sending false to automatically use the radio group children
self:ArrangeFrames (false, self.AnchorOptions)
self:ArrangeFrames(false, self.AnchorOptions)
end,
SetOptions = function (self, radioOptions)
SetOptions = function(self, radioOptions)
self.RadioOptionsTable = radioOptions
self:Refresh()
end,
GetOptions = function(self)
return self.RadioOptionsTable
end,
}
--[=[
@@ -6201,7 +6221,7 @@ DF.RadioGroupCoreFunctions = {
options: override options for default_radiogroup_options table
anchorOptions: override options for default_framelayout_options table
--]=]
function DF:CreateRadionGroup (parent, radioOptions, name, options, anchorOptions)
function DF:CreateCheckboxGroup(parent, radioOptions, name, options, anchorOptions)
local f = CreateFrame ("frame", name, parent, "BackdropTemplate")
DF:Mixin (f, DF.OptionsFunctions)
@@ -6228,6 +6248,16 @@ function DF:CreateRadionGroup (parent, radioOptions, name, options, anchorOption
return f
end
function DF:CreateRadionGroup(parent, radioOptions, name, options, anchorOptions) --alias for miss spelled old function
return DF:CreateRadioGroup(parent, radioOptions, name, options, anchorOptions)
end
function DF:CreateRadioGroup(parent, radioOptions, name, options, anchorOptions)
options = options or {}
options.is_radio = true
return DF:CreateCheckboxGroup(parent, radioOptions, name, options, anchorOptions)
end
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--> load conditions panel