From 4d28b3adad07e15b561683baf5539bc0ed6dc1bb Mon Sep 17 00:00:00 2001 From: jpirnay Date: Thu, 16 Apr 2026 13:30:17 +0200 Subject: [PATCH] Use getContentRect for consistency --- .../settings/ClockSettingsActivity.cpp | 21 ++++++++----- .../settings/DetectTimezoneActivity.cpp | 26 ++++++++++------ src/activities/settings/SyncTimeActivity.cpp | 18 +++++++---- .../weather/WeatherSettingsActivity.cpp | 31 +++++++++++-------- 4 files changed, 60 insertions(+), 36 deletions(-) diff --git a/src/activities/settings/ClockSettingsActivity.cpp b/src/activities/settings/ClockSettingsActivity.cpp index 681f2ade..0137b77a 100644 --- a/src/activities/settings/ClockSettingsActivity.cpp +++ b/src/activities/settings/ClockSettingsActivity.cpp @@ -114,19 +114,24 @@ void ClockSettingsActivity::render(RenderLock&&) { renderer.clearScreen(); const auto& metrics = UITheme::getInstance().getMetrics(); - const auto pageWidth = renderer.getScreenWidth(); - const auto pageHeight = renderer.getScreenHeight(); + const Rect contentRect = UITheme::getContentRect(renderer, true, false); - GUI.drawHeader(renderer, Rect{0, metrics.topPadding, pageWidth, metrics.headerHeight}, tr(STR_CLOCK_SETTINGS)); - GUI.drawSubHeader(renderer, Rect{0, metrics.topPadding + metrics.headerHeight, pageWidth, metrics.tabBarHeight}, + GUI.drawHeader(renderer, + Rect(contentRect.x, contentRect.y + metrics.topPadding, contentRect.width, metrics.headerHeight), + tr(STR_CLOCK_SETTINGS)); + GUI.drawSubHeader(renderer, + Rect(contentRect.x, contentRect.y + metrics.topPadding + metrics.headerHeight, contentRect.width, + metrics.tabBarHeight), tr(STR_CLOCK_SETTINGS_WARNING)); - const int contentTop = metrics.topPadding + metrics.headerHeight + metrics.tabBarHeight + metrics.verticalSpacing; - const int contentHeight = pageHeight - contentTop - metrics.buttonHintsHeight - metrics.verticalSpacing * 2; + const int contentTop = + contentRect.y + metrics.topPadding + metrics.headerHeight + metrics.tabBarHeight + metrics.verticalSpacing; + const int contentHeight = contentRect.height - (metrics.topPadding + metrics.headerHeight + metrics.tabBarHeight + + metrics.verticalSpacing * 2); GUI.drawList( - renderer, Rect{0, contentTop, pageWidth, contentHeight}, static_cast(menuItems.size()), selectedIndex, - [this](int index) { return menuItems[index].getTitle(); }, nullptr, nullptr, + renderer, Rect(contentRect.x, contentTop, contentRect.width, contentHeight), static_cast(menuItems.size()), + selectedIndex, [this](int index) { return menuItems[index].getTitle(); }, nullptr, nullptr, [this](int index) { const auto action = menuItems[index].action; switch (action) { diff --git a/src/activities/settings/DetectTimezoneActivity.cpp b/src/activities/settings/DetectTimezoneActivity.cpp index 70859b41..e5ec6a9d 100644 --- a/src/activities/settings/DetectTimezoneActivity.cpp +++ b/src/activities/settings/DetectTimezoneActivity.cpp @@ -250,30 +250,37 @@ void DetectTimezoneActivity::performDetect() { void DetectTimezoneActivity::render(RenderLock&&) { const auto& metrics = UITheme::getInstance().getMetrics(); - const auto pageWidth = renderer.getScreenWidth(); - const auto pageHeight = renderer.getScreenHeight(); + const Rect contentRect = UITheme::getContentRect(renderer, true, false); + const int headerBottom = contentRect.y + metrics.topPadding + metrics.headerHeight; + const Rect bodyRect = Rect(contentRect.x, headerBottom, contentRect.width, + contentRect.height - (metrics.topPadding + metrics.headerHeight)); renderer.clearScreen(); - GUI.drawHeader(renderer, Rect{0, metrics.topPadding, pageWidth, metrics.headerHeight}, tr(STR_DETECT_TIMEZONE)); + GUI.drawHeader(renderer, + Rect(contentRect.x, contentRect.y + metrics.topPadding, contentRect.width, metrics.headerHeight), + tr(STR_DETECT_TIMEZONE)); if (state == CONNECTING) { - renderer.drawCenteredText(UI_10_FONT_ID, pageHeight / 2, tr(STR_CONNECTING), true, EpdFontFamily::BOLD); + renderer.drawCenteredText(UI_10_FONT_ID, bodyRect.y + bodyRect.height / 2, tr(STR_CONNECTING), true, + EpdFontFamily::BOLD); renderer.displayBuffer(); return; } if (state == DETECTING) { - renderer.drawCenteredText(UI_10_FONT_ID, pageHeight / 2, tr(STR_DETECTING_TIMEZONE), true, EpdFontFamily::BOLD); + renderer.drawCenteredText(UI_10_FONT_ID, bodyRect.y + bodyRect.height / 2, tr(STR_DETECTING_TIMEZONE), true, + EpdFontFamily::BOLD); renderer.displayBuffer(); return; } if (state == SUCCESS) { - renderer.drawCenteredText(UI_10_FONT_ID, pageHeight / 2 - 20, tr(STR_TIMEZONE_DETECTED), true, EpdFontFamily::BOLD); + renderer.drawCenteredText(UI_10_FONT_ID, bodyRect.y + bodyRect.height / 2 - 20, tr(STR_TIMEZONE_DETECTED), true, + EpdFontFamily::BOLD); if (!detectedTimezone.empty()) { - renderer.drawCenteredText(UI_10_FONT_ID, pageHeight / 2 + 5, detectedTimezone.c_str()); - renderer.drawCenteredText(UI_10_FONT_ID, pageHeight / 2 + 25, dstStatusLabel()); + renderer.drawCenteredText(UI_10_FONT_ID, bodyRect.y + bodyRect.height / 2 + 5, detectedTimezone.c_str()); + renderer.drawCenteredText(UI_10_FONT_ID, bodyRect.y + bodyRect.height / 2 + 25, dstStatusLabel()); } const auto labels = mappedInput.mapLabels(tr(STR_BACK), "", "", ""); @@ -283,7 +290,8 @@ void DetectTimezoneActivity::render(RenderLock&&) { } if (state == FAILED) { - renderer.drawCenteredText(UI_10_FONT_ID, pageHeight / 2, tr(STR_TIMEZONE_DETECT_FAILED), true, EpdFontFamily::BOLD); + renderer.drawCenteredText(UI_10_FONT_ID, bodyRect.y + bodyRect.height / 2, tr(STR_TIMEZONE_DETECT_FAILED), true, + EpdFontFamily::BOLD); const auto labels = mappedInput.mapLabels(tr(STR_BACK), "", "", ""); GUI.drawButtonHints(renderer, labels.btn1, labels.btn2, labels.btn3, labels.btn4); diff --git a/src/activities/settings/SyncTimeActivity.cpp b/src/activities/settings/SyncTimeActivity.cpp index 53ae4f28..6108a3c7 100644 --- a/src/activities/settings/SyncTimeActivity.cpp +++ b/src/activities/settings/SyncTimeActivity.cpp @@ -108,20 +108,25 @@ void SyncTimeActivity::performSync() { void SyncTimeActivity::render(RenderLock&&) { const auto& metrics = UITheme::getInstance().getMetrics(); - const auto pageWidth = renderer.getScreenWidth(); - const auto pageHeight = renderer.getScreenHeight(); + const Rect contentRect = UITheme::getContentRect(renderer, true, false); + const int headerBottom = contentRect.y + metrics.topPadding + metrics.headerHeight; + const Rect bodyRect = Rect(contentRect.x, headerBottom, contentRect.width, + contentRect.height - (metrics.topPadding + metrics.headerHeight)); renderer.clearScreen(); - GUI.drawHeader(renderer, Rect{0, metrics.topPadding, pageWidth, metrics.headerHeight}, tr(STR_SYNC_TIME)); + GUI.drawHeader(renderer, + Rect(contentRect.x, contentRect.y + metrics.topPadding, contentRect.width, metrics.headerHeight), + tr(STR_SYNC_TIME)); if (state == SYNCING) { - renderer.drawCenteredText(UI_10_FONT_ID, pageHeight / 2, tr(STR_SYNCING_CLOCK), true, EpdFontFamily::BOLD); + renderer.drawCenteredText(UI_10_FONT_ID, bodyRect.y + bodyRect.height / 2, tr(STR_SYNCING_CLOCK), true, + EpdFontFamily::BOLD); renderer.displayBuffer(); return; } if (state == SUCCESS) { - int y = pageHeight / 2 - 40; + int y = bodyRect.y + bodyRect.height / 2 - 40; renderer.drawCenteredText(UI_10_FONT_ID, y, tr(STR_TIME_SYNCED), true, EpdFontFamily::BOLD); time_t now = HalClock::now(); @@ -179,7 +184,8 @@ void SyncTimeActivity::render(RenderLock&&) { } if (state == FAILED) { - renderer.drawCenteredText(UI_10_FONT_ID, pageHeight / 2, tr(STR_TIME_SYNC_FAILED), true, EpdFontFamily::BOLD); + renderer.drawCenteredText(UI_10_FONT_ID, bodyRect.y + bodyRect.height / 2, tr(STR_TIME_SYNC_FAILED), true, + EpdFontFamily::BOLD); const auto labels = mappedInput.mapLabels(tr(STR_BACK), "", "", ""); GUI.drawButtonHints(renderer, labels.btn1, labels.btn2, labels.btn3, labels.btn4); diff --git a/src/activities/weather/WeatherSettingsActivity.cpp b/src/activities/weather/WeatherSettingsActivity.cpp index 8f3fdbd4..b3b69664 100644 --- a/src/activities/weather/WeatherSettingsActivity.cpp +++ b/src/activities/weather/WeatherSettingsActivity.cpp @@ -207,23 +207,24 @@ void WeatherSettingsActivity::render(RenderLock&&) { renderer.clearScreen(); const auto& metrics = UITheme::getInstance().getMetrics(); - const auto pageWidth = renderer.getScreenWidth(); - const auto pageHeight = renderer.getScreenHeight(); + const Rect contentRect = UITheme::getContentRect(renderer, true, false); if (showingSearchResults) { // Display search results - GUI.drawHeader(renderer, Rect{0, metrics.topPadding, pageWidth, metrics.headerHeight}, + GUI.drawHeader(renderer, + Rect(contentRect.x, contentRect.y + metrics.topPadding, contentRect.width, metrics.headerHeight), tr(STR_WEATHER_SEARCH_RESULTS)); - const int contentTop = metrics.topPadding + metrics.headerHeight + metrics.verticalSpacing; - const int contentHeight = pageHeight - contentTop - metrics.buttonHintsHeight - metrics.verticalSpacing * 2; + const int contentTop = contentRect.y + metrics.topPadding + metrics.headerHeight + metrics.verticalSpacing; + const int contentHeight = + contentRect.height - (metrics.topPadding + metrics.headerHeight + metrics.verticalSpacing * 2); if (searchResults.empty()) { - renderer.drawCenteredText(UI_10_FONT_ID, pageHeight / 2, tr(STR_NO_ENTRIES)); + renderer.drawCenteredText(UI_10_FONT_ID, contentTop + contentHeight / 2, tr(STR_NO_ENTRIES)); } else { GUI.drawList( - renderer, Rect{0, contentTop, pageWidth, contentHeight}, static_cast(searchResults.size()), - static_cast(selectedIndex), + renderer, Rect(contentRect.x, contentTop, contentRect.width, contentHeight), + static_cast(searchResults.size()), static_cast(selectedIndex), [this](int index) { const auto& r = searchResults[index]; std::string label = r.name; @@ -241,14 +242,18 @@ void WeatherSettingsActivity::render(RenderLock&&) { } // Main settings menu - GUI.drawHeader(renderer, Rect{0, metrics.topPadding, pageWidth, metrics.headerHeight}, tr(STR_WEATHER_SETTINGS)); + GUI.drawHeader(renderer, + Rect(contentRect.x, contentRect.y + metrics.topPadding, contentRect.width, metrics.headerHeight), + tr(STR_WEATHER_SETTINGS)); - const int contentTop = metrics.topPadding + metrics.headerHeight + metrics.verticalSpacing; - const int contentHeight = pageHeight - contentTop - metrics.buttonHintsHeight - metrics.verticalSpacing * 2; + const int contentTop = contentRect.y + metrics.topPadding + metrics.headerHeight + metrics.verticalSpacing; + const int contentHeight = + contentRect.height - (metrics.topPadding + metrics.headerHeight + metrics.verticalSpacing * 2); GUI.drawList( - renderer, Rect{0, contentTop, pageWidth, contentHeight}, MENU_ITEMS, static_cast(selectedIndex), - [](int index) { return std::string(I18N.get(menuNames[index])); }, nullptr, nullptr, + renderer, Rect(contentRect.x, contentTop, contentRect.width, contentHeight), MENU_ITEMS, + static_cast(selectedIndex), [](int index) { return std::string(I18N.get(menuNames[index])); }, nullptr, + nullptr, [this](int index) -> std::string { switch (index) { case 0: {