First commit

I shall move all this to another branch -> master_vendored or something
This commit is contained in:
2025-03-12 21:42:39 +00:00
commit f9d0bfa4d9
226 changed files with 240315 additions and 0 deletions
+24
View File
@@ -0,0 +1,24 @@
{
"name": "ili9488CursesUI",
"version": "0.1.1",
"description": "Simple UI for creating interfaces with the ili9488 and arduinos",
"keywords": "ili9488, pro micro, curses",
"repository":
{
"type": "git",
"url": "https://github.com/ESilva15/ili9488CursesUI"
},
"authors":
[
{
"name": "Eduardo Silva",
"maintainer": true
}
],
"dependencies": {
"Adafruit_GFX_Library": "~1.11.3",
"Adafruit_BusIO": "1.16.1"
},
"frameworks": "*",
"platforms": "*"
}
View File
+117
View File
@@ -0,0 +1,117 @@
#include "UIComponent.h"
// #include "u8g2.h"
#include "UIDrawing.h"
// #include <U8g2lib.h>
#include <cstdint>
UIElement::UIElement(Arduino_GFX *d, UIDimensions dims, UIDecorations *decor,
char *title)
: display(d), dims(dims), decor(decor), title(title) {}
UIDimensions::UIDimensions(uint16_t x, uint16_t y, uint16_t w, uint16_t h)
: x(x), y(y), width(w), height(h) {}
int16_t UIElement::getContentAreaX0() {
return this->dims.x + DEFAULT_BORDER_THICKNESS + DEFAULT_MARGIN;
}
int16_t UIElement::getContentAreaY0() {
return this->dims.y + this->getTitleAreaHeight() +
DEFAULT_TITLE_CONTENT_SPACING;
}
uint16_t UIElement::getContentAreaHeight() {
return this->dims.height - (DEFAULT_MARGIN * 2) - DEFAULT_BORDER_THICKNESS -
this->getTitleAreaHeight();
}
uint16_t UIElement::getContentAreaWidth() {
return this->dims.width - ((DEFAULT_BORDER_THICKNESS + DEFAULT_MARGIN) * 2);
}
int16_t UIElement::getTitleAreaX0() {
return this->dims.x + DEFAULT_BORDER_THICKNESS + DEFAULT_MARGIN;
}
int16_t UIElement::getTitleAreaY0() { return this->dims.y; }
uint16_t UIElement::getTitleAreaHeight() {
int16_t x = 0, y = 0;
uint16_t w = 0, h = 0;
this->display->setTextSize(this->decor->titleSize);
this->display->getTextBounds((const char *)this->title, 0, 0, &x, &y, &w, &h);
return h;
}
void UIElement::drawBox() {
// This is the border rectangle
for (int k = 0; k < DEFAULT_BORDER_THICKNESS; k++) {
this->display->drawRect(
this->dims.x + k, this->dims.y + k, this->dims.width - (k * 2),
this->dims.height - (k * 2), this->decor->borderColor);
}
// For debugging purpouses
// title area
int16_t x = 0, y = 0;
uint16_t w = 0, h = 0;
// U8G2 u8g2; // No display pin setup needed since we're only using font data
// u8g2.setFont(u8g2_font_9x18_tf);
// int ascent = u8g2.getAscent();
h = this->getTitleAreaHeight();
int16_t titleTopLeftX = this->getTitleAreaX0();
this->display->drawRect(titleTopLeftX, this->getTitleAreaY0(), w, h, BLUE);
// content area
x = this->getContentAreaX0();
y = this->getContentAreaY0();
w = this->getContentAreaWidth();
h = this->getContentAreaHeight();
this->display->drawRect(x, y, w, h, BLUE);
this->display->setCursor(titleTopLeftX, this->dims.y);
this->display->print(this->title);
}
void UIElement::replaceString(char *oldVal, char *newVal) {
size_t newValLen = strlen(newVal);
size_t oldValLen = strlen(oldVal);
int16_t x0 = this->getContentAreaX0();
int16_t y0 = this->getContentAreaY0();
this->display->setTextSize(this->decor->textSize);
// If the new value is shorter, delete the extra in advance
if (oldValLen > newValLen) {
// If the old value is longer than the new value, we have to delete the
// extra of the old value, which is whatever starts at the new value len
for (size_t start = newValLen; start < oldValLen; start++) {
this->display->setCursor(x0 + start * (CHR_WIDTH(this->decor->textSize)),
y0);
this->display->setTextColor(this->decor->bgColor);
this->display->print(oldVal[start]);
}
}
for (size_t k = 0; k < newValLen; k++) {
if (k <= oldValLen) {
if (oldVal[k] != newVal[k]) {
this->display->setCursor(x0 + k * (CHR_WIDTH(this->decor->textSize)),
y0 + 0);
this->display->setTextColor(this->decor->bgColor);
this->display->print(oldVal[k]);
}
}
this->display->setCursor(x0 + k * (CHR_WIDTH(this->decor->textSize)),
y0 + 0);
this->display->setTextColor(this->decor->fgColor);
this->display->print(newVal[k]);
}
}
+37
View File
@@ -0,0 +1,37 @@
#ifndef __UI_COMPONENT
#define __UI_COMPONENT
#include "Arduino_GFX.h"
#include "UIDecorations.h"
#include <stdint.h>
struct UIDimensions {
uint16_t x = 0, y = 0;
uint16_t width = 0, height = 0;
UIDimensions(uint16_t x, uint16_t y, uint16_t w, uint16_t h);
};
struct UIElement {
Arduino_GFX *display;
UIDimensions dims;
UIDecorations *decor;
char *title;
uint64_t lastUpdate = 0;
uint16_t refreshRate = 0;
UIElement(Arduino_GFX *d, UIDimensions dims, UIDecorations *decor,
char *Title);
void drawBox();
void replaceString(char *oldVal, char *newVal);
int16_t getContentAreaX0();
int16_t getContentAreaY0();
uint16_t getContentAreaHeight();
uint16_t getContentAreaWidth();
int16_t getTitleAreaX0();
int16_t getTitleAreaY0();
uint16_t getTitleAreaHeight();
uint16_t getTitleAreaWidth();
};
#endif
+6
View File
@@ -0,0 +1,6 @@
#include "UIDecorations.h"
UIDecorations::UIDecorations() {}
UIDecorations::UIDecorations(uint16_t bg, uint16_t fg, uint16_t title,
uint16_t border, uint8_t titleSize,
uint8_t textSize) {}
+17
View File
@@ -0,0 +1,17 @@
#ifndef __UI_DECORATIONS
#define __UI_DECORATIONS
#include "UIDrawing.h"
#include <stdint.h>
struct UIDecorations {
uint16_t bgColor = MAIN_BG_COLOR, fgColor = MAIN_FG_COLOR;
uint16_t titleColor = MAIN_FG_COLOR, borderColor = RED;
uint8_t titleSize = 2, textSize = 4;
UIDecorations();
UIDecorations(uint16_t bg, uint16_t fg, uint16_t title, uint16_t border,
uint8_t titleSize, uint8_t textSize);
};
#endif
+12
View File
@@ -0,0 +1,12 @@
#include "UIDrawing.h"
uint16_t calculateHeight(int16_t titleSize, int16_t textSize, int16_t nLines) {
return CHR_HEIGHT(titleSize) + CHR_HEIGHT(textSize) +
DEFAULT_TITLE_CONTENT_SPACING +
(2 * (DEFAULT_BORDER_THICKNESS + DEFAULT_MARGIN));
}
uint16_t calculateWidth(int16_t textSize, int16_t nChars) {
return CHR_WIDTH(textSize) * nChars +
(2 * (DEFAULT_MARGIN + DEFAULT_BORDER_THICKNESS));
}
+25
View File
@@ -0,0 +1,25 @@
#ifndef __CURSES_UI_VISUALS
#define __CURSES_UI_VISUALS
#include <Arduino_GFX.h>
#define RIGHT 0
#define INVERTED 1
#define LEFT 2
#define NORMAL 3
#define DEFAULT_BORDER_THICKNESS 3
#define DEFAULT_TITLE_CONTENT_SPACING 3
#define DEFAULT_MARGIN 3
#define MAIN_BG_COLOR RGB565(20, 10, 10)
#define MAIN_FG_COLOR RGB565(255, 255, 255)
#define CHR_WIDTH(size) (6 * size)
#define CHR_HEIGHT(size) (8 * size)
#define CHR_SPACE(size) (size)
uint16_t calculateHeight(int16_t titleSize, int16_t textSize, int16_t nLines);
uint16_t calculateWidth(int16_t textSize, int16_t nChars);
#endif
+36
View File
@@ -0,0 +1,36 @@
#include "UIString.h"
#include "UIComponent.h"
#include <Arduino_GFX.h>
UIString::UIString(Arduino_GFX *d, UIDimensions dims, UIDecorations *decor,
char *title)
: UIElement(d, dims, decor, title) {}
void UIString::Update(const char *v) {
uint64_t time = millis();
if ((time - this->lastUpdate) <= this->refreshRate) {
return;
}
// If the value is larger than our buffer - should add a way of knowing we
// got an error here
if (strlen(v) >= this->bufferSize) {
return;
}
// If the value hasn't changed we do not need to re-render
if (strcmp(this->value, v) == 0) {
return;
}
char newVal[this->bufferSize];
sprintf(newVal, "%s", v);
char oldVal[this->bufferSize];
sprintf(oldVal, "%s", this->value);
// Figure out the x0 and y0 for the text
replaceString(oldVal, newVal);
strncpy(this->value, v, this->bufferSize);
}
+16
View File
@@ -0,0 +1,16 @@
#ifndef __UI_STRING
#define __UI_STRING
#include "UIComponent.h"
// Representation of single line strings
struct UIString : UIElement {
static const size_t bufferSize = 256;
char value[bufferSize];
UIString(Arduino_GFX *d, UIDimensions dims, UIDecorations *decor,
char *title);
void Update(const char *value);
};
#endif