diff --git a/src/widgets/progressbar.cpp b/src/widgets/progressbar.cpp index d2fca4f..bdb8ee6 100644 --- a/src/widgets/progressbar.cpp +++ b/src/widgets/progressbar.cpp @@ -31,4 +31,22 @@ void ProgressBar::redraw(TftInterface &tft, int value) m_lastValue = value; } + +void ProgressBar::changeColor(TftInterface &tft, const uint32_t color, const uint32_t backgroundColor) +{ + if (color != m_color) + { + // redraw already drawn area in new color + tft.fillRect(m_x+1, m_y+1, m_lastValue-m_x-1, m_height-2, color); + m_color = color; + } + + if (backgroundColor != m_backgroundColor) + { + // redraw background in new color + tft.fillRect(m_x+1, m_y+1, m_width-2, m_height-2, backgroundColor); + m_backgroundColor = backgroundColor; + } +} + } // namespace espgui diff --git a/src/widgets/progressbar.h b/src/widgets/progressbar.h index 009046e..aa02960 100644 --- a/src/widgets/progressbar.h +++ b/src/widgets/progressbar.h @@ -21,6 +21,8 @@ public: void start(TftInterface &tft); void redraw(TftInterface &tft, int value); + void changeColor(TftInterface &tft, const uint32_t color = TFT_YELLOW, const uint32_t backgroundColor = TFT_BLACK); + private: const int m_x; const int m_y; @@ -28,8 +30,8 @@ private: const int m_height; const int m_min; const int m_max; - const uint32_t m_color; - const uint32_t m_backgroundColor; + uint32_t m_color; + uint32_t m_backgroundColor; int m_lastValue{}; };