Represents a CSS color value, like a RGBA color from a #rrggbb or #rgb hex value, or the currentcolor keyword.
More...
#include "donner/css/Color.h"
|
| constexpr | Color (Type value) |
| | Construct a new color object from a supported color type.
|
|
bool | operator== (const Color &other) const |
| | Equality operator.
|
|
bool | operator== (const RGBA &other) const |
| | Equality operator for Color == RGBA.
|
|
bool | operator== (const HSLA &other) const |
|
bool | operator== (const CurrentColor &other) const |
|
bool | isCurrentColor () const |
| | Returns true if the color is currentcolor.
|
|
bool | hasRGBA () const |
| | Returns true if the color is an RGBA color.
|
| RGBA | rgba () const |
| | Returns the RGBA color value, if this object stores an RGBA color.
|
|
bool | hasHSLA () const |
| | Returns true if the color is an HSLA color.
|
| HSLA | hsla () const |
| | Returns the HSLA color value, if this object stores an HSLA color.
|
| RGBA | asRGBA () const |
| | Returns the color as RGBA.
|
| RGBA | resolve (RGBA currentColor, float opacity) const |
| | Resolves the current value of this color to RGBA, by using the current rendering state, such as the currentColor and opacity.
|
|
| static std::optional< Color > | ByName (std::string_view name) |
| | Parse a named color, such as red or steelblue.
|
|
|
Type | value |
| | The color value.
|
|
|
bool | operator== (const RGBA &lhs, const Color &rhs) |
| | Equality operator RGBA == Color.
|
| std::ostream & | operator<< (std::ostream &os, const Color &color) |
| | Ostream output operator.
|
Represents a CSS color value, like a RGBA color from a #rrggbb or #rgb hex value, or the currentcolor keyword.
Colors are parsed using donner::css::parser::ColorParser.
Note that non-RGB colors, such as HSL are not yet supported, see bug https://github.com/jwmcglynn/donner/issues/6.
◆ Color()
| donner::css::Color::Color |
( |
Type | value | ) |
|
|
inlineconstexpr |
Construct a new color object from a supported color type.
For example:
constexpr Color(Type value)
Construct a new color object from a supported color type.
Definition Color.h:141
static constexpr RGBA RGB(uint8_t r, uint8_t g, uint8_t b)
Constructor, for RGB colors, which are fully opaque.
Definition Color.h:38
- Parameters
-
◆ asRGBA()
| RGBA donner::css::Color::asRGBA |
( |
| ) |
const |
◆ ByName()
| std::optional< Color > donner::css::Color::ByName |
( |
std::string_view | name | ) |
|
|
static |
Parse a named color, such as red or steelblue.
All colors on the CSS named color list are supported, https://www.w3.org/TR/css-color-4/#named-colors, plus two special colors, transparent and currentcolor.
- Parameters
-
| name | The color name, such as red or steelblue. |
- Returns
- The parsed color, or std::nullopt if the color could not be parsed.
◆ hsla()
| HSLA donner::css::Color::hsla |
( |
| ) |
const |
|
inline |
Returns the HSLA color value, if this object stores an HSLA color.
- Precondition
- hasHSLA() returns true.
◆ resolve()
| RGBA donner::css::Color::resolve |
( |
RGBA | currentColor, |
|
|
float | opacity ) const |
Resolves the current value of this color to RGBA, by using the current rendering state, such as the currentColor and opacity.
- Parameters
-
| currentColor | The current color, used if this color is currentcolor. |
| opacity | The current opacity, used to multiply the alpha channel. |
◆ rgba()
| RGBA donner::css::Color::rgba |
( |
| ) |
const |
|
inline |
Returns the RGBA color value, if this object stores an RGBA color.
- Precondition
- hasRGBA() returns true.
◆ operator<<
| std::ostream & operator<< |
( |
std::ostream & | os, |
|
|
const Color & | color ) |
|
friend |
Ostream output operator.
Example output:
or
RGBA rgba() const
Returns the RGBA color value, if this object stores an RGBA color.
Definition Color.h:184
- Parameters
-
| os | The output stream. |
| color | The color to output. |
The documentation for this struct was generated from the following files:
- donner/css/Color.h
- donner/css/Color.cc