using polymorphism now but still have to decide on a better pattern
This commit is contained in:
+4
-2
@@ -7,7 +7,7 @@ UIBar::UIBar(Arduino_GFX *d, UIDimensions dims, UIDecorations decor,
|
|||||||
char *title)
|
char *title)
|
||||||
: UIElement(d, dims, decor, title) {}
|
: UIElement(d, dims, decor, title) {}
|
||||||
|
|
||||||
void UIBar::Update(char *v) {
|
void UIBar::Update(const char *v, bool forceRedraw) {
|
||||||
unsigned long time = millis();
|
unsigned long time = millis();
|
||||||
if ((time - this->lastUpdate) <= this->refreshRate) {
|
if ((time - this->lastUpdate) <= this->refreshRate) {
|
||||||
return;
|
return;
|
||||||
@@ -16,7 +16,7 @@ void UIBar::Update(char *v) {
|
|||||||
// Conver the string to an integer
|
// Conver the string to an integer
|
||||||
uint32_t newVal = atoi(v);
|
uint32_t newVal = atoi(v);
|
||||||
|
|
||||||
if (this->value == newVal) {
|
if ((this->value == newVal) && !forceRedraw) {
|
||||||
// If the value hasn't changed we do not need to re-render
|
// If the value hasn't changed we do not need to re-render
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -104,3 +104,5 @@ void UIBar::Box() {
|
|||||||
this->display->print(legend);
|
this->display->print(legend);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UIBar::Redraw() {}
|
||||||
|
|||||||
+2
-1
@@ -12,7 +12,8 @@ struct UIBar : UIElement {
|
|||||||
UIBar();
|
UIBar();
|
||||||
UIBar(Arduino_GFX *d, UIDimensions dims, UIDecorations decor, char *title);
|
UIBar(Arduino_GFX *d, UIDimensions dims, UIDecorations decor, char *title);
|
||||||
|
|
||||||
void Update(char *val);
|
void Update(const char *val, bool forceRedraw) override;
|
||||||
|
void Redraw() override;
|
||||||
void DrawBar(uint32_t *oldValue, uint32_t *newValue);
|
void DrawBar(uint32_t *oldValue, uint32_t *newValue);
|
||||||
void renderBlank();
|
void renderBlank();
|
||||||
void Box();
|
void Box();
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
#include "UIBase.h"
|
||||||
|
#include "HardwareSerial.h"
|
||||||
|
#include "UIComponent.h"
|
||||||
|
#include <Arduino_GFX.h>
|
||||||
|
|
||||||
|
UIBase::UIBase() : UIElement(nullptr, {0, 0, 0, 0}, UIDecorations(), (char *)"") {
|
||||||
|
this->type = STRING;
|
||||||
|
memset(this->value, 0, this->bufferSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
UIBase::UIBase(Arduino_GFX *d, UIDimensions dims, UIDecorations decor,
|
||||||
|
char *title)
|
||||||
|
: UIElement(d, dims, decor, title) {
|
||||||
|
this->type = BASE;
|
||||||
|
memset(this->value, 0, this->bufferSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UIBase::Update(const char* data, bool forceRedraw) {}
|
||||||
|
void UIBase::Redraw() {}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
#ifndef __UI_BASE__
|
||||||
|
#define __UI_BASE__
|
||||||
|
|
||||||
|
#include "UIComponent.h"
|
||||||
|
|
||||||
|
// Representation of single line strings
|
||||||
|
struct UIBase : UIElement {
|
||||||
|
static const std::size_t bufferSize = 64;
|
||||||
|
char value[bufferSize];
|
||||||
|
|
||||||
|
UIBase();
|
||||||
|
UIBase(Arduino_GFX *d, UIDimensions dims, UIDecorations decor, char *title);
|
||||||
|
void Update(const char *value, bool forceRedraw) override;
|
||||||
|
void Redraw() override;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -63,6 +63,10 @@ public:
|
|||||||
void drawBox();
|
void drawBox();
|
||||||
void noBox();
|
void noBox();
|
||||||
void replaceString(char *oldVal, char *newVal);
|
void replaceString(char *oldVal, char *newVal);
|
||||||
|
|
||||||
|
// Viewing - more like actual rendering data
|
||||||
|
virtual void Update(const char *data, bool forceRedraw) = 0;
|
||||||
|
virtual void Redraw() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+6
-2
@@ -15,7 +15,7 @@ UIString::UIString(Arduino_GFX *d, UIDimensions dims, UIDecorations decor,
|
|||||||
memset(this->value, 0, this->bufferSize);
|
memset(this->value, 0, this->bufferSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIString::Update(const char *v) {
|
void UIString::Update(const char *v, bool forceRedraw) {
|
||||||
uint64_t time = millis();
|
uint64_t time = millis();
|
||||||
if ((time - this->lastUpdate) <= this->refreshRate) {
|
if ((time - this->lastUpdate) <= this->refreshRate) {
|
||||||
return;
|
return;
|
||||||
@@ -28,7 +28,7 @@ void UIString::Update(const char *v) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If the value hasn't changed we do not need to re-render
|
// If the value hasn't changed we do not need to re-render
|
||||||
if (strcmp(this->value, v) == 0) {
|
if ((strcmp(this->value, v) == 0) && !forceRedraw) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,3 +46,7 @@ void UIString::Update(const char *v) {
|
|||||||
replaceString(oldVal, newVal);
|
replaceString(oldVal, newVal);
|
||||||
strncpy(this->value, v, this->bufferSize);
|
strncpy(this->value, v, this->bufferSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UIString::Redraw() {
|
||||||
|
this->Update(this->value, true);
|
||||||
|
}
|
||||||
|
|||||||
+2
-1
@@ -11,7 +11,8 @@ struct UIString : UIElement {
|
|||||||
UIString();
|
UIString();
|
||||||
UIString(Arduino_GFX *d, UIDimensions dims, UIDecorations decor,
|
UIString(Arduino_GFX *d, UIDimensions dims, UIDecorations decor,
|
||||||
char *title);
|
char *title);
|
||||||
void Update(const char *value);
|
void Update(const char *value, bool forceRedraw) override;
|
||||||
|
void Redraw() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+4
-1
@@ -76,8 +76,11 @@ void UITable::setup() {
|
|||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
this->tableData[r * COLUMNS + c]->drawBox();
|
this->tableData[r * COLUMNS + c]->drawBox();
|
||||||
this->tableData[r * COLUMNS + c]->Update("---");
|
this->tableData[r * COLUMNS + c]->Update("---", false);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UITable::Update(const char* data, bool forceRedraw) {}
|
||||||
|
void UITable::Redraw() {}
|
||||||
|
|||||||
@@ -27,6 +27,10 @@ struct UITable : UIElement {
|
|||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
uint16_t getContentAreaHeight();
|
uint16_t getContentAreaHeight();
|
||||||
|
|
||||||
|
// Rendering
|
||||||
|
void Update(const char* data, bool forceRedraw) override;
|
||||||
|
void Redraw() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+2
-1
@@ -2,6 +2,7 @@
|
|||||||
#include "UIComponent.h"
|
#include "UIComponent.h"
|
||||||
#include "UIBar.h"
|
#include "UIBar.h"
|
||||||
#include "UIString.h"
|
#include "UIString.h"
|
||||||
|
#include "UIBase.h"
|
||||||
#include "UITable.h"
|
#include "UITable.h"
|
||||||
#include "values.h"
|
#include "values.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
@@ -43,7 +44,7 @@ namespace WindowPool {
|
|||||||
pool[nextIndex].table = new UITable();
|
pool[nextIndex].table = new UITable();
|
||||||
break;
|
break;
|
||||||
case BASE:
|
case BASE:
|
||||||
pool[nextIndex].base = new UIElement();
|
pool[nextIndex].base = new UIBase();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-1
@@ -9,12 +9,14 @@ struct UIElement;
|
|||||||
struct UIString;
|
struct UIString;
|
||||||
struct UIBar;
|
struct UIBar;
|
||||||
struct UITable;
|
struct UITable;
|
||||||
|
struct UIBase;
|
||||||
|
|
||||||
namespace WindowPool {
|
namespace WindowPool {
|
||||||
struct WindowEntry {
|
struct WindowEntry {
|
||||||
ComponentType type;
|
ComponentType type;
|
||||||
|
// Well I did this like this but I recon we can use polymorphism instead
|
||||||
union {
|
union {
|
||||||
UIElement* base;
|
UIBase* base;
|
||||||
UIString* str;
|
UIString* str;
|
||||||
UIBar* bar;
|
UIBar* bar;
|
||||||
UITable* table;
|
UITable* table;
|
||||||
|
|||||||
Reference in New Issue
Block a user