Some layout changes

This commit is contained in:
2025-05-21 18:10:50 +01:00
parent 106fdbb4dd
commit a41ac82389
4 changed files with 31 additions and 13 deletions
+4 -3
View File
@@ -5,7 +5,7 @@ UIBar::UIBar(Arduino_GFX *d, UIDimensions dims, UIDecorations *decor,
char *title)
: UIElement(d, dims, decor, title) {}
void UIBar::Update(char* v) {
void UIBar::Update(char *v) {
unsigned long time = millis();
if ((time - this->lastUpdate) <= this->refreshRate) {
return;
@@ -92,11 +92,12 @@ void UIBar::Box() {
this->display->setTextColor(RED);
this->display->drawFastVLine(x, this->dims.y + this->dims.height, 7, RED);
this->display->setCursor(x, this->dims.y + this->dims.height + 7 + 2);
this->display->setTextColor(WHITE);
char legend[5];
sprintf(legend, "%d", k);
this->display->setCursor(x - (CHR_WIDTH(this->decor->textSize) / 2),
this->dims.y + this->dims.height + 7 + 2);
this->display->setTextColor(WHITE);
this->display->setTextSize(this->decor->textSize);
this->display->print(legend);
}
+3 -1
View File
@@ -40,9 +40,11 @@ struct UIElement {
uint16_t getTitleAreaWidth();
// Positioning
void horizontalCenter();
void horizontalCenter(UIElement *reference);
void verticalCenter(UIElement *reference);
void placeBelow(UIElement *reference);
void placeRight(UIElement *reference);
void placeLeft(UIElement *reference);
// Drawing
void drawBox();
+17 -4
View File
@@ -1,5 +1,6 @@
#include "UIDrawing.h"
#include "Arduino_GFX.h"
#include "HardwareSerial.h"
#include "UIComponent.h"
#include <cstdint>
@@ -7,7 +8,7 @@
* On the placement functions, change 5 to a variable or something
*/
#define DEBUG
// #define DEBUG
uint16_t calculateHeight(int16_t titleSize, int16_t textSize, int16_t nLines) {
return CHR_HEIGHT(titleSize) + CHR_HEIGHT(textSize) +
@@ -20,9 +21,17 @@ uint16_t calculateWidth(int16_t textSize, int16_t nChars) {
(2 * (DEFAULT_MARGIN + DEFAULT_BORDER_THICKNESS));
}
void UIElement::horizontalCenter() {
uint16_t scrW = this->display->width();
this->dims.x = (scrW - this->dims.width) / 2;
void UIElement::horizontalCenter(UIElement *ref) {
uint16_t middlePoint = 0;
if (ref != nullptr) {
Serial2.println("We are here indeed!");
middlePoint = ref->dims.x + (ref->dims.width / 2);
} else {
middlePoint = this->display->width() / 2;
}
this->dims.x = middlePoint - (this->dims.width / 2);
}
// We can add a mode of alignment here, center, left, right, whatever
@@ -36,6 +45,10 @@ void UIElement::placeRight(UIElement *ref) {
this->dims.x = ref->dims.x + ref->dims.width + 5;
}
void UIElement::placeLeft(UIElement *ref) {
this->dims.x = ref->dims.x - this->dims.width - 5;
}
void UIElement::drawBox() {
// This is the border rectangle
if (this->decor->hasBorder) {