Skip to content

Commit

Permalink
add new generic FormatText fn for custom tags
Browse files Browse the repository at this point in the history
  • Loading branch information
Krealle committed Dec 16, 2024
1 parent a8bb73b commit 9ea8d5c
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions Widgets/Texts/CustomFormats.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ local nameLengths = {
long = 20,
}

local format = string.format

local UnitName = UnitName
local UnitPower = UnitPower
local UnitIsAFK = UnitIsAFK
Expand All @@ -45,6 +47,35 @@ local UnitGetTotalHealAbsorbs = UnitGetTotalHealAbsorbs
-- MARK: Formatting Functions
-------------------------------------------------

---@param max number
---@param min number?
---@param percent boolean?
---@param short boolean?
---@return string? result
---@return boolean? isPositive
local function FormatText(max, min, percent, short)
local isPositive
if percent then
if not min then return end

local val = min / max * 100
isPositive = val > 0

if short then
return format("%d%%", val), isPositive
end

return format("%.2f%%", val), isPositive
end

isPositive = max >= 0
if short then
return F:FormatNumber(max), isPositive
end

return tostring(max), isPositive
end

-- Formats a percent value with decimals
---@param max number
---@param cur number
Expand Down

0 comments on commit 9ea8d5c

Please sign in to comment.