Made the header it's own code to be easier to create future screens

This commit is contained in:
HarukiToreda 2025-03-29 20:27:59 -04:00
parent 213a178d71
commit a3a0c14923

View File

@ -2010,54 +2010,37 @@ static void drawDistanceScreen(OLEDDisplay *display, OLEDDisplayUiState *state,
} }
static void drawDefaultScreen(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) { void drawCommonHeader(OLEDDisplay *display, int16_t x, int16_t y) {
display->clear();
display->setTextAlignment(TEXT_ALIGN_LEFT);
display->setFont(FONT_SMALL);
bool isInverted = (config.display.displaymode == meshtastic_Config_DisplayConfig_DisplayMode_INVERTED); bool isInverted = (config.display.displaymode == meshtastic_Config_DisplayConfig_DisplayMode_INVERTED);
bool isBold = config.display.heading_bold; bool isBold = config.display.heading_bold;
const int xOffset = 3; const int xOffset = 3;
const int highlightHeight = FONT_HEIGHT_SMALL - 1; const int highlightHeight = FONT_HEIGHT_SMALL - 1;
int screenWidth = display->getWidth();
display->setFont(FONT_SMALL);
display->setTextAlignment(TEXT_ALIGN_LEFT);
// Draw header background highlight
if (isInverted) { if (isInverted) {
drawRoundedHighlight(display, 0, y, SCREEN_WIDTH, highlightHeight, 2); drawRoundedHighlight(display, 0, y, SCREEN_WIDTH, highlightHeight, 2);
display->setColor(BLACK); display->setColor(BLACK);
} }
// === TOP ROW: Battery, %, Time === // Battery icon
int screenWidth = display->getWidth();
// Draw battery icon slightly inset from top
drawBattery(display, x + xOffset, y + 2, imgBattery, powerStatus); drawBattery(display, x + xOffset, y + 2, imgBattery, powerStatus);
// Calculate vertical center for text (centered in header row) // Centered text Y
int textY = y + (highlightHeight - FONT_HEIGHT_SMALL) / 2; int textY = y + (highlightHeight - FONT_HEIGHT_SMALL) / 2;
// Battery Percentage // Battery %
char percentStr[8]; char percentStr[8];
snprintf(percentStr, sizeof(percentStr), "%d%%", powerStatus->getBatteryChargePercent()); snprintf(percentStr, sizeof(percentStr), "%d%%", powerStatus->getBatteryChargePercent());
int batteryOffset = screenWidth > 128 ? 34 : 18; int batteryOffset = screenWidth > 128 ? 34 : 18;
int percentX = x + xOffset + batteryOffset; int percentX = x + xOffset + batteryOffset;
display->drawString(percentX, textY, percentStr); display->drawString(percentX, textY, percentStr);
if (isBold) display->drawString(percentX + 1, textY, percentStr); if (isBold) display->drawString(percentX + 1, textY, percentStr);
// --- Voltage (Commented out) --- // Optional: Local time
/* uint32_t rtc_sec = getValidTime(RTCQuality::RTCQualityDevice, true);
char voltStr[10];
int batV = powerStatus->getBatteryVoltageMv() / 1000;
int batCv = (powerStatus->getBatteryVoltageMv() % 1000) / 10;
snprintf(voltStr, sizeof(voltStr), "%d.%02dV", batV, batCv);
int voltX = SCREEN_WIDTH - xOffset - display->getStringWidth(voltStr);
display->drawString(voltX, textY, voltStr);
if (isBold) display->drawString(voltX + 1, textY, voltStr);
*/
// --- Local Time ---
uint32_t rtc_sec = getValidTime(RTCQuality::RTCQualityDevice, true); // local time
if (rtc_sec > 0) { if (rtc_sec > 0) {
long hms = rtc_sec % SEC_PER_DAY; long hms = rtc_sec % SEC_PER_DAY;
hms = (hms + SEC_PER_DAY) % SEC_PER_DAY; hms = (hms + SEC_PER_DAY) % SEC_PER_DAY;
@ -2078,6 +2061,14 @@ static void drawDefaultScreen(OLEDDisplay *display, OLEDDisplayUiState *state, i
} }
display->setColor(WHITE); display->setColor(WHITE);
}
static void drawDefaultScreen(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) {
display->clear();
display->setTextAlignment(TEXT_ALIGN_LEFT);
display->setFont(FONT_SMALL);
// === Header ===
drawCommonHeader(display, x, y);
// === Second Row: Node and GPS === // === Second Row: Node and GPS ===
bool origBold = config.display.heading_bold; bool origBold = config.display.heading_bold;
@ -2130,6 +2121,7 @@ static void drawDefaultScreen(OLEDDisplay *display, OLEDDisplayUiState *state, i
display->drawString(uptimeX, uptimeY, uptimeFullStr); display->drawString(uptimeX, uptimeY, uptimeFullStr);
} }
#if defined(ESP_PLATFORM) && defined(USE_ST7789) #if defined(ESP_PLATFORM) && defined(USE_ST7789)
SPIClass SPI1(HSPI); SPIClass SPI1(HSPI);
#endif #endif