Skip to content

Commit

Permalink
powerprediction: Add dynamic size adjustment
Browse files Browse the repository at this point in the history
  • Loading branch information
ls- committed Jul 16, 2024
1 parent 17c4399 commit 07e3f10
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions elements/powerprediction.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ local ADDITIONAL_POWER_BAR_INDEX = 0

local _, playerClass = UnitClass('player')

local function UpdateSize(self, event, unit)
local element = self.PowerPrediction

if(element.mainBar and element.mainSize) then
element.mainBar[element.isMainHoriz and 'SetWidth' or 'SetHeight'](element.mainBar, element.mainSize)
end

if(element.altBar and element.altSize) then
element.altBar[element.isAltHoriz and 'SetWidth' or 'SetHeight'](element.altBar, element.altSize)
end
end

local function Update(self, event, unit)
if(self.unit ~= unit) then return end

Expand Down Expand Up @@ -129,7 +141,45 @@ local function Update(self, event, unit)
end
end

local function shouldUpdateMainSize(self)
if(not self.Power) then return end

local isHoriz = self.Power:GetOrientation() == 'HORIZONTAL'
local newSize = self.Power[isHoriz and 'GetWidth' or 'GetHeight'](self.Power)
if(isHoriz ~= self.PowerPrediction.isMainHoriz or newSize ~= self.PowerPrediction.mainSize) then
self.PowerPrediction.isMainHoriz = isHoriz
self.PowerPrediction.mainSize = newSize

return true
end
end

local function shouldUpdateAltSize(self)
if(not self.AdditionalPower) then return end

local isHoriz = self.AdditionalPower:GetOrientation() == 'HORIZONTAL'
local newSize = self.AdditionalPower[isHoriz and 'GetWidth' or 'GetHeight'](self.AdditionalPower)
if(isHoriz ~= self.PowerPrediction.isAltHoriz or newSize ~= self.PowerPrediction.altSize) then
self.PowerPrediction.isAltHoriz = isHoriz
self.PowerPrediction.altSize = newSize

return true
end
end

local function Path(self, ...)
--[[ Override: PowerPrediction.UpdateSize(self, event, unit, ...)
Used to completely override the internal function for updating the widgets' size.
* self - the parent object
* event - the event triggering the update (string)
* unit - the unit accompanying the event (string)
* ... - the arguments accompanying the event
--]]
if(shouldUpdateMainSize(self) or shouldUpdateAltSize(self)) then
(self.PowerPrediction.UpdateSize or UpdateSize) (self, ...)
end

--[[ Override: PowerPrediction.Override(self, event, unit, ...)
Used to completely override the internal update function.
Expand Down

0 comments on commit 07e3f10

Please sign in to comment.