From 1d9e6736a29c12263a5ca380db412d3298e80764 Mon Sep 17 00:00:00 2001 From: ainyan03 <205502311+ainyan03@users.noreply.github.com> Date: Thu, 15 Oct 2026 11:16:56 +0000 Subject: [PATCH] Accept struct color types in setBaseColor and setTextColor With a palette, these functions stored the given value as is, which needed an implicit conversion to uint32_t. The struct color types (rgb565_t, rgb888_t, ...) only convert explicitly, so passing one failed to compile even when drawing to a display without a palette. The value is now cast explicitly: with a palette it is used as the palette index, as setColor() already does; without one it is converted to RGB888 as before. --- src/lgfx/v1/LGFXBase.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lgfx/v1/LGFXBase.hpp b/src/lgfx/v1/LGFXBase.hpp index 8d38b085..2548a206 100644 --- a/src/lgfx/v1/LGFXBase.hpp +++ b/src/lgfx/v1/LGFXBase.hpp @@ -131,7 +131,7 @@ namespace lgfx LGFX_INLINE_T void setColor(T color) { setRawColor(_write_conv.convert(color)); } LGFX_INLINE void setRawColor(uint32_t c) { *((uint32_t*)&_color) = c; } LGFX_INLINE uint32_t getRawColor(void) const { return *((uint32_t*)&_color); } - LGFX_INLINE_T void setBaseColor(T c) { _base_rgb888 = hasPalette() ? c : convert_to_rgb888(c); } + LGFX_INLINE_T void setBaseColor(T c) { _base_rgb888 = hasPalette() ? static_cast(c) : convert_to_rgb888(c); } LGFX_INLINE uint32_t getBaseColor(void) const { return _base_rgb888; } LGFX_INLINE color_conv_t* getColorConverter(void) { return &_write_conv; } LGFX_INLINE color_depth_t getColorDepth(void) const { return _write_conv.depth; } @@ -690,7 +690,7 @@ namespace lgfx template void setTextColor(T color) { - _text_style.fore_rgb888 = _text_style.back_rgb888 = this->hasPalette() ? color : convert_to_rgb888(color); + _text_style.fore_rgb888 = _text_style.back_rgb888 = this->hasPalette() ? static_cast(color) : convert_to_rgb888(color); } template void setTextColor(T1 fgcolor, T2 bgcolor) { @@ -698,8 +698,8 @@ namespace lgfx _text_style.fore_rgb888 = convert_to_rgb888(fgcolor); _text_style.back_rgb888 = convert_to_rgb888(bgcolor); } else { - _text_style.fore_rgb888 = fgcolor; - _text_style.back_rgb888 = bgcolor; + _text_style.fore_rgb888 = static_cast(fgcolor); + _text_style.back_rgb888 = static_cast(bgcolor); } }