Use getContentRect for consistency

This commit is contained in:
jpirnay
2026-04-16 13:30:17 +02:00
parent 4f1ad01c7e
commit 4d28b3adad
4 changed files with 60 additions and 36 deletions
@@ -114,19 +114,24 @@ void ClockSettingsActivity::render(RenderLock&&) {
renderer.clearScreen(); renderer.clearScreen();
const auto& metrics = UITheme::getInstance().getMetrics(); const auto& metrics = UITheme::getInstance().getMetrics();
const auto pageWidth = renderer.getScreenWidth(); const Rect contentRect = UITheme::getContentRect(renderer, true, false);
const auto pageHeight = renderer.getScreenHeight();
GUI.drawHeader(renderer, Rect{0, metrics.topPadding, pageWidth, metrics.headerHeight}, tr(STR_CLOCK_SETTINGS)); GUI.drawHeader(renderer,
GUI.drawSubHeader(renderer, Rect{0, metrics.topPadding + metrics.headerHeight, pageWidth, metrics.tabBarHeight}, 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)); tr(STR_CLOCK_SETTINGS_WARNING));
const int contentTop = metrics.topPadding + metrics.headerHeight + metrics.tabBarHeight + metrics.verticalSpacing; const int contentTop =
const int contentHeight = pageHeight - contentTop - metrics.buttonHintsHeight - metrics.verticalSpacing * 2; 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( GUI.drawList(
renderer, Rect{0, contentTop, pageWidth, contentHeight}, static_cast<int>(menuItems.size()), selectedIndex, renderer, Rect(contentRect.x, contentTop, contentRect.width, contentHeight), static_cast<int>(menuItems.size()),
[this](int index) { return menuItems[index].getTitle(); }, nullptr, nullptr, selectedIndex, [this](int index) { return menuItems[index].getTitle(); }, nullptr, nullptr,
[this](int index) { [this](int index) {
const auto action = menuItems[index].action; const auto action = menuItems[index].action;
switch (action) { switch (action) {
@@ -250,30 +250,37 @@ void DetectTimezoneActivity::performDetect() {
void DetectTimezoneActivity::render(RenderLock&&) { void DetectTimezoneActivity::render(RenderLock&&) {
const auto& metrics = UITheme::getInstance().getMetrics(); const auto& metrics = UITheme::getInstance().getMetrics();
const auto pageWidth = renderer.getScreenWidth(); const Rect contentRect = UITheme::getContentRect(renderer, true, false);
const auto pageHeight = renderer.getScreenHeight(); 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(); 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) { 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(); renderer.displayBuffer();
return; return;
} }
if (state == DETECTING) { 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(); renderer.displayBuffer();
return; return;
} }
if (state == SUCCESS) { 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()) { if (!detectedTimezone.empty()) {
renderer.drawCenteredText(UI_10_FONT_ID, pageHeight / 2 + 5, detectedTimezone.c_str()); renderer.drawCenteredText(UI_10_FONT_ID, bodyRect.y + bodyRect.height / 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 + 25, dstStatusLabel());
} }
const auto labels = mappedInput.mapLabels(tr(STR_BACK), "", "", ""); const auto labels = mappedInput.mapLabels(tr(STR_BACK), "", "", "");
@@ -283,7 +290,8 @@ void DetectTimezoneActivity::render(RenderLock&&) {
} }
if (state == FAILED) { 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), "", "", ""); const auto labels = mappedInput.mapLabels(tr(STR_BACK), "", "", "");
GUI.drawButtonHints(renderer, labels.btn1, labels.btn2, labels.btn3, labels.btn4); GUI.drawButtonHints(renderer, labels.btn1, labels.btn2, labels.btn3, labels.btn4);
+12 -6
View File
@@ -108,20 +108,25 @@ void SyncTimeActivity::performSync() {
void SyncTimeActivity::render(RenderLock&&) { void SyncTimeActivity::render(RenderLock&&) {
const auto& metrics = UITheme::getInstance().getMetrics(); const auto& metrics = UITheme::getInstance().getMetrics();
const auto pageWidth = renderer.getScreenWidth(); const Rect contentRect = UITheme::getContentRect(renderer, true, false);
const auto pageHeight = renderer.getScreenHeight(); 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(); 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) { 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(); renderer.displayBuffer();
return; return;
} }
if (state == SUCCESS) { 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); renderer.drawCenteredText(UI_10_FONT_ID, y, tr(STR_TIME_SYNCED), true, EpdFontFamily::BOLD);
time_t now = HalClock::now(); time_t now = HalClock::now();
@@ -179,7 +184,8 @@ void SyncTimeActivity::render(RenderLock&&) {
} }
if (state == FAILED) { 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), "", "", ""); const auto labels = mappedInput.mapLabels(tr(STR_BACK), "", "", "");
GUI.drawButtonHints(renderer, labels.btn1, labels.btn2, labels.btn3, labels.btn4); GUI.drawButtonHints(renderer, labels.btn1, labels.btn2, labels.btn3, labels.btn4);
@@ -207,23 +207,24 @@ void WeatherSettingsActivity::render(RenderLock&&) {
renderer.clearScreen(); renderer.clearScreen();
const auto& metrics = UITheme::getInstance().getMetrics(); const auto& metrics = UITheme::getInstance().getMetrics();
const auto pageWidth = renderer.getScreenWidth(); const Rect contentRect = UITheme::getContentRect(renderer, true, false);
const auto pageHeight = renderer.getScreenHeight();
if (showingSearchResults) { if (showingSearchResults) {
// Display search results // 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)); tr(STR_WEATHER_SEARCH_RESULTS));
const int contentTop = metrics.topPadding + metrics.headerHeight + metrics.verticalSpacing; const int contentTop = contentRect.y + metrics.topPadding + metrics.headerHeight + metrics.verticalSpacing;
const int contentHeight = pageHeight - contentTop - metrics.buttonHintsHeight - metrics.verticalSpacing * 2; const int contentHeight =
contentRect.height - (metrics.topPadding + metrics.headerHeight + metrics.verticalSpacing * 2);
if (searchResults.empty()) { 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 { } else {
GUI.drawList( GUI.drawList(
renderer, Rect{0, contentTop, pageWidth, contentHeight}, static_cast<int>(searchResults.size()), renderer, Rect(contentRect.x, contentTop, contentRect.width, contentHeight),
static_cast<int>(selectedIndex), static_cast<int>(searchResults.size()), static_cast<int>(selectedIndex),
[this](int index) { [this](int index) {
const auto& r = searchResults[index]; const auto& r = searchResults[index];
std::string label = r.name; std::string label = r.name;
@@ -241,14 +242,18 @@ void WeatherSettingsActivity::render(RenderLock&&) {
} }
// Main settings menu // 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 contentTop = contentRect.y + metrics.topPadding + metrics.headerHeight + metrics.verticalSpacing;
const int contentHeight = pageHeight - contentTop - metrics.buttonHintsHeight - metrics.verticalSpacing * 2; const int contentHeight =
contentRect.height - (metrics.topPadding + metrics.headerHeight + metrics.verticalSpacing * 2);
GUI.drawList( GUI.drawList(
renderer, Rect{0, contentTop, pageWidth, contentHeight}, MENU_ITEMS, static_cast<int>(selectedIndex), renderer, Rect(contentRect.x, contentTop, contentRect.width, contentHeight), MENU_ITEMS,
[](int index) { return std::string(I18N.get(menuNames[index])); }, nullptr, nullptr, static_cast<int>(selectedIndex), [](int index) { return std::string(I18N.get(menuNames[index])); }, nullptr,
nullptr,
[this](int index) -> std::string { [this](int index) -> std::string {
switch (index) { switch (index) {
case 0: { case 0: {