- Clean up DiesalTools

- ObjectBase: Add optional param to `SetParentObject()` adding to parent children.
- AccordianSection: Update color for `content-outline` to `000000`.
- DropDown: Add "dropdownWidth" to allow for the dropdown show to be set to a specific width. Also update dropdown to be shown above everything.
main
jeffi 10 months ago
parent 77148b2c89
commit 264220973c
  1. 32
      DiesalGUI-2.0/Objects/AccordianSection.lua
  2. 14
      DiesalGUI-2.0/Objects/DropDown.lua
  3. 6
      DiesalGUI-2.0/Objects/ObjectBase.lua
  4. 34
      DiesalTools-2.0/DiesalTools-2.0.lua

@ -81,8 +81,8 @@ local Stylesheet = {
["content-inline"] = {
type = "outline",
layer = "ARTWORK",
color = "ffffff",
alpha = 0.02,
color = "000000",
alpha = 1,
position = { 0, 0, -1, 0 },
},
["text-Font"] = {
@ -129,13 +129,19 @@ local methods = {
self.button:SetHeight(self.settings.buttonHeight)
-- postion
self:ClearAllPoints()
local subsectionXOffset = self.settings.subsection and 5 or 0
local subsectionYOffset = self.settings.subsection and -5 or 0
if self.settings.position == 1 then
self:SetPoint("TOPLEFT")
self:SetPoint("RIGHT")
self:SetPoint("TOPLEFT", subsectionXOffset, subsectionYOffset)
self:SetPoint("RIGHT", -subsectionXOffset, 0)
elseif self.settings.subsection then
local anchor = self.settings.parentObject.content
self:SetPoint("TOPLEFT", anchor, "BOTTOMLEFT", subsectionXOffset, subsectionYOffset)
self:SetPoint("RIGHT", -subsectionXOffset, 0)
else
local anchor = self.settings.parentObject.children[self.settings.position - 1].frame
self:SetPoint("TOPLEFT", anchor, "BOTTOMLEFT", 0, 0)
self:SetPoint("RIGHT")
self:SetPoint("TOPLEFT", anchor, "BOTTOMLEFT", subsectionXOffset, subsectionYOffset)
self:SetPoint("RIGHT", -subsectionXOffset, 0)
end
-- set section name
self.text:SetText(self.settings.sectionName)
@ -157,6 +163,10 @@ local methods = {
self.textures["button-leftExpandIcon"]:SetAlpha(0)
self.content:Hide()
self:UpdateHeight()
if self.settings.subsection and self.settings.parentObject then
self.settings.parentObject:ApplySettings()
self.settings.parentObject:UpdateHeight()
end
end,
---@param self DiesalAccordianSection
@ -167,6 +177,10 @@ local methods = {
self.textures["button-leftCollapseIcon"]:SetAlpha(0)
self.content:Show()
self:UpdateHeight()
if self.settings.subsection and self.settings.parentObject then
self.settings.parentObject:ApplySettings()
self.settings.parentObject:UpdateHeight()
end
end,
---@param self DiesalAccordianSection
@ -190,7 +204,7 @@ local methods = {
if settings.expanded then
contentHeight = settings.contentPadding[3] + settings.contentPadding[4]
for i = 1, #children do
contentHeight = contentHeight + children[i].frame:GetHeight()
contentHeight = contentHeight + (children[i].frame:GetHeight() * self.settings.offsetMultiplier)
end
end
self.content:SetHeight(contentHeight)
@ -206,6 +220,8 @@ local methods = {
---@field contentPadding Diesal.GUI.Padding
---@field expanded boolean
---@field buttonHeight number
---@field subsection boolean
---@field offsetMultiplier number
---@class Diesal.GUI.Object.Accordian.Section.Settings : Diesal.GUI.Object.Accordian.Section.Settings.Default
---@field sectionName string
@ -231,6 +247,8 @@ local function Constructor()
contentPadding = { 0, 0, 3, 1 },
expanded = true,
buttonHeight = 16,
subsection = false,
offsetMultiplier = 1.5,
}
local button = self:CreateRegion("Button", "button", frame)

@ -140,8 +140,7 @@ local methods = {
for position, item in ipairs(list) do
local dropdownItem = DiesalGUI:Create("DiesalDropDownItem")
DiesalGUI:OnMouse(dropdownItem.frame, "LeftButton")
self:AddChild(dropdownItem)
dropdownItem:SetParentObject(self)
dropdownItem:SetParentObject(self, true)
dropdownItem:SetSettings({
key = item.key,
value = item.value,
@ -349,6 +348,7 @@ local methods = {
---@param children Frame[]
FixStrata = function(self, strata, parent, children)
parent:SetFrameStrata(strata)
parent:Raise()
for i, child in ipairs(children) do
self:FixStrata(strata, child, {
child:GetChildren() --[[@as Frame]],
@ -365,8 +365,9 @@ local methods = {
---@field itemHeight number
---@field width number
---@field height number
---@field list table
---@field multiSelect boolean
---@field list? table
---@field multiSelect? boolean
---@field dropdownWidth? number
---@class DiesalDropDown : Diesal.GUI.Object.DropDown
@ -408,12 +409,17 @@ local function Constructor()
frame:SetScript("OnClick", function(this, button, down)
if button == "LeftButton" then
if self.dropdown:IsVisible() then
self.dropdown:SetParent(self.frame)
self.dropdown:Hide()
else
self.dropdown:SetParent(UIParent)
DiesalGUI:OnMouse(self.dropdown, button)
self:FixStrata("TOOLTIP", self.dropdown, {
self.dropdown:GetChildren() --[[@as Frame]],
})
if self.settings.dropdownWidth then
self.dropdown:SetPoint("TOPRIGHT", frame, "BOTTOMRIGHT", frame:GetWidth() + self.settings.dropdownWidth, -2)
end
self.dropdown:Show()
end
end

@ -296,7 +296,8 @@ local ObjectBase = {
---@generic T : Diesal.GUI.ObjectBase
---@param self T | Diesal.GUI.ObjectBase
---@param parent? Diesal.Object
SetParentObject = function(self, parent)
---@param addToChildren? boolean
SetParentObject = function(self, parent, addToChildren)
local frame = self.frame
local settings = self.settings
@ -307,6 +308,9 @@ local ObjectBase = {
end
settings.parentObject = parent
if parent and addToChildren then
parent:AddChild(self)
end
end,
---@generic T : Diesal.GUI.ObjectBase

@ -6,18 +6,17 @@ local DiesalTools = LibStub:NewLibrary(MAJOR, MINOR)
if not DiesalTools then
return
end -- No Upgrade needed.
-- ~~| Libraries |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- ~~| Lua Upvalues |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
end
local type, select, pairs, tonumber, tostring = type, select, pairs, tonumber, tostring
local table_concat = table.concat
local setmetatable, getmetatable, next = setmetatable, getmetatable, next
local sub, format, lower, upper, gsub = string.sub, string.format, string.lower, string.upper, string.gsub
local floor, ceil, abs, modf = math.floor, math.ceil, math.abs, math.modf
-- ~~| WoW Upvalues |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
local CreateFrame, UIParent, GetCursorPosition = CreateFrame, UIParent, GetCursorPosition
local GetScreenWidth, GetScreenHeight = GetScreenWidth, GetScreenHeight
-- ~~| Locals |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
local escapeSequences = {
["\a"] = "\\a", -- Bell
["\b"] = "\\b", -- Backspace
@ -30,6 +29,7 @@ local escapeSequences = {
['"'] = '\\"', -- Quotation mark
["|"] = "||",
}
local lua_keywords = {
["and"] = true,
["break"] = true,
@ -72,7 +72,6 @@ local formattedArgs = {}
---@param level number
local function GetCaller(level)
-- ADDON:LogMessage(debugstack(10,2, 0))
for trace in debugstack(level, 2, 0):gmatch("(.-)\n") do
-- Blizzard Sandbox
local match, _, file, line = trace:find("^.*\\(.-):(%d+)")
@ -92,12 +91,14 @@ local function GetCaller(level)
end
return format("%s[%sUnknown Caller%s]|r", colors.orange, colors.red, colors.orange)
end
---@param number number
---@param base? number
local function round(number, base)
base = base or 1
return floor((number + base / 2) / base) * base
end
---@param color string | number | table
---@param g? number
---@param b? number
@ -117,9 +118,10 @@ local function getRGBColorValues(color, g, b)
end
end
---@param value string | number[]
function DiesalTools.GetColor(value)
if not value then
return
return nil
end
if type(value) == "table" and #value >= 3 then
@ -132,8 +134,11 @@ end
-- ~~| API |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function DiesalTools.Stack()
print("|r------------------------------| Stack Trace |-------------------------------")
local stack = debugstack(1, 12, 0)
if not stack then
return
end
print("|r--------------------------------| Stack Trace |---------------------------------")
for trace in stack:gmatch("(.-)\n") do
local match, _, file, line, func = trace:find("^.*\\(.-):(%d+).-`(.*)'$")
if match then
@ -143,14 +148,11 @@ function DiesalTools.Stack()
print("|r--------------------------------------------------------------------------------")
end
--[[ copy = TableCopy(src, dest, metatable)
@Arguments:
dest Table to copy to
src Table to copy
metatable if true copies the metatable as well (boolean)
@Returns:
table copy of table
--]]
---@generic S
---@param src S
---@param dest? table
---@param metatable? boolean
---@return S
function DiesalTools.TableCopy(src, dest, metatable)
if type(src) == "table" then
if not dest then

Loading…
Cancel
Save