mirror of
https://github.com/thooge/esp32-nmea2000-obp60.git
synced 2026-09-11 19:55:14 +02:00
Fix drawTextRalign(): avoid wobbling when DSEG italic font is used
This commit is contained in:
@@ -572,16 +572,32 @@ void drawButtonCenter(int16_t cx, int16_t cy, int8_t sx, int8_t sy, String text,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Draw right aligned text
|
// Draw right aligned text
|
||||||
void drawTextRalign(int16_t x, int16_t y, String text) {
|
// int16_t x - upper right x position for text to start printing
|
||||||
int16_t x1, y1;
|
// int16_t y - upper right y position for text to start printing
|
||||||
uint16_t w, h;
|
// const String& text - text to be printed
|
||||||
|
// bool dsegAdjust = false - optional, for adjustment of DSEG italic font
|
||||||
|
void drawTextRalign(int16_t x, int16_t y, const String& text, bool dsegAdjust)
|
||||||
|
{
|
||||||
|
int16_t x1 = 0, y1 = 0;
|
||||||
|
uint16_t w = 0, h = 0;
|
||||||
|
String str = text;
|
||||||
|
|
||||||
|
// make sure that we always have a char with max size at last position for boundary test
|
||||||
|
// to avoid text wobbling of DSEG italic font
|
||||||
|
if (dsegAdjust && str.length() > 0 && isDigit(str[str.length() - 1])) {
|
||||||
|
str.setCharAt(str.length() - 1, '8');
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef TFT_DISPLAY
|
#ifdef TFT_DISPLAY
|
||||||
w = getdisplay().textWidth(text);
|
w = getdisplay().textWidth(str);
|
||||||
h = getdisplay().fontHeight();
|
h = getdisplay().fontHeight();
|
||||||
#else
|
#else
|
||||||
getdisplay().getTextBounds(text, 0, 150, &x1, &y1, &w, &h);
|
getdisplay().getTextBounds(str, 0, y, &x1, &y1, &w, &h);
|
||||||
#endif
|
#endif
|
||||||
getdisplay().setCursor(x - w - 1, y); // '-1' required since some strings wrap around w/o it
|
|
||||||
|
int16_t cursorX = x - x1 - w;
|
||||||
|
getdisplay().setCursor(cursorX, y);
|
||||||
|
// getdisplay().setCursor(x - w - 1, y); // '-1' required since some strings wrap around w/o it
|
||||||
getdisplay().print(text);
|
getdisplay().print(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -734,7 +734,7 @@ String xdrDelete(String input); // Delete xdr prefix from string
|
|||||||
|
|
||||||
void drawTextCenter(int16_t cx, int16_t cy, String text);
|
void drawTextCenter(int16_t cx, int16_t cy, String text);
|
||||||
void drawButtonCenter(int16_t cx, int16_t cy, int8_t sx, int8_t sy, String text, uint16_t fg, uint16_t bg, bool inverted);
|
void drawButtonCenter(int16_t cx, int16_t cy, int8_t sx, int8_t sy, String text, uint16_t fg, uint16_t bg, bool inverted);
|
||||||
void drawTextRalign(int16_t x, int16_t y, String text);
|
void drawTextRalign(int16_t x, int16_t y, const String& text, bool dsegAdjust = false);
|
||||||
void drawTextBoxed(Rect box, String text, uint16_t fg, uint16_t bg, bool inverted, bool border);
|
void drawTextBoxed(Rect box, String text, uint16_t fg, uint16_t bg, bool inverted, bool border);
|
||||||
|
|
||||||
void displayTrendHigh(int16_t x, int16_t y, uint16_t size, uint16_t color);
|
void displayTrendHigh(int16_t x, int16_t y, uint16_t size, uint16_t color);
|
||||||
|
|||||||
@@ -6,21 +6,21 @@
|
|||||||
const int SixValues_x1 = 5;
|
const int SixValues_x1 = 5;
|
||||||
const int SixValues_DeltaX = 200;
|
const int SixValues_DeltaX = 200;
|
||||||
|
|
||||||
// const int SixValues_y1 = 23;
|
|
||||||
const int SixValues_y1 = 22;
|
const int SixValues_y1 = 22;
|
||||||
const int SixValues_DeltaY = 83;
|
const int SixValues_DeltaY = 83;
|
||||||
|
|
||||||
const int HowManyValues = 6;
|
const int HowManyValues = 6;
|
||||||
|
|
||||||
class PageSixValues : public Page
|
class PageSixValues : public Page {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
PageSixValues(CommonData &common){
|
PageSixValues(CommonData& common)
|
||||||
|
{
|
||||||
commonData = &common;
|
commonData = &common;
|
||||||
common.logger->logDebug(GwLog::LOG, "Instantiate PageSixValues");
|
common.logger->logDebug(GwLog::LOG, "Instantiate PageSixValues");
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual int handleKey(int key){
|
virtual int handleKey(int key)
|
||||||
|
{
|
||||||
// Code for keylock
|
// Code for keylock
|
||||||
if (key == 11) {
|
if (key == 11) {
|
||||||
commonData->keylock = !commonData->keylock;
|
commonData->keylock = !commonData->keylock;
|
||||||
@@ -29,18 +29,17 @@ class PageSixValues : public Page
|
|||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
int displayPage(PageData &pageData){
|
int displayPage(PageData& pageData)
|
||||||
|
{
|
||||||
GwConfigHandler* config = commonData->config;
|
GwConfigHandler* config = commonData->config;
|
||||||
GwLog* logger = commonData->logger;
|
GwLog* logger = commonData->logger;
|
||||||
|
|
||||||
|
|
||||||
// Old values for hold function
|
// Old values for hold function
|
||||||
static String OldDataText[HowManyValues] = { "", "", "", "", "", "" };
|
static String OldDataText[HowManyValues] = { "", "", "", "", "", "" };
|
||||||
static String OldDataUnits[HowManyValues] = { "", "", "", "", "", "" };
|
static String OldDataUnits[HowManyValues] = { "", "", "", "", "", "" };
|
||||||
|
|
||||||
// Get config data
|
// Get config data
|
||||||
String lengthformat = config->getString(config->lengthFormat);
|
String lengthformat = config->getString(config->lengthFormat);
|
||||||
// bool simulation = config->getBool(config->useSimuData);
|
|
||||||
bool holdvalues = config->getBool(config->holdvalues);
|
bool holdvalues = config->getBool(config->holdvalues);
|
||||||
String flashLED = config->getString(config->flashLED);
|
String flashLED = config->getString(config->flashLED);
|
||||||
String backlightMode = config->getString(config->backlight);
|
String backlightMode = config->getString(config->backlight);
|
||||||
@@ -70,7 +69,8 @@ class PageSixValues : public Page
|
|||||||
setFlashLED(false);
|
setFlashLED(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bvalue == NULL) return PAGE_OK; // WTF why this statement?
|
if (bvalue == NULL)
|
||||||
|
return PAGE_OK;
|
||||||
|
|
||||||
// Draw page
|
// Draw page
|
||||||
//***********************************************************
|
//***********************************************************
|
||||||
@@ -99,44 +99,33 @@ class PageSixValues : public Page
|
|||||||
getdisplay().setFont(&Ubuntu_Bold8pt8b);
|
getdisplay().setFont(&Ubuntu_Bold8pt8b);
|
||||||
if (holdvalues == false) {
|
if (holdvalues == false) {
|
||||||
drawTextRalign(x0 + 187, y0 + 19, DataUnits[ValueIndex]); // Unit
|
drawTextRalign(x0 + 187, y0 + 19, DataUnits[ValueIndex]); // Unit
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
drawTextRalign(x0 + 187, y0 + 19, OldDataUnits[ValueIndex]);
|
drawTextRalign(x0 + 187, y0 + 19, OldDataUnits[ValueIndex]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Switch font depending on data type
|
// Switch font depending on data type
|
||||||
if (DataFormat[ValueIndex] == "formatLatitude" || DataFormat[ValueIndex] == "formatLongitude") {
|
if (DataFormat[ValueIndex] == "formatLatitude" || DataFormat[ValueIndex] == "formatLongitude") {
|
||||||
getdisplay().setFont(&Ubuntu_Bold12pt8b);
|
getdisplay().setFont(&Ubuntu_Bold12pt8b);
|
||||||
getdisplay().setCursor(x0+21, y0+60);
|
} else if (DataFormat[ValueIndex] == "formatTime" || DataFormat[ValueIndex] == "formatDate") {
|
||||||
}
|
|
||||||
else if(DataFormat[ValueIndex] == "formatTime" || DataFormat[ValueIndex] == "formatDate"){
|
|
||||||
getdisplay().setFont(&Ubuntu_Bold16pt8b);
|
getdisplay().setFont(&Ubuntu_Bold16pt8b);
|
||||||
getdisplay().setCursor(x0+23,y0+55);
|
|
||||||
}
|
}
|
||||||
// pressure in hPa
|
// pressure in hPa
|
||||||
else if (DataFormat[ValueIndex] == "formatXdr:P:P") {
|
else if (DataFormat[ValueIndex] == "formatXdr:P:P") {
|
||||||
getdisplay().setFont(&DSEG7Classic_BoldItalic26pt7b);
|
getdisplay().setFont(&DSEG7Classic_BoldItalic26pt7b);
|
||||||
getdisplay().setCursor(x0+23, y0+79);
|
|
||||||
}
|
}
|
||||||
// RPM
|
// RPM
|
||||||
else if (DataFormat[ValueIndex] == "formatXdr:T:R") {
|
else if (DataFormat[ValueIndex] == "formatXdr:T:R") {
|
||||||
getdisplay().setFont(&DSEG7Classic_BoldItalic16pt7b);
|
getdisplay().setFont(&DSEG7Classic_BoldItalic16pt7b);
|
||||||
getdisplay().setCursor(x0+23, y0+79);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
getdisplay().setFont(&DSEG7Classic_BoldItalic26pt7b);
|
getdisplay().setFont(&DSEG7Classic_BoldItalic26pt7b);
|
||||||
if ( DataText[ValueIndex][0] == '-' )
|
|
||||||
getdisplay().setCursor(x0+23, y0+79);
|
|
||||||
else
|
|
||||||
getdisplay().setCursor(x0+65, y0+79);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show bus data
|
// Show bus data
|
||||||
if (holdvalues == false) {
|
if (holdvalues == false) {
|
||||||
getdisplay().print(DataText[ValueIndex]); // Real value as formated string
|
drawTextRalign(x0 + 187, y0 + 79, DataText[ValueIndex], true); // Real value as formatted string
|
||||||
}
|
} else {
|
||||||
else{
|
drawTextRalign(x0 + 187, y0 + 79, OldDataText[ValueIndex], true); // Old value as formatted string
|
||||||
getdisplay().print(OldDataText[ValueIndex]); // Old value as formated string
|
|
||||||
}
|
}
|
||||||
if (DataValid[ValueIndex] == true) {
|
if (DataValid[ValueIndex] == true) {
|
||||||
OldDataText[ValueIndex] = DataText[ValueIndex]; // Save the old value
|
OldDataText[ValueIndex] = DataText[ValueIndex]; // Save the old value
|
||||||
@@ -149,9 +138,9 @@ class PageSixValues : public Page
|
|||||||
|
|
||||||
return PAGE_UPDATE;
|
return PAGE_UPDATE;
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
static Page *createPage(CommonData &common){
|
static Page* createPage(CommonData& common)
|
||||||
|
{
|
||||||
return new PageSixValues(common);
|
return new PageSixValues(common);
|
||||||
} /**
|
} /**
|
||||||
* with the code below we make this page known to the PageTask
|
* with the code below we make this page known to the PageTask
|
||||||
|
|||||||
Reference in New Issue
Block a user