Merge pull request #752 from Jipok/rgba_hex_fix

Support rgba hex format
This commit is contained in:
Adam 2021-12-20 19:07:38 -05:00 committed by GitHub
commit 19c239de42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 5 deletions

View File

@ -47,22 +47,22 @@ end
function common.color(str) function common.color(str)
local r, g, b, a = str:match("#(%x%x)(%x%x)(%x%x)") local r, g, b, a = str:match("^#(%x%x)(%x%x)(%x%x)(%x?%x?)$")
if r then if r then
r = tonumber(r, 16) r = tonumber(r, 16)
g = tonumber(g, 16) g = tonumber(g, 16)
b = tonumber(b, 16) b = tonumber(b, 16)
a = 1 a = tonumber(a, 16) or 0xff
elseif str:match("rgba?%s*%([%d%s%.,]+%)") then elseif str:match("rgba?%s*%([%d%s%.,]+%)") then
local f = str:gmatch("[%d.]+") local f = str:gmatch("[%d.]+")
r = (f() or 0) r = (f() or 0)
g = (f() or 0) g = (f() or 0)
b = (f() or 0) b = (f() or 0)
a = f() or 1 a = (f() or 1) * 0xff
else else
error(string.format("bad color string '%s'", str)) error(string.format("bad color string '%s'", str))
end end
return r, g, b, a * 0xff return r, g, b, a
end end
@ -349,7 +349,7 @@ function common.relative_path(ref_dir, dir)
if drive and ref_drive and drive ~= ref_drive then if drive and ref_drive and drive ~= ref_drive then
-- Windows, different drives, system.absolute_path fails for C:\..\D:\ -- Windows, different drives, system.absolute_path fails for C:\..\D:\
return dir return dir
end end
local ref_ls = split_on_slash(ref_dir) local ref_ls = split_on_slash(ref_dir)
local dir_ls = split_on_slash(dir) local dir_ls = split_on_slash(dir)
local i = 1 local i = 1