Some more spaghetti won't kill anyone
I really need to fix some of this tho : (
This commit is contained in:
@@ -3,3 +3,7 @@ Library for curses like interfaces on embedded displays.
|
|||||||
|
|
||||||
Right now its only for my [CDashDisplay](https://github.com/ESilva15/CDashDisplay)
|
Right now its only for my [CDashDisplay](https://github.com/ESilva15/CDashDisplay)
|
||||||
project, so it probably doesn't work that good on other projects.
|
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.
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "UIBar.h"
|
#include "UIBar.h"
|
||||||
#include "UIComponent.h"
|
#include "UIComponent.h"
|
||||||
#include "UIDrawing.h"
|
#include "UIDrawing.h"
|
||||||
|
#include <cstdint>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
UIBar::UIBar() {
|
UIBar::UIBar() {
|
||||||
@@ -13,6 +14,25 @@ UIBar::UIBar(Arduino_GFX *d, UIDimensions dims, UIDecorations decor,
|
|||||||
this->type = BAR;
|
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) {
|
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) {
|
||||||
@@ -101,6 +121,7 @@ void UIBar::drawBox() {
|
|||||||
this->display->setTextColor(RED);
|
this->display->setTextColor(RED);
|
||||||
this->display->drawFastVLine(x, this->dims.y + this->dims.height, 7, 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];
|
char legend[5];
|
||||||
sprintf(legend, "%d", k);
|
sprintf(legend, "%d", k);
|
||||||
this->display->setCursor(x - (CHR_WIDTH(this->decor.textSize) / 2),
|
this->display->setCursor(x - (CHR_WIDTH(this->decor.textSize) / 2),
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ struct UIBar : UIElement {
|
|||||||
uint8_t range = 0; // define the tach range, ie: 8 for 8000rpm
|
uint8_t range = 0; // define the tach range, ie: 8 for 8000rpm
|
||||||
|
|
||||||
UIBar();
|
UIBar();
|
||||||
|
~UIBar() override;
|
||||||
UIBar(Arduino_GFX *d, UIDimensions dims, UIDecorations decor, char *title);
|
UIBar(Arduino_GFX *d, UIDimensions dims, UIDecorations decor, char *title);
|
||||||
|
|
||||||
void Update(const char *val, bool forceRedraw) override;
|
void Update(const char *val, bool forceRedraw) override;
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ UIElement::UIElement(Arduino_GFX *d, UIDimensions dims, UIDecorations decor,
|
|||||||
|
|
||||||
UIElement::~UIElement() {
|
UIElement::~UIElement() {
|
||||||
// Destruction involves redrawing over the "old" area
|
// Destruction involves redrawing over the "old" area
|
||||||
|
|
||||||
fillRect(this->dims.x, this->dims.y, this->dims.width, this->dims.height,
|
fillRect(this->dims.x, this->dims.y, this->dims.width, this->dims.height,
|
||||||
this->decor.bgColor, this->display);
|
this->decor.bgColor, this->display);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -25,7 +25,7 @@ public:
|
|||||||
UIElement();
|
UIElement();
|
||||||
UIElement(Arduino_GFX *d, UIDimensions dims, UIDecorations decor,
|
UIElement(Arduino_GFX *d, UIDimensions dims, UIDecorations decor,
|
||||||
char *Title);
|
char *Title);
|
||||||
~UIElement();
|
virtual ~UIElement();
|
||||||
|
|
||||||
// Children
|
// Children
|
||||||
int16_t children[MAX_CHILDREN];
|
int16_t children[MAX_CHILDREN];
|
||||||
|
|||||||
@@ -56,8 +56,10 @@ namespace WindowPool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Deallocate(int16_t id) {
|
void Deallocate(int16_t id) {
|
||||||
|
// NOTE: I don't think we need this since it calls the destructor...
|
||||||
switch(pool[id].type) {
|
switch(pool[id].type) {
|
||||||
case BAR:
|
case BAR:
|
||||||
|
delete pool[id].str;
|
||||||
break;
|
break;
|
||||||
case STRING:
|
case STRING:
|
||||||
delete pool[id].str;
|
delete pool[id].str;
|
||||||
|
|||||||
Reference in New Issue
Block a user