refactor: Right-align stock change percentage column

This commit is contained in:
C committed 2026-07-02 18:56:30 -07:00
1 parent 4a32c31a7b
commit 5687532c01
1 file changed
+9 -6
+9 -6
View File
@@ -224,10 +224,10 @@ void setup() {
int ROWY = (SCREEN_BOTTOM - ROW0) / NUM_STOCKS; int ROWY = (SCREEN_BOTTOM - ROW0) / NUM_STOCKS;
// Pick the largest font that fits the row height, with matching column positions // Pick the largest font that fits the row height, with matching column positions
int textSz, colPrice, colArrow, colChg, arrowSz, arrowOff; int textSz, charW, colPrice, colArrow, arrowSz, arrowOff;
if (ROWY >= 48) { textSz=3; colPrice=240; colArrow=455; colChg=500; arrowSz=32; arrowOff=6; } if (ROWY >= 48) { textSz=3; charW=24; colPrice=240; colArrow=460; arrowSz=20; arrowOff=14; }
else if (ROWY >= 32) { textSz=2; colPrice=168; colArrow=300; colChg=340; arrowSz=22; arrowOff=4; } else if (ROWY >= 32) { textSz=2; charW=16; colPrice=168; colArrow=310; arrowSz=14; arrowOff= 9; }
else { textSz=1; colPrice= 84; colArrow=152; colChg=168; arrowSz=12; arrowOff=2; } else { textSz=1; charW= 8; colPrice= 84; colArrow=152; arrowSz= 8; arrowOff= 4; }
M5.Display.setTextSize(textSz); M5.Display.setTextSize(textSz);
@@ -244,8 +244,11 @@ void setup() {
if (sd[i].change >= 0.0f) drawUpArrow (colArrow, y + arrowOff, arrowSz); if (sd[i].change >= 0.0f) drawUpArrow (colArrow, y + arrowOff, arrowSz);
else drawDownArrow(colArrow, y + arrowOff, arrowSz); else drawDownArrow(colArrow, y + arrowOff, arrowSz);
M5.Display.setCursor(colChg, y); // Right-align change text so all closing ')' line up at x=940
M5.Display.printf("%+.2f (%+.2f%%)", sd[i].change, sd[i].pct); 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 { } else {
M5.Display.setCursor(240, y); M5.Display.setCursor(240, y);
M5.Display.print(" N/A"); M5.Display.print(" N/A");