[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)
{
if (windowFlags & BUTTON_BACKGROUND) {
dc->drawSolidFilledRect(0, 0, rect.w, rect.h, DISABLE_COLOR);
if (bgColor) {
dc->drawSolidFilledRect(0, 0, rect.w, rect.h, bgColor);
}
coord_t x;
+12 -2
View File
@@ -29,6 +29,9 @@ class StaticText: public Window {
Window(parent, rect, windowFlags, textFlags),
text(std::move(text))
{
if (windowFlags & BUTTON_BACKGROUND) {
setBackgroundColor(DISABLE_COLOR);
}
}
#if defined(DEBUG_WINDOWS)
@@ -46,8 +49,14 @@ class StaticText: public Window {
invalidate();
}
void setBackgroundColor(LcdFlags color)
{
bgColor = color;
}
protected:
std::string text;
LcdFlags bgColor = 0;
};
class Subtitle: public StaticText {
@@ -124,14 +133,15 @@ class StaticBitmap: public Window {
class DynamicText: public StaticText
{
public:
DynamicText(Window * parent, const rect_t & rect, std::function<std::string()> textHandler):
StaticText(parent, rect),
DynamicText(Window * parent, const rect_t & rect, std::function<std::string()> textHandler, LcdFlags textFlags = 0):
StaticText(parent, rect, "", 0, textFlags),
textHandler(std::move(textHandler))
{
}
void checkEvents() override
{
StaticText::checkEvents();
std::string newText = textHandler();
if (newText != text) {
text = newText;