Avoid a invalidate when not needed

This commit is contained in:
Bertrand Songis
2021-03-10 10:43:36 +01:00
parent 8a196f5982
commit f0d963386f
2 changed files with 13 additions and 8 deletions
+6 -4
View File
@@ -21,7 +21,8 @@
#include "window.h" #include "window.h"
class Progress : public Window { class Progress: public Window
{
public: public:
Progress(Window * parent, const rect_t & rect): Progress(Window * parent, const rect_t & rect):
Window(parent, rect) Window(parent, rect)
@@ -35,15 +36,16 @@ class Progress : public Window {
} }
#endif #endif
void setValue(int value) void setValue(int newValue)
{ {
this->value = value; if (newValue != value) {
value = newValue;
invalidate(); invalidate();
} }
}
void paint(BitmapBuffer * dc) override; void paint(BitmapBuffer * dc) override;
protected: protected:
int value = 0; int value = 0;
}; };
+4 -1
View File
@@ -45,9 +45,11 @@ class StaticText: public Window
void setText(std::string value) void setText(std::string value)
{ {
if (text != value) {
text = std::move(value); text = std::move(value);
invalidate(); invalidate();
} }
}
void setBackgroundColor(LcdFlags color) void setBackgroundColor(LcdFlags color)
{ {
@@ -59,7 +61,8 @@ class StaticText: public Window
LcdFlags bgColor = 0; LcdFlags bgColor = 0;
}; };
class Subtitle: public StaticText { class Subtitle: public StaticText
{
public: public:
Subtitle(Window * parent, const rect_t & rect, const char * text): Subtitle(Window * parent, const rect_t & rect, const char * text):
StaticText(parent, rect, text, 0, FONT(BOLD)) StaticText(parent, rect, text, 0, FONT(BOLD))