mirror of
https://github.com/meshtastic/firmware.git
synced 2025-08-09 23:24:43 +00:00
Conditional tittle and data based on screen size
This commit is contained in:
parent
7181e1a296
commit
f60c4ec5bc
@ -2340,27 +2340,28 @@ static void drawMemoryScreen(OLEDDisplay *display, OLEDDisplayUiState *state, in
|
|||||||
// === Draw title ===
|
// === Draw title ===
|
||||||
const int highlightHeight = FONT_HEIGHT_SMALL - 1;
|
const int highlightHeight = FONT_HEIGHT_SMALL - 1;
|
||||||
const int textY = y + (highlightHeight - FONT_HEIGHT_SMALL) / 2;
|
const int textY = y + (highlightHeight - FONT_HEIGHT_SMALL) / 2;
|
||||||
|
const int screenWidth = display->getWidth();
|
||||||
|
const char* titleStr = (screenWidth > 128) ? "Memory" : "Mem";
|
||||||
|
const int centerX = x + SCREEN_WIDTH / 2;
|
||||||
|
|
||||||
if (config.display.displaymode == meshtastic_Config_DisplayConfig_DisplayMode_INVERTED) {
|
if (config.display.displaymode == meshtastic_Config_DisplayConfig_DisplayMode_INVERTED) {
|
||||||
display->setColor(BLACK);
|
display->setColor(BLACK);
|
||||||
}
|
}
|
||||||
|
|
||||||
display->setTextAlignment(TEXT_ALIGN_CENTER);
|
display->setTextAlignment(TEXT_ALIGN_CENTER);
|
||||||
const int centerX = x + SCREEN_WIDTH / 2;
|
display->drawString(centerX, textY, titleStr);
|
||||||
display->drawString(centerX, textY, "Memory");
|
|
||||||
if (config.display.heading_bold) {
|
if (config.display.heading_bold) {
|
||||||
display->drawString(centerX + 1, textY, "Memory");
|
display->drawString(centerX + 1, textY, titleStr);
|
||||||
}
|
}
|
||||||
display->setColor(WHITE);
|
display->setColor(WHITE);
|
||||||
|
|
||||||
// === Layout ===
|
// === Layout ===
|
||||||
const int screenWidth = display->getWidth();
|
|
||||||
const int rowYOffset = FONT_HEIGHT_SMALL - 3;
|
const int rowYOffset = FONT_HEIGHT_SMALL - 3;
|
||||||
const int barHeight = 6;
|
const int barHeight = 6;
|
||||||
|
|
||||||
const int labelX = x;
|
const int labelX = x;
|
||||||
const int barsOffset = (screenWidth > 128) ? 24 : 0;
|
const int barsOffset = (screenWidth > 128) ? 24 : 0;
|
||||||
const int barX = x + 40 + barsOffset;
|
const int barX = x + 40 + barsOffset;
|
||||||
const int barWidth = SCREEN_WIDTH - barX - 35;
|
|
||||||
const int textRightX = x + SCREEN_WIDTH - 2;
|
const int textRightX = x + SCREEN_WIDTH - 2;
|
||||||
|
|
||||||
int rowY = y + rowYOffset;
|
int rowY = y + rowYOffset;
|
||||||
@ -2369,23 +2370,36 @@ static void drawMemoryScreen(OLEDDisplay *display, OLEDDisplayUiState *state, in
|
|||||||
if (total == 0) return;
|
if (total == 0) return;
|
||||||
|
|
||||||
int percent = (used * 100) / total;
|
int percent = (used * 100) / total;
|
||||||
int fillWidth = (used * barWidth) / total;
|
|
||||||
|
|
||||||
|
char combinedStr[24];
|
||||||
|
if (screenWidth > 128) {
|
||||||
|
snprintf(combinedStr, sizeof(combinedStr), "%3d%% %lu/%luKB", percent, used / 1024, total / 1024);
|
||||||
|
} else {
|
||||||
|
snprintf(combinedStr, sizeof(combinedStr), "%3d%%", percent);
|
||||||
|
}
|
||||||
|
|
||||||
|
int textWidth = display->getStringWidth(combinedStr);
|
||||||
|
int adjustedBarWidth = SCREEN_WIDTH - barX - textWidth - 6;
|
||||||
|
if (adjustedBarWidth < 10) adjustedBarWidth = 10; // prevent weird bar if display is too small
|
||||||
|
|
||||||
|
int fillWidth = (used * adjustedBarWidth) / total;
|
||||||
|
|
||||||
|
// Label
|
||||||
display->setTextAlignment(TEXT_ALIGN_LEFT);
|
display->setTextAlignment(TEXT_ALIGN_LEFT);
|
||||||
display->drawString(labelX, rowY, label);
|
display->drawString(labelX, rowY, label);
|
||||||
|
|
||||||
|
// Bar
|
||||||
int barY = rowY + (FONT_HEIGHT_SMALL - barHeight) / 2;
|
int barY = rowY + (FONT_HEIGHT_SMALL - barHeight) / 2;
|
||||||
display->setColor(WHITE);
|
display->setColor(WHITE);
|
||||||
display->drawRect(barX, barY, barWidth, barHeight);
|
display->drawRect(barX, barY, adjustedBarWidth, barHeight);
|
||||||
|
|
||||||
if (percent >= 80) display->setColor(BLACK);
|
if (percent >= 80) display->setColor(BLACK);
|
||||||
display->fillRect(barX, barY, fillWidth, barHeight);
|
display->fillRect(barX, barY, fillWidth, barHeight);
|
||||||
display->setColor(WHITE);
|
display->setColor(WHITE);
|
||||||
|
|
||||||
char percentStr[6];
|
// Value string
|
||||||
snprintf(percentStr, sizeof(percentStr), "%3d%%", percent);
|
|
||||||
display->setTextAlignment(TEXT_ALIGN_RIGHT);
|
display->setTextAlignment(TEXT_ALIGN_RIGHT);
|
||||||
display->drawString(textRightX, rowY, percentStr);
|
display->drawString(SCREEN_WIDTH - 2, rowY, combinedStr);
|
||||||
|
|
||||||
rowY += rowYOffset;
|
rowY += rowYOffset;
|
||||||
};
|
};
|
||||||
@ -2398,30 +2412,27 @@ static void drawMemoryScreen(OLEDDisplay *display, OLEDDisplayUiState *state, in
|
|||||||
uint32_t psramTotal = memGet.getPsramSize();
|
uint32_t psramTotal = memGet.getPsramSize();
|
||||||
|
|
||||||
uint32_t flashUsed = 0, flashTotal = 0;
|
uint32_t flashUsed = 0, flashTotal = 0;
|
||||||
|
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
flashUsed = FSCom.usedBytes();
|
flashUsed = FSCom.usedBytes();
|
||||||
flashTotal = FSCom.totalBytes();
|
flashTotal = FSCom.totalBytes();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAS_SDCARD
|
|
||||||
uint32_t sdUsed = 0, sdTotal = 0;
|
uint32_t sdUsed = 0, sdTotal = 0;
|
||||||
bool hasSD = SD.cardType() != CARD_NONE;
|
|
||||||
if (hasSD) {
|
|
||||||
sdUsed = SD.usedBytes();
|
|
||||||
sdTotal = SD.totalBytes();
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
bool hasSD = false;
|
bool hasSD = false;
|
||||||
uint32_t sdUsed = 0, sdTotal = 0;
|
#ifdef HAS_SDCARD
|
||||||
#endif
|
hasSD = SD.cardType() != CARD_NONE;
|
||||||
|
if (hasSD) {
|
||||||
|
sdUsed = SD.usedBytes();
|
||||||
|
sdTotal = SD.totalBytes();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// === Draw memory rows
|
// === Draw memory rows
|
||||||
drawUsageRow("Heap:", heapUsed, heapTotal);
|
drawUsageRow("Heap:", heapUsed, heapTotal);
|
||||||
drawUsageRow("PSRAM:", psramUsed, psramTotal);
|
drawUsageRow("PSRAM:", psramUsed, psramTotal);
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
if (flashTotal > 0) drawUsageRow("Flash:", flashUsed, flashTotal);
|
if (flashTotal > 0) drawUsageRow("Flash:", flashUsed, flashTotal);
|
||||||
#endif
|
#endif
|
||||||
if (hasSD && sdTotal > 0) drawUsageRow("SD:", sdUsed, sdTotal);
|
if (hasSD && sdTotal > 0) drawUsageRow("SD:", sdUsed, sdTotal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user