koutil
Loading...
Searching...
No Matches
koutil::term::color_t 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_t ()
 
constexpr color_t (channel_t r, channel_t g, channel_t b)
 Constructor with RGB values.
 
constexpr color_t (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 color_bg_t as_bg () const
 Converts the color to a ColorBG object.
 
constexpr color_fg_t as_fg () const
 Converts the color to a ColorFG object.
 
constexpr bool operator== (color_t other) const
 

Static Public Member Functions

static constexpr color_t from_rgb (channel_t red, channel_t green, channel_t blue)
 Creates a Color object from RGB values.
 
static constexpr color_t from_id (channel_t id)
 Creates a Color object from an ID value.
 
static constexpr color_t from_hsv (std::uint16_t h, float s, float v)
 Creates a Color object from HSV values.
 
static consteval color_t 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_t::channel_t = std::uint8_t

Member Enumeration Documentation

◆ Tag

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

Constructor & Destructor Documentation

◆ color_t() [1/3]

koutil::term::color_t::color_t ( )
inlineconstexpr

◆ color_t() [2/3]

koutil::term::color_t::color_t ( 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_t() [3/3]

koutil::term::color_t::color_t ( 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()

color_bg_t koutil::term::color_t::as_bg ( ) const
nodiscardconstexpr

Converts the color to a ColorBG object.

Returns
ColorBG object.

◆ as_fg()

color_fg_t koutil::term::color_t::as_fg ( ) const
nodiscardconstexpr

Converts the color to a ColorFG object.

Returns
ColorFG object.

◆ convert_val()

static constexpr std::uint8_t koutil::term::color_t::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_t::extract_value ( char val)
inlinestaticconstevalprivate

Extracts a value from a hexadecimal character.

Parameters
valHexadecimal character.
Returns
Extracted value.

◆ from_hex()

static consteval color_t koutil::term::color_t::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_t koutil::term::color_t::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_t koutil::term::color_t::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_t koutil::term::color_t::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_t::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_t::id ( ) const
inlinenodiscardconstexpr

Gets the ID value of the color.

Returns
ID value.

◆ operator==()

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

Member Data Documentation

◆ blue

const channel_t koutil::term::color_t::blue

◆ green

const channel_t koutil::term::color_t::green

◆ red

const channel_t koutil::term::color_t::red

◆ tag

const Tag koutil::term::color_t::tag

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