[display] Make COLOR_OFF and COLOR_ON inline constexpr

Convert COLOR_OFF and COLOR_ON from extern const to inline constexpr.
The Color class already has constexpr constructors so these can be
compile-time constants, allowing the compiler to optimize default
parameter values and eliminate the runtime storage.
This commit is contained in:
J. Nick Koston
2026-02-17 21:50:24 -06:00
parent a3d7e76992
commit 686ed76402
2 changed files with 3 additions and 4 deletions

View File

@@ -9,8 +9,7 @@ namespace esphome {
namespace display {
static const char *const TAG = "display";
const Color COLOR_OFF(0, 0, 0, 0);
const Color COLOR_ON(255, 255, 255, 255);
// COLOR_OFF and COLOR_ON are now inline constexpr in display.h
void Display::fill(Color color) { this->filled_rectangle(0, 0, this->get_width(), this->get_height(), color); }
void Display::clear() { this->fill(COLOR_OFF); }

View File

@@ -298,9 +298,9 @@ using display_writer_t = DisplayWriter<Display>;
}
/// Turn the pixel OFF.
extern const Color COLOR_OFF;
inline constexpr Color COLOR_OFF(0, 0, 0, 0);
/// Turn the pixel ON.
extern const Color COLOR_ON;
inline constexpr Color COLOR_ON(255, 255, 255, 255);
class BaseImage {
public: