Support hex colours with 4 chars e.g. #ff0a

This commit is contained in:
Darren Burns
2022-05-03 17:46:29 +01:00
parent 21fa59d6a3
commit b7ebdd323f
2 changed files with 6 additions and 1 deletions

View File

@@ -7,6 +7,6 @@
.list-item {
height: 8;
color: #12a;
color: #12a0;
background: #ffffff00;
}

View File

@@ -278,6 +278,11 @@ class Color(NamedTuple):
if rgb_hex_triple is not None:
r, g, b = rgb_hex_triple
color = cls(int(r + r, 16), int(g + g, 16), int(b + b, 16))
elif rgb_hex_quad is not None:
r, g, b, a = rgb_hex_quad
color = cls(
int(r + r, 16), int(g + g, 16), int(b + b, 16), int(a + a, 16) / 255.0
)
elif rgb_hex is not None:
r, g, b = [int(pair, 16) for pair in split_pairs3(rgb_hex)]
color = cls(r, g, b, 1.0)