ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
esphome::Color Struct Reference

#include <color.h>

Public Member Functions

 operator lv_color_t () const
 
constexpr Color () ESPHOME_ALWAYS_INLINE
 
constexpr Color (uint8_t red, uint8_t green, uint8_t blue) ESPHOME_ALWAYS_INLINE
 
constexpr Color (uint8_t red, uint8_t green, uint8_t blue, uint8_t white) ESPHOME_ALWAYS_INLINE
 
constexpr Color (uint32_t colorcode) ESPHOME_ALWAYS_INLINE
 
bool is_on () const ESPHOME_ALWAYS_INLINE
 
bool operator== (const Color &rhs) const
 
bool operator== (uint32_t colorcode) const
 
bool operator!= (const Color &rhs) const
 
bool operator!= (uint32_t colorcode) const
 
uint8_t & operator[] (uint8_t x) ESPHOME_ALWAYS_INLINE
 
const uint8_t & operator[] (uint8_t x) const ESPHOME_ALWAYS_INLINE
 
Color operator* (uint8_t scale) const ESPHOME_ALWAYS_INLINE
 
Color operator~ () const ESPHOME_ALWAYS_INLINE
 
Color & operator*= (uint8_t scale) ESPHOME_ALWAYS_INLINE
 
Color operator* (const Color &scale) const ESPHOME_ALWAYS_INLINE
 
Color & operator*= (const Color &scale) ESPHOME_ALWAYS_INLINE
 
Color operator+ (const Color &add) const ESPHOME_ALWAYS_INLINE
 
Color & operator+= (const Color &add) ESPHOME_ALWAYS_INLINE
 
Color operator+ (uint8_t add) const ESPHOME_ALWAYS_INLINE
 
Color & operator+= (uint8_t add) ESPHOME_ALWAYS_INLINE
 
Color operator- (const Color &subtract) const ESPHOME_ALWAYS_INLINE
 
Color & operator-= (const Color &subtract) ESPHOME_ALWAYS_INLINE
 
Color operator- (uint8_t subtract) const ESPHOME_ALWAYS_INLINE
 
Color & operator-= (uint8_t subtract) ESPHOME_ALWAYS_INLINE
 
Color gradient (const Color &to_color, uint8_t amnt) const
 
Color fade_to_white (uint8_t amnt) const
 
Color fade_to_black (uint8_t amnt) const
 
Color lighten (uint8_t delta)
 
Color darken (uint8_t delta)
 

Static Public Member Functions

static Color random_color ()
 
static uint8_t blend_channel (uint8_t from, uint8_t to, uint8_t amnt) ESPHOME_ALWAYS_INLINE
 One channel of gradient(): from at amnt 0 to to at amnt 255.
 

Data Fields

union { 
 
   struct { 
 
      union { 
 
         uint8_t   r 
 
         uint8_t   red 
 
      }  
 
      union { 
 
         uint8_t   g 
 
         uint8_t   green 
 
      }  
 
      union { 
 
         uint8_t   b 
 
         uint8_t   blue 
 
      }  
 
      union { 
 
         uint8_t   w 
 
         uint8_t   white 
 
      }  
 
   }  
 
   uint8_t   raw [4] 
 
   uint32_t   raw_32 
 
};  
 

Static Public Attributes

static const Color BLACK
 
static const Color WHITE
 

Detailed Description

Definition at line 32 of file color.h.

Constructor & Destructor Documentation

◆ Color() [1/4]

esphome::Color::Color ( )
inlineconstexpr

Definition at line 61 of file color.h.

◆ Color() [2/4]

esphome::Color::Color ( uint8_t red,
uint8_t green,
uint8_t blue )
inlineconstexpr

Definition at line 62 of file color.h.

◆ Color() [3/4]

esphome::Color::Color ( uint8_t red,
uint8_t green,
uint8_t blue,
uint8_t white )
inlineconstexpr

Definition at line 67 of file color.h.

◆ Color() [4/4]

esphome::Color::Color ( uint32_t colorcode)
inlineexplicitconstexpr

Definition at line 71 of file color.h.

Member Function Documentation

◆ blend_channel()

static uint8_t esphome::Color::blend_channel ( uint8_t from,
uint8_t to,
uint8_t amnt )
inlinestatic

One channel of gradient(): from at amnt 0 to to at amnt 255.

Inline so a per pixel loop can blend without a call; gradient() itself stays out of line so the light effects and fade_to_*() share one copy.

Definition at line 187 of file color.h.

◆ darken()

Color esphome::Color::darken ( uint8_t delta)
inline

Definition at line 195 of file color.h.

◆ fade_to_black()

Color esphome::Color::fade_to_black ( uint8_t amnt) const

