From 339c26c815f58e8702981b09fe471e2edded44b8 Mon Sep 17 00:00:00 2001 From: Clyde Stubbs <2366188+clydebarrow@users.noreply.github.com> Date: Mon, 4 Aug 2025 10:51:34 +1000 Subject: [PATCH] [color][lvgl] Allow Color to be used for lv_color_t (#10016) --- esphome/core/color.h | 10 ++++++++++ tests/components/lvgl/lvgl-package.yaml | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/esphome/core/color.h b/esphome/core/color.h index 2b307bb438..5dce58a485 100644 --- a/esphome/core/color.h +++ b/esphome/core/color.h @@ -1,8 +1,13 @@ #pragma once +#include "defines.h" #include "component.h" #include "helpers.h" +#ifdef USE_LVGL +#include "esphome/components/lvgl/lvgl_proxy.h" +#endif // USE_LVGL + namespace esphome { inline static constexpr uint8_t esp_scale8(uint8_t i, uint8_t scale) { @@ -33,6 +38,11 @@ struct Color { uint32_t raw_32; }; +#ifdef USE_LVGL + // convenience function for Color to get a lv_color_t representation + operator lv_color_t() const { return lv_color_make(this->r, this->g, this->b); } +#endif + inline constexpr Color() ESPHOME_ALWAYS_INLINE : raw_32(0) {} // NOLINT inline constexpr Color(uint8_t red, uint8_t green, uint8_t blue) ESPHOME_ALWAYS_INLINE : r(red), g(green), diff --git a/tests/components/lvgl/lvgl-package.yaml b/tests/components/lvgl/lvgl-package.yaml index 853466c9cc..7cd2e2b93e 100644 --- a/tests/components/lvgl/lvgl-package.yaml +++ b/tests/components/lvgl/lvgl-package.yaml @@ -78,7 +78,7 @@ lvgl: - id: date_style text_font: roboto10 align: center - text_color: color_id2 + text_color: !lambda return color_id2; bg_opa: cover radius: 4 pad_all: 2