Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Power Text hide if empty/full #38

Merged
merged 2 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Menu/Builder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ function Builder:CreatePowerFormatOptions(parent, widgetName)

---@class PowerFormatOptions: OptionsFrame
local f = CUF:CreateFrame(nil, parent, 1, 1, true, true)
f.optionHeight = 70
f.optionHeight = 100
f.id = "PowerFormatOptions"

f.formatDropdown = self:CreateDropdown(parent, widgetName, "Format", 200,
Expand All @@ -917,6 +917,10 @@ function Builder:CreatePowerFormatOptions(parent, widgetName)
SetEnabled(text == L["Custom"])
end)

f.hideIfEmptyOrFull = self:CreateCheckBox(f, widgetName, L["hideIfEmptyOrFull"],
const.OPTION_KIND.HIDE_IF_EMPTY_OR_FULL)
self:AnchorBelow(f.hideIfEmptyOrFull, f.formatEditBox, 35)

local function LoadPageDB()
SetEnabled(HandleWidgetOption(widgetName, const.OPTION_KIND.FORMAT) == const.PowerTextFormat.CUSTOM)
end
Expand Down
9 changes: 9 additions & 0 deletions Widgets/Texts/PowerText.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ function W.UpdatePowerTextWidget(button, unit, setting, subSetting)
widget:SetTextFormat(styleTable.textFormat)
widget:SetFormat(styleTable.format)
end
if not setting or setting == const.OPTION_KIND.HIDE_IF_EMPTY_OR_FULL then
widget.hideIfEmptyOrFull = styleTable.hideIfEmptyOrFull
end

if widget.enabled and button:IsVisible() then
widget.Update(button)
Expand Down Expand Up @@ -167,6 +170,7 @@ function W:CreatePowerText(button)
button.widgets.powerText = powerText

powerText.textFormat = ""
powerText.hideIfEmptyOrFull = false

powerText.SetFormat = PowerText_SetFormat
powerText.SetTextFormat = PowerText_SetTextFormat
Expand All @@ -176,6 +180,11 @@ function W:CreatePowerText(button)
local powerMax = UnitPowerMax(button.states.unit)
local power = UnitPower(button.states.unit)

if self.hideIfEmptyOrFull and (power == 0 or power == powerMax) then
self:Hide()
return
end

if powerMax > 0 and power then
button.widgets.powerText:SetValue(power, powerMax)
button.widgets.powerText:Show()
Expand Down