Definition at line 16 of file color.cpp.

◆ fade_to_white()

Color esphome::Color::fade_to_white ( uint8_t amnt) const

Definition at line 14 of file color.cpp.

◆ gradient()

Color esphome::Color::gradient ( const Color & to_color,
uint8_t amnt ) const

Definition at line 9 of file color.cpp.

◆ is_on()

bool esphome::Color::is_on ( ) const
inline

Definition at line 76 of file color.h.

◆ lighten()

Color esphome::Color::lighten ( uint8_t delta)
inline

Definition at line 194 of file color.h.

◆ operator lv_color_t()

esphome::Color::operator lv_color_t ( ) const
inline

Definition at line 58 of file color.h.

◆ operator!=() [1/2]

bool esphome::Color::operator!= ( const Color & rhs) const
inline

Definition at line 84 of file color.h.

◆ operator!=() [2/2]

bool esphome::Color::operator!= ( uint32_t colorcode) const
inline

Definition at line 87 of file color.h.

◆ operator*() [1/2]

Color esphome::Color::operator* ( const Color & scale) const
inline

Definition at line 106 of file color.h.

◆ operator*() [2/2]

Color esphome::Color::operator* ( uint8_t scale) const
inline

Definition at line 92 of file color.h.

◆ operator*=() [1/2]

Color & esphome::Color::operator*= ( const Color & scale)
inline

Definition at line 110 of file color.h.

◆ operator*=() [2/2]

Color & esphome::Color::operator*= ( uint8_t scale)
inline

Definition at line 99 of file color.h.

◆ operator+() [1/2]

Color esphome::Color::operator+ ( const Color & add) const
inline

Definition at line 117 of file color.h.

◆ operator+() [2/2]

Color esphome::Color::operator+ ( uint8_t add) const
inline

Definition at line 142 of file color.h.

◆ operator+=() [1/2]

Color & esphome::Color::operator+= ( const Color & add)
inline

Definition at line 141 of file color.h.

◆ operator+=() [2/2]

Color & esphome::Color::operator+= ( uint8_t add)
inline

Definition at line 143 of file color.h.

◆ operator-() [1/2]

Color esphome::Color::operator- ( const Color & subtract) const
inline

Definition at line 144 of file color.h.

◆ operator-() [2/2]

Color esphome::Color::operator- ( uint8_t subtract) const
inline

Definition at line 169 of file color.h.

◆ operator-=() [1/2]

Color & esphome::Color::operator-= ( const Color & subtract)
inline

Definition at line 168 of file color.h.

◆ operator-=() [2/2]

Color & esphome::Color::operator-= ( uint8_t subtract)
inline

Definition at line 172 of file color.h.

◆ operator==() [1/2]

bool esphome::Color::operator== ( const Color & rhs) const
inline

Definition at line 78 of file color.h.

◆ operator==() [2/2]

bool esphome::Color::operator== ( uint32_t colorcode) const
inline

Definition at line 81 of file color.h.

◆ operator[]() [1/2]

const uint8_t & esphome::Color::operator[] ( uint8_t x) const
inline

Definition at line 91 of file color.h.

◆ operator[]() [2/2]

uint8_t & esphome::Color::operator[] ( uint8_t x)
inline

Definition at line 90 of file color.h.

◆ operator~()

Color esphome::Color::operator~ ( ) const
inline

Definition at line 96 of file color.h.

◆ random_color()

static Color esphome::Color::random_color ( )
inlinestatic

Definition at line 173 of file color.h.

Field Documentation

◆ [union]

union { ... } esphome::Color

◆ b

uint8_t esphome::Color::b

Definition at line 44 of file color.h.

◆ BLACK

const Color esphome::Color::BLACK
staticconstinit

Definition at line 197 of file color.h.

◆ blue

uint8_t esphome::Color::blue

Definition at line 45 of file color.h.

◆ g

uint8_t esphome::Color::g

Definition at line 40 of file color.h.

◆ green

uint8_t esphome::Color::green

Definition at line 41 of file color.h.

◆ r

uint8_t esphome::Color::r

Definition at line 36 of file color.h.

◆ raw

uint8_t esphome::Color::raw[4]

Definition at line 52 of file color.h.

◆ raw_32

uint32_t esphome::Color::raw_32

Definition at line 53 of file color.h.

◆ red

uint8_t esphome::Color::red

Definition at line 37 of file color.h.

◆ w

uint8_t esphome::Color::w

Definition at line 48 of file color.h.

◆ WHITE

const Color esphome::Color::WHITE
staticconstinit

Definition at line 198 of file color.h.

◆ white

uint8_t esphome::Color::white

Definition at line 49 of file color.h.


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