diff --git a/lib/obp60task/OBP60Extensions.cpp b/lib/obp60task/OBP60Extensions.cpp index d30b135..33965ff 100644 --- a/lib/obp60task/OBP60Extensions.cpp +++ b/lib/obp60task/OBP60Extensions.cpp @@ -576,7 +576,7 @@ void drawButtonCenter(int16_t cx, int16_t cy, int8_t sx, int8_t sy, String text, // int16_t y - upper right y position for text to start printing // 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 drawTextRalign(int16_t x, int16_t y, const String& text, bool dsegAdjust) { int16_t x1 = 0, y1 = 0; uint16_t w = 0, h = 0; @@ -599,6 +599,34 @@ void drawTextRalign(int16_t x, int16_t y, const String& text, bool dsegAdjust) getdisplay().setCursor(cursorX, y); // getdisplay().setCursor(x - w - 1, y); // '-1' required since some strings wrap around w/o it getdisplay().print(text); + + return cursorX; // actual visible left edge +} + +// Draw right aligned numbers with smaller decimals +// int16_t x - upper right x position for text to start printing +// int16_t y - upper right y position for text to start printing +// const String& text - number as text to be printed +// const GFXfont* mainFont - font type and size for integer part of number +// const GFXfont* decimalFont - font type and size for decimals part of number +void printDecimalRightAlign(int16_t x, int16_t y, const String& text, const GFXfont* mainFont, const GFXfont* decimalFont) { + String integerPart, decimalPart; + const int16_t dot = text.indexOf('.'); + + if (dot != -1) { + integerPart = text.substring(0, dot + 1); // includes '.' + decimalPart = text.substring(dot + 1); + } else { + integerPart = text; + } + + // Draw decimal part first. + display.setFont(decimalFont); + int16_t decimalLeft = drawTextRalign(x, y, decimalPart); + + // Draw integer part immediately to its left. + display.setFont(mainFont); + drawTextRalign(decimalLeft, y, integerPart); } // Draw text inside box, normal or inverted diff --git a/lib/obp60task/OBP60Formatter.cpp b/lib/obp60task/OBP60Formatter.cpp index 6aafe2e..7df3f48 100644 --- a/lib/obp60task/OBP60Formatter.cpp +++ b/lib/obp60task/OBP60Formatter.cpp @@ -100,17 +100,19 @@ FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata, bool //All values are displayed using a DSEG7* font. In this font, ' ' is a very short space, and '.' takes up no space at all. //For a space that is as long as a number, '!' is used. For details see https://www.keshikan.net/fonts-e.html // - fmt_dec_1 = "!%1.1f"; //insert a blank digit and then display a two-digit number - fmt_dec_10 = "!%2.0f"; //insert a blank digit and then display a two-digit number - fmt_dec_100 = "%3.0f"; //dispay a three digit number - limit_dec_10=9.95; // use fmt_dec_1 below this number to avoid formatting 9.96 as 10.0 instead of 10 - limit_dec_100=99.5; + fmt_dec_1 = "!%1.1f"; // blank digit + 2 digit number, incl. 1 decimal +// fmt_dec_10 = "!%2.0f"; //insert a blank digit and then display a two-digit number + fmt_dec_10 = "%3.1f"; // 3 digit number, incl. 1 decimal + fmt_dec_100 = "%3.0f"; // 3 digit number, no decimal + limit_dec_10=9.95; // use fmt_dec_1 below this number to avoid formatting 9.96 as 10.0 instead of 10 + limit_dec_100=99.5; } else { fmt_dec_1 = "%3.2f"; - fmt_dec_10 = "%3.1f"; +// fmt_dec_10 = "%3.1f"; + fmt_dec_10 = "%3.2f"; // test for small decimals fmt_dec_100 = "%3.0f"; - limit_dec_10=9.995; - limit_dec_100=99.95; + limit_dec_10=9.995; + limit_dec_100=99.95; } // LOG_DEBUG(GwLog::DEBUG,"formatValue init: getFormat: %s date->value: %f time->value: %f", value->getFormat(), commondata.date->value, commondata.time->value); diff --git a/lib/obp60task/PageSixValues.cpp b/lib/obp60task/PageSixValues.cpp index 0813f3a..0405f82 100644 --- a/lib/obp60task/PageSixValues.cpp +++ b/lib/obp60task/PageSixValues.cpp @@ -123,9 +123,11 @@ public: // Show bus data if (holdvalues == false) { - drawTextRalign(x0 + 187, y0 + 79, DataText[ValueIndex], true); // Real value as formatted string +// drawTextRalign(x0 + 187, y0 + 79, DataText[ValueIndex], true); // Real value as formatted string + printDecimalRightAlign(x0 + 187, y0 + 79, DataText[ValueIndex], &DSEG7Classic_BoldItalic26pt7b, &DSEG7Classic_BoldItalic20pt7b); // Real value as formatted string } else { - drawTextRalign(x0 + 187, y0 + 79, OldDataText[ValueIndex], true); // Old value as formatted string +// drawTextRalign(x0 + 187, y0 + 79, OldDataText[ValueIndex], true); // Old value as formatted string + printDecimalRightAlign(x0 + 187, y0 + 79, OldDataText[ValueIndex], &DSEG7Classic_BoldItalic26pt7b, &DSEG7Classic_BoldItalic20pt7b); // Real value as formatted string } if (DataValid[ValueIndex] == true) { OldDataText[ValueIndex] = DataText[ValueIndex]; // Save the old value