6#include <Ultralight/CAPI/CAPI_ColorTypes.h>
9#include <Ultralight/detail/Css.h>
25concept Utf8StringLike = !std::is_same_v<std::remove_cvref_t<T>,
String>
26 &&
requires(
const T& text) {
27 { text.data() } -> std::convertible_to<const char*>;
28 { text.size() } -> std::convertible_to<size_t>;
101 constexpr Color(
float red,
float green,
float blue,
float alpha = 1.0f)
112 UL_CSS_CONSTEVAL
Color(
const char (&s)[N]) {
113 const detail::CssColor c = detail::ParseCssColor(s, N - 1);
114 if (c.status != detail::CssStatus::Ok) {
115 if (std::is_constant_evaluated())
116 detail::RaiseCssError(c.status);
136 constexpr operator ULColor()
const {
return ULColor {
r,
g,
b,
a,
space,
flags }; }
159 template <detail::Utf8StringLike S>
197static_assert(
sizeof(
Color) ==
sizeof(ULColor),
"Color must mirror ULColor");
#define UExport
Definition Exports.h:22
An RGBA color value in a certain color space (with CSS parsing helpers).
Definition Color.h:69
static Color Parse(const S &css)
Parse CSS color text held in any UTF-8 string type with data() and size() (eg, std::string or std::st...
Definition Color.h:160
static Color Parse(const String &css)
Parse a CSS color string at runtime: the full CSS color grammar (named colors, hex,...
constexpr Color(const ULColor &c)
Create a Color from its C mirror (implicit; the two carry identical state).
Definition Color.h:130
float r
Red, 0..1, in the space named by space.
Definition Color.h:86
Space
The color space of the channels.
Definition Color.h:74
@ kSRGB
sRGB (the only value currently produced or accepted).
Definition Color.h:75
float a
Alpha, 0..1, linear (1 is fully opaque).
Definition Color.h:89
String ToHexString() const
Serialize this color as CSS hex text: lowercase #rrggbb, or #rrggbbaa when the alpha channel is not f...
friend constexpr bool operator==(const Color &, const Color &)=default
constexpr Color(float red, float green, float blue, float alpha=1.0f)
Create a set sRGB color from float channels (0..1; alpha 1 is fully opaque).
Definition Color.h:101
float b
Blue, 0..1.
Definition Color.h:88
float g
Green, 0..1.
Definition Color.h:87
uint8_t flags
A Flags combination (see is_set() and invalid()).
Definition Color.h:91
constexpr bool invalid() const
Whether or not this color came from a string that failed to parse (Parse() at runtime,...
Definition Color.h:187
constexpr Color()=default
Create an unset Color (the receiving field's default applies).
UL_CSS_CONSTEVAL Color(const char(&s)[N])
Create a Color from a CSS string literal, parsed and validated at compile time.
Definition Color.h:112
constexpr bool is_set() const
Whether or not this color was explicitly set.
Definition Color.h:180
Flags
State bits carried in flags.
Definition Color.h:81
@ kSet
Explicitly set (unset means the receiving field's default applies).
Definition Color.h:82
@ kInvalid
Came from a string that failed to parse; ignored with a warning.
Definition Color.h:83
uint8_t space
A Space value.
Definition Color.h:90
Unicode string container with conversions for UTF-8, UTF-16, and UTF-32.
Definition String.h:31
String()
Create empty string.
@ String
UTF-8 text (from strings and enums).
Definition ValueTraits.h:31
Root namespace for every public Ultralight type, function, and enumeration.