[StaticText] Possibility to have a background color

This commit is contained in:
Bertrand Songis
2020-10-09 19:12:21 +02:00
parent 8d27a510a4
commit c8a798a66c
2 changed files with 14 additions and 4 deletions
+2 -2
View File
@@ -22,8 +22,8 @@
void StaticText::paint(BitmapBuffer * dc) void StaticText::paint(BitmapBuffer * dc)
{ {
if (windowFlags & BUTTON_BACKGROUND) { if (bgColor) {
dc->drawSolidFilledRect(0, 0, rect.w, rect.h, DISABLE_COLOR); dc->drawSolidFilledRect(0, 0, rect.w, rect.h, bgColor);
} }
coord_t x; coord_t x;
+12 -2
View File
@@ -29,6 +29,9 @@ class StaticText: public Window {
Window(parent, rect, windowFlags, textFlags), Window(parent, rect, windowFlags, textFlags),
text(std::move(text)) text(std::move(text))
{ {
if (windowFlags & BUTTON_BACKGROUND) {
setBackgroundColor(DISABLE_COLOR);
}
} }
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
@@ -46,8 +49,14 @@ class StaticText: public Window {
invalidate(); invalidate();
} }
void setBackgroundColor(LcdFlags color)
{
bgColor = color;
}
protected: protected:
std::string text; std::string text;
LcdFlags bgColor = 0;
}; };
class Subtitle: public StaticText { class Subtitle: public StaticText {
@@ -124,14 +133,15 @@ class StaticBitmap: public Window {
class DynamicText: public StaticText class DynamicText: public StaticText
{ {
public: public:
DynamicText(Window * parent, const rect_t & rect, std::function<std::string()> textHandler): DynamicText(Window * parent, const rect_t & rect, std::function<std::string()> textHandler, LcdFlags textFlags = 0):
StaticText(parent, rect), StaticText(parent, rect, "", 0, textFlags),
textHandler(std::move(textHandler)) textHandler(std::move(textHandler))
{ {
} }
void checkEvents() override void checkEvents() override
{ {
StaticText::checkEvents();
std::string newText = textHandler(); std::string newText = textHandler();
if (newText != text) { if (newText != text) {
text = newText; text = newText;