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

fix: use official color:lerp implementation if possible #56

Merged
merged 3 commits into from
Jul 4, 2024
Merged
Changes from 2 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
30 changes: 22 additions & 8 deletions lua/pixelui/core/cl_color.lua
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ do
end

function PIXEL.LerpColor(t, from, to)
return createColor(from.r, from.g, from.b, from.a):Lerp(t, to)
return createColor(from.r, from.g, from.b, from.a):Lerp(to, t)
end

function PIXEL.IsColorEqualTo(from, to)
Expand All @@ -161,11 +161,25 @@ function colorMeta:Offset(offset)
return self
end

local lerp = Lerp
function colorMeta:Lerp(t, to)
self.r = lerp(t, self.r, to.r)
self.g = lerp(t, self.g, to.g)
self.b = lerp(t, self.b, to.b)
self.a = lerp(t, self.a, to.a)
return self
-- Combatibility for versions before 2024.06.28
if not colorMeta.Lerp then
local lerp = Lerp
local isColor = IsColor
function colorMeta:Lerp(target, fraction)
if isColor(fraction) then
-- Don't break addons using this based on Pixel UI for now.
local rememberFraction = fraction
fraction = target
target = rememberFraction

-- Scream at them though, should be fine to keep this backwards compatibility until the update.
ErrorNoHaltWithStack("Deprecated PIXEL-UI Color:Lerp(fraction, target) is used.")
end

self.r = lerp(fraction, self.r, target.r)
self.g = lerp(fraction, self.g, target.g)
self.b = lerp(fraction, self.b, target.b)
self.a = lerp(fraction, self.a, target.a)
return self
end
end