NovaSVG 0.10.0
A header-only SVG library
Loading...
Searching...
No Matches
novasvg::color_literals Namespace Reference

String literal operators for creating Color instances. More...

Functions

novasvg::Color operator""_c (const char *str, std::size_t len)
 String literal operator for creating Color instances.
 

Detailed Description

String literal operators for creating Color instances.

This namespace provides the _c suffix operator for creating colors from string literals at compile-time (when possible).

Usage
using namespace novasvg::color_literals;
Color c1 = "red"_c; // From color name
Color c2 = "#FF0000"_c; // From hex
Color c3 = "gray"_c | 50; // Blend with transparent
Color c4 = "gray"_c | 50 | "black"_c; // Chain blends
Represents a color in RGBA format (0xRRGGBBAA).
Definition color.h:85
String literal operators for creating Color instances.
Note
Always include "using namespace novasvg::color_literals;" or use explicit qualification to use these literals.

Function Documentation

◆ operator""_c()

novasvg::Color novasvg::color_literals::operator""_c ( const char *  str,
std::size_t  len 
)
inline

String literal operator for creating Color instances.

This operator allows creating colors using the _c suffix on string literals. It automatically detects whether the string is a hex color code or a color name.

Parameters
strString literal (must include quotes).
lenLength of the string literal.
Returns
Color instance parsed from the string.
Exceptions
std::invalid_argumentIf the format is invalid or the color name is not recognized.
Example
using namespace novasvg::color_literals;
Color c1 = "red"_c; // Color::red()
Color c2 = "#FF0000"_c; // Color::fromHash("#FF0000")
Color c3 = "skyblue"_c; // Color::fromName("skyblue")
Color c4 = "gray"_c | 50; // Blend with 50% transparent
Note
The string must be a valid string literal. For runtime strings, use Color::fromString() instead.

Definition at line 1018 of file color.h.

References novasvg::Color::fromString().