diff --git a/m5paper-stockticker.ino b/m5paper-stockticker.ino index 00d4ee4..c291490 100644 --- a/m5paper-stockticker.ino +++ b/m5paper-stockticker.ino @@ -224,10 +224,10 @@ void setup() { int ROWY = (SCREEN_BOTTOM - ROW0) / NUM_STOCKS; // Pick the largest font that fits the row height, with matching column positions - int textSz, colPrice, colArrow, colChg, arrowSz, arrowOff; - if (ROWY >= 48) { textSz=3; colPrice=240; colArrow=455; colChg=500; arrowSz=32; arrowOff=6; } - else if (ROWY >= 32) { textSz=2; colPrice=168; colArrow=300; colChg=340; arrowSz=22; arrowOff=4; } - else { textSz=1; colPrice= 84; colArrow=152; colChg=168; arrowSz=12; arrowOff=2; } + int textSz, charW, colPrice, colArrow, arrowSz, arrowOff; + if (ROWY >= 48) { textSz=3; charW=24; colPrice=240; colArrow=460; arrowSz=20; arrowOff=14; } + else if (ROWY >= 32) { textSz=2; charW=16; colPrice=168; colArrow=310; arrowSz=14; arrowOff= 9; } + else { textSz=1; charW= 8; colPrice= 84; colArrow=152; arrowSz= 8; arrowOff= 4; } M5.Display.setTextSize(textSz); @@ -244,8 +244,11 @@ void setup() { if (sd[i].change >= 0.0f) drawUpArrow (colArrow, y + arrowOff, arrowSz); else drawDownArrow(colArrow, y + arrowOff, arrowSz); - M5.Display.setCursor(colChg, y); - M5.Display.printf("%+.2f (%+.2f%%)", sd[i].change, sd[i].pct); + // Right-align change text so all closing ')' line up at x=940 + char chgBuf[32]; + snprintf(chgBuf, sizeof(chgBuf), "%+.2f (%+.2f%%)", sd[i].change, sd[i].pct); + M5.Display.setCursor(940 - (int)strlen(chgBuf) * charW, y); + M5.Display.print(chgBuf); } else { M5.Display.setCursor(240, y); M5.Display.print(" N/A");