koutil
Loading...
Searching...
No Matches
koutil::term::Color Struct Reference

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.
 

Detailed Description

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.

Member Typedef Documentation

◆ channel_t

using koutil::term::Color::channel_t = std::uint8_t

Member Enumeration Documentation

◆ Tag

enum class koutil::term::Color::Tag : std::uint8_t
strong
Enumerator
RGB 
ID 

Constructor & Destructor Documentation

◆ Color() [1/3]

koutil::term::Color::Color ( )
inlineconstexpr

◆ Color() [2/3]

koutil::term::Color::Color ( channel_t r,
channel_t g,
channel_t b )
inlineconstexpr

Constructor with RGB values.

Initializes the color with the specified RGB values and the RGB tag.

Parameters
rRed channel value.
gGreen channel value.
bBlue channel value.

◆ Color() [3/3]

koutil::term::Color::Color ( std::uint8_t id)
inlineconstexpr

Constructor with an ID value.

Initializes the color with the specified ID value and the ID tag.

Parameters
idID value.

Member Function Documentation

◆ as_bg()

ColorBG koutil::term::Color::as_bg ( ) const
nodiscardconstexpr

Converts the color to a ColorBG object.

Returns
ColorBG object.

◆ as_fg()

ColorFG koutil::term::Color::as_fg ( ) const
nodiscardconstexpr

Converts the color to a ColorFG object.

Returns
ColorFG object.

◆ convert_val()

static constexpr std::uint8_t koutil::term::Color::convert_val ( float val)
inlinestaticconstexprprivate

Converts a floating-point value to a channel value.

Parameters
valFloating-point value.
Returns
Channel value.

◆ extract_value()

static consteval std::uint8_t koutil::term::Color::extract_value ( char val)
inlinestaticconstevalprivate

Extracts a value from a hexadecimal character.

Parameters
valHexadecimal character.
Returns
Extracted value.

◆ from_hex()

static consteval Color koutil::term::Color::from_hex ( std::string_view hex)
inlinestaticconsteval

Creates a Color object from a hexadecimal string.

Parameters
hexHexadecimal string (e.g., "#RRGGBB" or "#RGB").
Returns
Color object.

◆ from_hsv()

Color koutil::term::Color::from_hsv ( std::uint16_t h,
float s,
float v )
staticconstexpr

Creates a Color object from HSV values.

Parameters
hHue value (0-359).
sSaturation value (0.0-1.0).
vValue (0.0-1.0).
Returns
Color object.

◆ from_id()

static constexpr Color koutil::term::Color::from_id ( channel_t id)
inlinestaticconstexpr

Creates a Color object from an ID value.

Parameters
idID value.
Returns
Color object.

◆ from_rgb()

static constexpr Color koutil::term::Color::from_rgb ( channel_t red,
channel_t green,
channel_t blue )
inlinestaticconstexpr

Creates a Color object from RGB values.

Parameters
redRed channel value.
greenGreen channel value.
blueBlue channel value.
Returns
Color object.

◆ get_channels()

std::array< channel_t, 3 > koutil::term::Color::get_channels ( ) const
inlinenodiscardconstexpr

Gets the RGB channel values of the color.

Returns
Array containing red, green, and blue channel values.

◆ id()

channel_t koutil::term::Color::id ( ) const
inlinenodiscardconstexpr

Gets the ID value of the color.

Returns
ID value.

◆ operator==()

bool koutil::term::Color::operator== ( Color other) const
inlineconstexpr

Member Data Documentation

◆ blue

const channel_t koutil::term::Color::blue

◆ green

const channel_t koutil::term::Color::green

◆ red

const channel_t koutil::term::Color::red

◆ tag

const Tag koutil::term::Color::tag

The documentation for this struct was generated from the following file: