Add custom background

This commit is contained in:
Florian Wetzel
2025-02-07 16:46:24 +01:00
parent 1f80ca10f9
commit 13dd0481fb
2 changed files with 6 additions and 4 deletions

View File

@ -8,8 +8,8 @@
#include "tftcolors.h" #include "tftcolors.h"
namespace espgui { namespace espgui {
ProgressBar::ProgressBar(int x, int y, int width, int height, int min, int max, uint32_t color) : ProgressBar::ProgressBar(int x, int y, int width, int height, int min, int max, uint32_t color, uint32_t backgroundColor) :
m_x{x}, m_y{y}, m_width{width}, m_height{height}, m_min{min}, m_max{max}, m_color{color} m_x{x}, m_y{y}, m_width{width}, m_height{height}, m_min{min}, m_max{max}, m_color{color}, m_backgroundColor{backgroundColor}
{ {
} }
@ -17,6 +17,7 @@ void ProgressBar::start(TftInterface &tft)
{ {
m_lastValue = m_x+1; m_lastValue = m_x+1;
tft.drawRect(m_x, m_y, m_width, m_height, TFT_WHITE); tft.drawRect(m_x, m_y, m_width, m_height, TFT_WHITE);
tft.fillRect(m_x+1, m_y+1, m_width-2, m_height-2, m_backgroundColor);
} }
void ProgressBar::redraw(TftInterface &tft, int value) void ProgressBar::redraw(TftInterface &tft, int value)
@ -24,7 +25,7 @@ void ProgressBar::redraw(TftInterface &tft, int value)
value = cpputils::mapValueClamped(value, m_min, m_max, m_x+1, m_x+m_width-1); value = cpputils::mapValueClamped(value, m_min, m_max, m_x+1, m_x+m_width-1);
if (value < m_lastValue) if (value < m_lastValue)
tft.fillRect(value, m_y+1, m_lastValue-value, m_height-2, TFT_BLACK); tft.fillRect(value, m_y+1, m_lastValue-value, m_height-2, m_backgroundColor);
else if (value > m_lastValue) else if (value > m_lastValue)
tft.fillRect(m_lastValue, m_y+1, value-m_lastValue, m_height-2, m_color); tft.fillRect(m_lastValue, m_y+1, value-m_lastValue, m_height-2, m_color);

View File

@ -16,7 +16,7 @@ namespace espgui {
class ProgressBar class ProgressBar
{ {
public: public:
ProgressBar(int x, int y, int width, int height, int min, int max, uint32_t color = TFT_YELLOW); ProgressBar(int x, int y, int width, int height, int min, int max, uint32_t color = TFT_YELLOW, uint32_t backgroundColor = TFT_BLACK);
void start(TftInterface &tft); void start(TftInterface &tft);
void redraw(TftInterface &tft, int value); void redraw(TftInterface &tft, int value);
@ -29,6 +29,7 @@ private:
const int m_min; const int m_min;
const int m_max; const int m_max;
const uint32_t m_color; const uint32_t m_color;
const uint32_t m_backgroundColor;
int m_lastValue{}; int m_lastValue{};
}; };