From 0ec1e34a96dc50f68369da92d7bf6de3b77f2999 Mon Sep 17 00:00:00 2001 From: Eduardo Silva Date: Tue, 9 Jun 2026 16:36:05 +0100 Subject: [PATCH] Some more spaghetti won't kill anyone I really need to fix some of this tho : ( --- README.md | 4 ++++ src/UIBar.cpp | 21 +++++++++++++++++++++ src/UIBar.h | 1 + src/UIComponent.cpp | 1 - src/UIComponent.h | 2 +- src/windowPool.cpp | 2 ++ 6 files changed, 29 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a0856a7..e2b752e 100644 --- a/README.md +++ b/README.md @@ -3,3 +3,7 @@ Library for curses like interfaces on embedded displays. Right now its only for my [CDashDisplay](https://github.com/ESilva15/CDashDisplay) project, so it probably doesn't work that good on other projects. + +# TO-DO +- Start suing `Arduino_Canvas` for drawable elements. I think it uses double buffering¿ +Need to explore that. diff --git a/src/UIBar.cpp b/src/UIBar.cpp index 20b974b..5f07afa 100644 --- a/src/UIBar.cpp +++ b/src/UIBar.cpp @@ -1,6 +1,7 @@ #include "UIBar.h" #include "UIComponent.h" #include "UIDrawing.h" +#include #include UIBar::UIBar() { @@ -13,6 +14,25 @@ UIBar::UIBar(Arduino_GFX *d, UIDimensions dims, UIDecorations decor, this->type = BAR; } +UIBar::~UIBar() { + // height taking the rule into account + // NOTE: need to clean this all up the 7s and 2 and whatever + int16_t charWidth = CHR_WIDTH(this->decor.textSize); + int16_t textHeight = 8 * this->decor.textSize; + int16_t totalHeight = this->dims.height + 7 + 2 + textHeight; + int16_t totalX = this->dims.x - (charWidth / 2); + int16_t totalWidth = this->dims.width + charWidth; + + + this->display->fillRect( + totalX, + this->dims.y, + totalWidth, + totalHeight, + this->decor.bgColor + ); +} + void UIBar::Update(const char *v, bool forceRedraw) { unsigned long time = millis(); if ((time - this->lastUpdate) <= this->refreshRate) { @@ -101,6 +121,7 @@ void UIBar::drawBox() { this->display->setTextColor(RED); this->display->drawFastVLine(x, this->dims.y + this->dims.height, 7, RED); + // NOTE: this may fill here due to insuficcient memory? char legend[5]; sprintf(legend, "%d", k); this->display->setCursor(x - (CHR_WIDTH(this->decor.textSize) / 2), diff --git a/src/UIBar.h b/src/UIBar.h index 31a8b0b..b8fc9b9 100644 --- a/src/UIBar.h +++ b/src/UIBar.h @@ -11,6 +11,7 @@ struct UIBar : UIElement { uint8_t range = 0; // define the tach range, ie: 8 for 8000rpm UIBar(); + ~UIBar() override; UIBar(Arduino_GFX *d, UIDimensions dims, UIDecorations decor, char *title); void Update(const char *val, bool forceRedraw) override; diff --git a/src/UIComponent.cpp b/src/UIComponent.cpp index 4375bba..e0888ee 100644 --- a/src/UIComponent.cpp +++ b/src/UIComponent.cpp @@ -24,7 +24,6 @@ UIElement::UIElement(Arduino_GFX *d, UIDimensions dims, UIDecorations decor, UIElement::~UIElement() { // Destruction involves redrawing over the "old" area - fillRect(this->dims.x, this->dims.y, this->dims.width, this->dims.height, this->decor.bgColor, this->display); } diff --git a/src/UIComponent.h b/src/UIComponent.h index 0f7a9ad..289f3be 100644 --- a/src/UIComponent.h +++ b/src/UIComponent.h @@ -25,7 +25,7 @@ public: UIElement(); UIElement(Arduino_GFX *d, UIDimensions dims, UIDecorations decor, char *Title); - ~UIElement(); + virtual ~UIElement(); // Children int16_t children[MAX_CHILDREN]; diff --git a/src/windowPool.cpp b/src/windowPool.cpp index 3b878d8..6828adf 100644 --- a/src/windowPool.cpp +++ b/src/windowPool.cpp @@ -56,8 +56,10 @@ namespace WindowPool { } void Deallocate(int16_t id) { + // NOTE: I don't think we need this since it calls the destructor... switch(pool[id].type) { case BAR: + delete pool[id].str; break; case STRING: delete pool[id].str;