Skip to content

Commit

Permalink
add style fns
Browse files Browse the repository at this point in the history
  • Loading branch information
Krealle committed Sep 5, 2024
1 parent 04702d5 commit 7355868
Showing 1 changed file with 68 additions and 9 deletions.
77 changes: 68 additions & 9 deletions Widgets/Bars/ClassBar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,19 @@ function W.UpdateClassBarWidget(button, unit, setting, subSetting, ...)
if not setting or setting == const.OPTION_KIND.COLOR then
widget:UpdateColors()
end
--[[ if widget.enabled and button:IsVisible() then
widget.Update(button)
end ]]
if not setting or setting == const.OPTION_KIND.SPACING then
widget:SetSpacingStyle(styleTable.spacing)
end
if not setting or setting == const.OPTION_KIND.VERTICAL_FILL then
widget:SetFillStyle(styleTable.verticalFill)
end
if not setting or setting == const.OPTION_KIND.SAME_SIZE_AS_HEALTH_BAR then
widget.sameSizeAsHealthBar = styleTable.sameSizeAsHealthBar
widget:UpdateSize()
end
if not setting or setting == const.OPTION_KIND.SIZE then
widget:SetSizeStyle(styleTable.size)
end
end

Handler:RegisterWidget(W.UpdateClassBarWidget, const.WIDGET_KIND.CLASS_BAR)
Expand Down Expand Up @@ -122,20 +132,29 @@ end

---@param self ClassBarWidget
local function UpdateSize(self)
local maxWidth = self.parent:GetWidth()
local maxWidth
if self.sameSizeAsHealthBar then
maxWidth = self.parent:GetWidth()
else
maxWidth = self.width
end
self:SetSize(maxWidth, self.height)

local barWidth = maxWidth / self.maxPower
local totalWidth = (barWidth * self.maxPower) - self.spacing
local startX = (maxWidth - totalWidth) / 2

for i = 1, #self do
local bar = self[i]
bar:ClearAllPoints()

if i <= self.maxPower then
bar:SetWidth(barWidth)
bar:SetSize(barWidth, 8)
bar:ClearAllPoints()
bar:SetSize(barWidth - self.spacing, self.height)

if i == 1 then
bar:SetPoint("TOPLEFT", self.parent, "TOPLEFT", 0, 0)
bar:SetPoint("LEFT", self, "LEFT", startX, 0)
else
bar:SetPoint("TOPLEFT", self[i - 1], "TOPRIGHT", 0, 0)
bar:SetPoint("LEFT", self[i - 1], "RIGHT", self.spacing, 0)
end

bar:Show()
Expand All @@ -145,6 +164,7 @@ local function UpdateSize(self)
end
end


---@param self ClassBarWidget
local function UpdatePowerType(self)
if self.inVehicle and PlayerVehicleHasComboPoints() then
Expand Down Expand Up @@ -465,6 +485,35 @@ local function Disable(self)
return true
end

-------------------------------------------------
-- MARK: Options
-------------------------------------------------

---@param self ClassBarWidget
---@param spacing number
local function SetSpacingStyle(self, spacing)
self.spacing = spacing
self:UpdateSize()
end

---@param self ClassBarWidget
---@param verticalFill boolean
local function SetFillStyle(self, verticalFill)
local orientation = verticalFill and "VERTICAL" or "HORIZONTAL"
for i = 1, #self do
local bar = self[i]
bar:SetOrientation(orientation)
end
end

---@param self ClassBarWidget
---@param sizeSize SizeOpt
local function SetSizeStyle(self, sizeSize)
self.width = sizeSize.width
self.height = sizeSize.height
self:UpdateSize()
end

-------------------------------------------------
-- MARK: CreatePowerBar
-------------------------------------------------
Expand All @@ -485,6 +534,11 @@ function W:CreateClassBar(button)
classBar.enabled = false
classBar.parent = button.widgets.healthBar

classBar.spacing = 5
classBar.sameSizeAsHealthBar = true
classBar.height = 8
classBar.width = 200

classBar.showForVehicle = false
classBar.inVehicle = false
classBar.maxPower = 0
Expand Down Expand Up @@ -547,8 +601,13 @@ function W:CreateClassBar(button)
classBar.TogglePowerEvents = TogglePowerEvents

classBar.SetEnabled = W.SetEnabled
classBar.SetPosition = W.SetPosition
classBar.SetWidgetFrameLevel = W.SetWidgetFrameLevel
classBar._SetIsSelected = W.SetIsSelected

classBar.SetFillStyle = SetFillStyle
classBar.SetSizeStyle = SetSizeStyle
classBar.SetSpacingStyle = SetSpacingStyle
end

W:RegisterCreateWidgetFunc(CUF.constants.WIDGET_KIND.CLASS_BAR, W.CreateClassBar)

0 comments on commit 7355868

Please sign in to comment.