fix: add header bar and fix bottom spacing in BookInfo

Draw the standard header (clock, battery, title) via GUI.drawHeader().
Replace hardcoded MARGIN with theme metrics for content positioning.
Content area now starts below the header and stops above button hints
so the last lines are never obscured.

Made-with: Cursor
This commit is contained in:
cottongin
2026-03-09 03:17:49 -04:00
parent efa727eff2
commit 4c62437689
2 changed files with 34 additions and 15 deletions

View File

@@ -16,7 +16,6 @@
#include "fontIds.h"
namespace {
constexpr int MARGIN = 20;
constexpr int LABEL_VALUE_GAP = 4;
constexpr int SECTION_GAP = 14;
constexpr int MAX_WRAPPED_LINES = 60;
@@ -132,7 +131,9 @@ void BookInfoActivity::onEnter() {
void BookInfoActivity::onExit() { Activity::onExit(); }
void BookInfoActivity::buildLayout(const BookMetadataCache::BookMetadata& meta, size_t fileSize) {
const int contentW = renderer.getScreenWidth() - MARGIN * 2;
const auto& metrics = UITheme::getInstance().getMetrics();
const int sidePad = metrics.contentSidePadding;
const int contentW = renderer.getScreenWidth() - sidePad * 2;
fields.reserve(13);
auto addField = [&](const char* label, const std::string& text, bool bold, EpdFontFamily::Style style) {
@@ -181,7 +182,8 @@ void BookInfoActivity::buildLayout(const BookMetadataCache::BookMetadata& meta,
const int lineH10 = renderer.getLineHeight(UI_10_FONT_ID);
const int lineH12 = renderer.getLineHeight(UI_12_FONT_ID);
int h = MARGIN;
const int contentTop = metrics.topPadding + metrics.headerHeight + metrics.verticalSpacing;
int h = contentTop;
if (!coverBmpPath.empty()) {
FsFile file;
@@ -205,6 +207,7 @@ void BookInfoActivity::buildLayout(const BookMetadataCache::BookMetadata& meta,
h += static_cast<int>(field.lines.size()) * lineH12;
h += SECTION_GAP;
}
h += metrics.buttonHintsHeight + metrics.verticalSpacing;
contentHeight = h;
}
@@ -243,20 +246,28 @@ void BookInfoActivity::loop() {
void BookInfoActivity::render(RenderLock&&) {
renderer.clearScreen();
const auto& metrics = UITheme::getInstance().getMetrics();
const int pageW = renderer.getScreenWidth();
const int pageH = renderer.getScreenHeight();
const int sidePad = metrics.contentSidePadding;
const int lineH10 = renderer.getLineHeight(UI_10_FONT_ID);
const int lineH12 = renderer.getLineHeight(UI_12_FONT_ID);
int y = MARGIN - scrollOffset;
const int contentTop = metrics.topPadding + metrics.headerHeight + metrics.verticalSpacing;
const int contentBottom = pageH - metrics.buttonHintsHeight - metrics.verticalSpacing;
GUI.drawHeader(renderer, Rect(0, metrics.topPadding, pageW, metrics.headerHeight), tr(STR_BOOK_INFO));
int y = contentTop - scrollOffset;
// Cover image — only draw if at least partially visible
if (!coverBmpPath.empty() && coverDisplayHeight > 0) {
if (y + coverDisplayHeight > 0 && y < pageH) {
if (y + coverDisplayHeight > contentTop && y < contentBottom) {
FsFile file;
if (Storage.openFileForRead("BIF", coverBmpPath, file)) {
Bitmap bitmap(file);
if (bitmap.parseHeaders() == BmpReaderError::Ok) {
const int coverX = (renderer.getScreenWidth() - coverDisplayWidth) / 2;
renderer.drawBitmap1Bit(bitmap, coverX, y, coverDisplayWidth, std::min(coverDisplayHeight, pageH - y));
const int coverX = (pageW - coverDisplayWidth) / 2;
renderer.drawBitmap1Bit(bitmap, coverX, y, coverDisplayWidth,
std::min(coverDisplayHeight, contentBottom - y));
}
file.close();
}
@@ -265,20 +276,20 @@ void BookInfoActivity::render(RenderLock&&) {
}
for (const auto& field : fields) {
if (y >= pageH) break;
if (y >= contentBottom) break;
if (field.label) {
if (y + lineH10 > 0 && y < pageH) {
renderer.drawText(UI_10_FONT_ID, MARGIN, y, field.label, true, EpdFontFamily::BOLD);
if (y + lineH10 > contentTop && y < contentBottom) {
renderer.drawText(UI_10_FONT_ID, sidePad, y, field.label, true, EpdFontFamily::BOLD);
}
y += lineH10 + LABEL_VALUE_GAP;
}
const auto style = field.bold ? EpdFontFamily::BOLD : EpdFontFamily::REGULAR;
for (const auto& line : field.lines) {
if (y >= pageH) break;
if (y + lineH12 > 0) {
renderer.drawText(UI_12_FONT_ID, MARGIN, y, line.c_str(), true, style);
if (y >= contentBottom) break;
if (y + lineH12 > contentTop) {
renderer.drawText(UI_12_FONT_ID, sidePad, y, line.c_str(), true, style);
}
y += lineH12;
}