Some layout changes
This commit is contained in:
@@ -5,7 +5,7 @@ UIBar::UIBar(Arduino_GFX *d, UIDimensions dims, UIDecorations *decor,
|
|||||||
char *title)
|
char *title)
|
||||||
: UIElement(d, dims, decor, title) {}
|
: UIElement(d, dims, decor, title) {}
|
||||||
|
|
||||||
void UIBar::Update(char* v) {
|
void UIBar::Update(char *v) {
|
||||||
unsigned long time = millis();
|
unsigned long time = millis();
|
||||||
if ((time - this->lastUpdate) <= this->refreshRate) {
|
if ((time - this->lastUpdate) <= this->refreshRate) {
|
||||||
return;
|
return;
|
||||||
@@ -92,11 +92,12 @@ void UIBar::Box() {
|
|||||||
|
|
||||||
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);
|
||||||
this->display->setCursor(x, this->dims.y + this->dims.height + 7 + 2);
|
|
||||||
this->display->setTextColor(WHITE);
|
|
||||||
|
|
||||||
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->dims.y + this->dims.height + 7 + 2);
|
||||||
|
this->display->setTextColor(WHITE);
|
||||||
this->display->setTextSize(this->decor->textSize);
|
this->display->setTextSize(this->decor->textSize);
|
||||||
this->display->print(legend);
|
this->display->print(legend);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,9 +40,11 @@ struct UIElement {
|
|||||||
uint16_t getTitleAreaWidth();
|
uint16_t getTitleAreaWidth();
|
||||||
|
|
||||||
// Positioning
|
// Positioning
|
||||||
void horizontalCenter();
|
void horizontalCenter(UIElement *reference);
|
||||||
|
void verticalCenter(UIElement *reference);
|
||||||
void placeBelow(UIElement *reference);
|
void placeBelow(UIElement *reference);
|
||||||
void placeRight(UIElement *reference);
|
void placeRight(UIElement *reference);
|
||||||
|
void placeLeft(UIElement *reference);
|
||||||
|
|
||||||
// Drawing
|
// Drawing
|
||||||
void drawBox();
|
void drawBox();
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include "UIDrawing.h"
|
#include "UIDrawing.h"
|
||||||
#include "Arduino_GFX.h"
|
#include "Arduino_GFX.h"
|
||||||
|
#include "HardwareSerial.h"
|
||||||
#include "UIComponent.h"
|
#include "UIComponent.h"
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
@@ -7,7 +8,7 @@
|
|||||||
* On the placement functions, change 5 to a variable or something
|
* 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) {
|
uint16_t calculateHeight(int16_t titleSize, int16_t textSize, int16_t nLines) {
|
||||||
return CHR_HEIGHT(titleSize) + CHR_HEIGHT(textSize) +
|
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));
|
(2 * (DEFAULT_MARGIN + DEFAULT_BORDER_THICKNESS));
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIElement::horizontalCenter() {
|
void UIElement::horizontalCenter(UIElement *ref) {
|
||||||
uint16_t scrW = this->display->width();
|
uint16_t middlePoint = 0;
|
||||||
this->dims.x = (scrW - this->dims.width) / 2;
|
|
||||||
|
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
|
// 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;
|
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() {
|
void UIElement::drawBox() {
|
||||||
// This is the border rectangle
|
// This is the border rectangle
|
||||||
if (this->decor->hasBorder) {
|
if (this->decor->hasBorder) {
|
||||||
|
|||||||
+7
-5
@@ -113,8 +113,9 @@ void setup() {
|
|||||||
// Setup the rpmBar box
|
// Setup the rpmBar box
|
||||||
rpmBarDecor->textSize = 3;
|
rpmBarDecor->textSize = 3;
|
||||||
rpmBar.dims.height = 50;
|
rpmBar.dims.height = 50;
|
||||||
rpmBar.dims.width = 350;
|
rpmBar.dims.width = 450;
|
||||||
rpmBar.horizontalCenter();
|
rpmBar.horizontalCenter(nullptr);
|
||||||
|
rpmBar.dims.x += 10;
|
||||||
rpmBar.range = 8;
|
rpmBar.range = 8;
|
||||||
rpmBar.refreshRate = 50;
|
rpmBar.refreshRate = 50;
|
||||||
ui->barTacho = &rpmBar;
|
ui->barTacho = &rpmBar;
|
||||||
@@ -126,8 +127,8 @@ void setup() {
|
|||||||
rpmText.dims.height =
|
rpmText.dims.height =
|
||||||
calculateHeight(rpmTextDecor->titleSize, rpmTextDecor->textSize, 1);
|
calculateHeight(rpmTextDecor->titleSize, rpmTextDecor->textSize, 1);
|
||||||
rpmText.dims.width = calculateWidth(rpmTextDecor->textSize, 5);
|
rpmText.dims.width = calculateWidth(rpmTextDecor->textSize, 5);
|
||||||
rpmText.horizontalCenter();
|
|
||||||
rpmText.placeBelow(&rpmBar);
|
rpmText.placeBelow(&rpmBar);
|
||||||
|
rpmText.horizontalCenter(&rpmBar);
|
||||||
rpmText.dims.y += 40; // We gotta fix how the bar declares its height instead
|
rpmText.dims.y += 40; // We gotta fix how the bar declares its height instead
|
||||||
// of doing this here
|
// of doing this here
|
||||||
rpmText.refreshRate = 100;
|
rpmText.refreshRate = 100;
|
||||||
@@ -154,7 +155,7 @@ void setup() {
|
|||||||
calculateHeight(gearTextDecor->titleSize, gearTextDecor->textSize, 1);
|
calculateHeight(gearTextDecor->titleSize, gearTextDecor->textSize, 1);
|
||||||
gearText.dims.width = calculateWidth(gearTextDecor->textSize, 2);
|
gearText.dims.width = calculateWidth(gearTextDecor->textSize, 2);
|
||||||
gearText.dims.y = rpmText.dims.height + 5;
|
gearText.dims.y = rpmText.dims.height + 5;
|
||||||
gearText.placeBelow(&rpmText);
|
gearText.placeLeft(&rpmText);
|
||||||
ui->digiGear = &gearText;
|
ui->digiGear = &gearText;
|
||||||
ui->digiGear->drawBox();
|
ui->digiGear->drawBox();
|
||||||
ui->digiGear->Update("-");
|
ui->digiGear->Update("-");
|
||||||
@@ -164,7 +165,8 @@ void setup() {
|
|||||||
lapDelta.dims.height =
|
lapDelta.dims.height =
|
||||||
calculateHeight(lapDeltaDecor->titleSize, lapDeltaDecor->textSize, 1);
|
calculateHeight(lapDeltaDecor->titleSize, lapDeltaDecor->textSize, 1);
|
||||||
lapDelta.dims.width = calculateWidth(lapDeltaDecor->textSize, 6);
|
lapDelta.dims.width = calculateWidth(lapDeltaDecor->textSize, 6);
|
||||||
lapDelta.placeBelow(&gearText);
|
lapDelta.placeBelow(&rpmText);
|
||||||
|
lapDelta.horizontalCenter(&rpmText);
|
||||||
ui->lapDelta = &lapDelta;
|
ui->lapDelta = &lapDelta;
|
||||||
ui->lapDelta->drawBox();
|
ui->lapDelta->drawBox();
|
||||||
ui->lapDelta->Update("--.-");
|
ui->lapDelta->Update("--.-");
|
||||||
|
|||||||
Reference in New Issue
Block a user