mirror of
https://github.com/appgurueu/modlib.git
synced 2024-08-19 21:04:13 +02:00
Colorspec: Support name#%x
This commit is contained in:
parent
5dd5e50704
commit
da0fc453cd
@ -203,7 +203,7 @@ function colorspec.from_string(string)
|
|||||||
if not number then
|
if not number then
|
||||||
local name, alpha_text = string:match("^([a-z]+)" .. hex .. "$")
|
local name, alpha_text = string:match("^([a-z]+)" .. hex .. "$")
|
||||||
if name then
|
if name then
|
||||||
if alpha_text:len() ~= 2 then
|
if alpha_text:len() > 2 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
number = named_colors[name]
|
number = named_colors[name]
|
||||||
@ -211,6 +211,9 @@ function colorspec.from_string(string)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
alpha = tonumber(alpha_text, 0x10)
|
alpha = tonumber(alpha_text, 0x10)
|
||||||
|
if alpha_text:len() == 1 then
|
||||||
|
alpha = alpha * 0x11
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if number then
|
if number then
|
||||||
|
1
test.lua
1
test.lua
@ -389,6 +389,7 @@ local spec = colorspec.from_number_rgba(0xDDCCBBAA)
|
|||||||
assertdump(table.equals(spec, {a = 0xAA, b = 0xBB, g = 0xCC, r = 0xDD}), spec)
|
assertdump(table.equals(spec, {a = 0xAA, b = 0xBB, g = 0xCC, r = 0xDD}), spec)
|
||||||
test_from_string("aliceblue", 0xf0f8ffff)
|
test_from_string("aliceblue", 0xf0f8ffff)
|
||||||
test_from_string("aliceblue#42", 0xf0f8ff42)
|
test_from_string("aliceblue#42", 0xf0f8ff42)
|
||||||
|
test_from_string("aliceblue#3", 0xf0f8ff33)
|
||||||
test_from_string("#333", 0x333333FF)
|
test_from_string("#333", 0x333333FF)
|
||||||
test_from_string("#694269", 0x694269FF)
|
test_from_string("#694269", 0x694269FF)
|
||||||
test_from_string("#11223344", 0x11223344)
|
test_from_string("#11223344", 0x11223344)
|
||||||
|
Loading…
Reference in New Issue
Block a user