Some more spaghetti won't kill anyone

I really need to fix some of this tho : (
This commit is contained in:
2026-06-09 16:36:05 +01:00
parent f49d3cd3e1
commit 0ec1e34a96
6 changed files with 29 additions and 2 deletions
+4
View File
@@ -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.
+21
View File
@@ -1,6 +1,7 @@
#include "UIBar.h"
#include "UIComponent.h"
#include "UIDrawing.h"
#include <cstdint>
#include <stdio.h>
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),
+1
View File
@@ -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;
-1
View File
@@ -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);
}
+1 -1
View File
@@ -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];
+2
View File
@@ -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;