koutil
|
Structure representing a color. More...
#include <color.h>
Public Types | |
enum class | Tag : std::uint8_t { RGB , ID } |
using | channel_t = std::uint8_t |
Public Member Functions | |
constexpr | Color () |
constexpr | Color (channel_t r, channel_t g, channel_t b) |
Constructor with RGB values. | |
constexpr | Color (std::uint8_t id) |
Constructor with an ID value. | |
constexpr std::array< channel_t, 3 > | get_channels () const |
Gets the RGB channel values of the color. | |
constexpr channel_t | id () const |
Gets the ID value of the color. | |
constexpr ColorBG | as_bg () const |
Converts the color to a ColorBG object. | |
constexpr ColorFG | as_fg () const |
Converts the color to a ColorFG object. | |
constexpr bool | operator== (Color other) const |
Static Public Member Functions | |
static constexpr Color | from_rgb (channel_t red, channel_t green, channel_t blue) |
Creates a Color object from RGB values. | |
static constexpr Color | from_id (channel_t id) |
Creates a Color object from an ID value. | |
static constexpr Color | from_hsv (std::uint16_t h, float s, float v) |
Creates a Color object from HSV values. | |
static consteval Color | from_hex (std::string_view hex) |
Creates a Color object from a hexadecimal string. | |
Public Attributes | |
const channel_t | red |
const channel_t | green |
const channel_t | blue |
const Tag | tag |
Static Private Member Functions | |
static consteval std::uint8_t | extract_value (char val) |
Extracts a value from a hexadecimal character. | |
static constexpr std::uint8_t | convert_val (float val) |
Converts a floating-point value to a channel value. | |
Structure representing a color.
The Color structure represents a color with red, green, and blue channels. It can also represent a color using an ID value. Color objects can be created from RGB values, ID values, hexadecimal strings, or HSV values.
using koutil::term::Color::channel_t = std::uint8_t |
|
strong |
|
inlineconstexpr |
Constructor with RGB values.
Initializes the color with the specified RGB values and the RGB tag.
r | Red channel value. |
g | Green channel value. |
b | Blue channel value. |
|
inlineconstexpr |
Constructor with an ID value.
Initializes the color with the specified ID value and the ID tag.
id | ID value. |
|
nodiscardconstexpr |
|
nodiscardconstexpr |
|
inlinestaticconstexprprivate |
Converts a floating-point value to a channel value.
val | Floating-point value. |
|
inlinestaticconstevalprivate |
Extracts a value from a hexadecimal character.
val | Hexadecimal character. |
|
inlinestaticconsteval |
|
staticconstexpr |
|
inlinenodiscardconstexpr |
Gets the RGB channel values of the color.
|
inlinenodiscardconstexpr |
Gets the ID value of the color.
|
inlineconstexpr |
const channel_t koutil::term::Color::blue |
const channel_t koutil::term::Color::green |
const channel_t koutil::term::Color::red |
const Tag koutil::term::Color::tag |