I will clean this mess but for now yay for the relative

This commit is contained in:
2025-04-10 23:27:22 +01:00
parent a44019a9a6
commit 4c57028874
9 changed files with 240 additions and 81 deletions
+3 -10
View File
@@ -25,15 +25,6 @@ int16_t UIElement::getContentAreaX0() {
int16_t UIElement::getContentAreaY0() {
if (this->decor->hasBorder) {
Serial2.print("Value to return: ");
Serial2.print(this->dims.y);
Serial2.print(" + ");
Serial2.print(this->getTitleAreaHeight());
Serial2.print(" + ");
Serial2.print(DEFAULT_TITLE_CONTENT_SPACING);
Serial2.print(" = ");
Serial2.println(this->dims.y + this->getTitleAreaHeight() +
DEFAULT_TITLE_CONTENT_SPACING);
return this->dims.y + this->getTitleAreaHeight() +
DEFAULT_TITLE_CONTENT_SPACING;
}
@@ -80,8 +71,10 @@ void UIElement::replaceString(char *oldVal, char *newVal) {
size_t newValLen = strlen(newVal);
size_t oldValLen = strlen(oldVal);
// It crashs somewhere around here
int16_t x0 = this->getContentAreaX0();
int16_t y0 = this->getContentAreaY0();
int16_t y0 = this->getContentAreaY0(); // <- Crashes here
// Before here
this->display->setTextSize(this->decor->textSize);
+9 -2
View File
@@ -1,15 +1,18 @@
#include "UIString.h"
#include "HardwareSerial.h"
#include "UIComponent.h"
#include <Arduino_GFX.h>
UIString::UIString() : UIElement(nullptr, {0, 0, 0, 0}, nullptr, (char *)"") {
this->type = STRING;
memset(this->value, 0, this->bufferSize);
}
UIString::UIString(Arduino_GFX *d, UIDimensions dims, UIDecorations *decor,
char *title)
: UIElement(d, dims, decor, title) {
this->type = STRING;
memset(this->value, 0, this->bufferSize);
}
void UIString::Update(const char *v) {
@@ -30,13 +33,17 @@ void UIString::Update(const char *v) {
}
char newVal[this->bufferSize];
memset(newVal, 0, this->bufferSize);
// strncpy(newVal, v, this->bufferSize - 1);
sprintf(newVal, "%s", v);
char oldVal[this->bufferSize];
memset(oldVal, 0, this->bufferSize);
// strncpy(oldVal, v, this->bufferSize - 1);
sprintf(oldVal, "%s", this->value);
// Figure out the x0 and y0 for the text
replaceString(oldVal, newVal);
replaceString(oldVal, newVal); // <- It crashes here somewhere
//
strncpy(this->value, v, this->bufferSize);
}
+1 -1
View File
@@ -5,7 +5,7 @@
// Representation of single line strings
struct UIString : UIElement {
static const size_t bufferSize = 256;
static const size_t bufferSize = 64;
char value[bufferSize];
UIString();
+21 -20
View File
@@ -10,19 +10,18 @@ UITable::UITable(Arduino_GFX *gfx, UIDimensions dims, UIDecorations *decor,
char *title)
: UIElement(gfx, dims, decor, title) {
this->type = TABLE;
this->tableData = new UIString*[ROWS * COLUMNS];
// Default decoration for every cell
UIDecorations *cellDecor = new UIDecorations();
cellDecor->textSize = 2;
this->decor->textSize = 2;
for (int k = 0; k < ROWS * COLUMNS; k++) {
this->tableData[k].decor = cellDecor;
this->tableData[k].dims.x = 0;
this->tableData[k].dims.y = 0;
this->tableData[k].dims.width = 0;
this->tableData[k].dims.height = 0;
this->tableData[k].display = this->display;
UIDecorations *cellDecor = new UIDecorations();
cellDecor->textSize = this->decor->textSize;
UIDimensions dims = {0, 0, 0, 0};
this->tableData[k] = new UIString(display, dims, cellDecor, (char *)"");
}
int cellH = CHR_HEIGHT(this->decor->textSize) + CELL_MARGIN;
@@ -32,7 +31,7 @@ UITable::UITable(Arduino_GFX *gfx, UIDimensions dims, UIDecorations *decor,
DEFAULT_MARGIN + DEFAULT_BORDER_THICKNESS;
this->dims.width =
(DEFAULT_BORDER_THICKNESS + DEFAULT_MARGIN) * 2 +
(CHR_WIDTH(this->decor->textSize) + CELL_MARGIN) * (3 + 24 + 5);
(CHR_WIDTH(this->decor->textSize) + CELL_MARGIN) * (3 + 18 + 12);
}
uint16_t UITable::getContentAreaHeight() {
@@ -48,8 +47,8 @@ uint16_t UITable::getContentAreaHeight() {
void UITable::setup() {
// Define the cell dimensions
int tableCellW[] = {3 * (CHR_WIDTH(this->decor->textSize) + CELL_MARGIN),
24 * (CHR_WIDTH(this->decor->textSize) + CELL_MARGIN),
5 * (CHR_WIDTH(this->decor->textSize) + CELL_MARGIN)};
18 * (CHR_WIDTH(this->decor->textSize) + CELL_MARGIN),
12 * (CHR_WIDTH(this->decor->textSize) + CELL_MARGIN)};
int cellH = CHR_HEIGHT(this->decor->textSize) + CELL_MARGIN;
// Initialize the cells
@@ -57,18 +56,20 @@ void UITable::setup() {
for (int r = 0; r < ROWS; r++) {
int16_t xOffset = this->getContentAreaX0();
for (int c = 0; c < COLUMNS; c++) {
this->tableData[r * COLUMNS + c].decor->textSize = this->decor->textSize;
this->tableData[r * COLUMNS + c].decor->hasBorder = false;
this->tableData[r * COLUMNS + c].dims.x = xOffset + CELL_MARGIN;
this->tableData[r * COLUMNS + c].dims.y = (cellH * r) + yOffset;
this->tableData[r * COLUMNS + c].dims.height = cellH;
this->tableData[r * COLUMNS + c].dims.width = tableCellW[c];
this->tableData[r * COLUMNS + c]->decor->textSize = this->decor->textSize;
this->tableData[r * COLUMNS + c]->decor->hasBorder = false;
this->tableData[r * COLUMNS + c]->dims.x = xOffset + CELL_MARGIN;
this->tableData[r * COLUMNS + c]->dims.y = (cellH * r) + yOffset;
this->tableData[r * COLUMNS + c]->dims.height = cellH;
this->tableData[r * COLUMNS + c]->dims.width = tableCellW[c];
memset(this->tableData[r * COLUMNS + c]->value, 0,
this->tableData[r * COLUMNS + c]->bufferSize);
xOffset += tableCellW[c];
#ifdef DEBUG
this->tableData[r * COLUMNS + c].drawBox();
this->tableData[r * COLUMNS + c].Update("123");
this->tableData[r * COLUMNS + c]->drawBox();
this->tableData[r * COLUMNS + c]->Update("---");
#endif
}
}
+1 -1
View File
@@ -15,7 +15,7 @@ struct UITable : UIElement {
// will hold rows * columns UIStrings to fill the table
int rows = ROWS;
int columns = COLUMNS;
UIString tableData[ROWS * COLUMNS];
UIString **tableData;
UITable(Arduino_GFX *gfx, UIDimensions dims, UIDecorations *decor, char *t);