includes/type: Added new color types

This commit is contained in:
Nik
2022-09-30 14:52:30 +02:00
committed by GitHub
parent 27d98d4552
commit 86f38ca545

43
includes/type/color.pat Normal file
View File

@@ -0,0 +1,43 @@
#pragma once
#include <std/io.pat>
namespace type {
struct RGBA8 {
u8 r, g, b, a;
} [[sealed, format("type::impl::format_color")]];
bitfield RGB565 {
r : 5;
g : 6;
b : 5;
} [[sealed, format("type::impl::format_color")]];
bitfield RGBA4 {
r : 4;
g : 4;
b : 4;
a : 4;
} [[sealed, format("type::impl::format_color")]];
namespace impl {
fn format_color(ref auto color) {
if (!std::core::has_member(color, "a")) {
return std::format("#{0:02X}{1:02X}{2:02X} | rgb({0}, {1}, {2})",
color.r,
color.g,
color.b);
} else {
return std::format("#{0:02X}{1:02X}{2:02X}{3:02X} | rgba({0}, {1}, {2}, {3})",
color.r,
color.g,
color.b,
color.a);
}
};
}
}