A fork of https://github.com/crosspoint-reader/crosspoint-reader
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Reclaim space if we don't show battery Percentage (#352)

## Summary

Give space to the chapter title if we don't show battery percentage.

---

### AI Usage

While CrossPoint doesn't have restrictions on AI tools in contributing,
please be transparent about their usage as it
helps set the right context for reviewers.

Did you use AI tools to help write this code? _**NO**_

---------

Co-authored-by: Dave Allie <dave@daveallie.com>

authored by

Jonas Diemer
Dave Allie
and committed by
GitHub
87d6c032 c9b54623

+19 -5
+19 -5
src/activities/reader/EpubReaderActivity.cpp
··· 463 463 if (showChapterTitle) { 464 464 // Centered chatper title text 465 465 // Page width minus existing content with 30px padding on each side 466 - const int titleMarginLeft = 50 + 30 + orientedMarginLeft; // 50px for battery 467 - const int titleMarginRight = progressTextWidth + 30 + orientedMarginRight; 468 - const int availableTextWidth = renderer.getScreenWidth() - titleMarginLeft - titleMarginRight; 466 + const int rendererableScreenWidth = renderer.getScreenWidth() - orientedMarginLeft - orientedMarginRight; 467 + 468 + const int batterySize = showBattery ? (showBatteryPercentage ? 50 : 20) : 0; 469 + const int titleMarginLeft = batterySize + 30; 470 + const int titleMarginRight = progressTextWidth + 30; 471 + 472 + // Attempt to center title on the screen, but if title is too wide then later we will center it within the 473 + // available space. 474 + int titleMarginLeftAdjusted = std::max(titleMarginLeft, titleMarginRight); 475 + int availableTitleSpace = rendererableScreenWidth - 2 * titleMarginLeftAdjusted; 469 476 const int tocIndex = epub->getTocIndexForSpineIndex(currentSpineIndex); 470 477 471 478 std::string title; ··· 477 484 const auto tocItem = epub->getTocItem(tocIndex); 478 485 title = tocItem.title; 479 486 titleWidth = renderer.getTextWidth(SMALL_FONT_ID, title.c_str()); 480 - while (titleWidth > availableTextWidth && title.length() > 11) { 487 + if (titleWidth > availableTitleSpace) { 488 + // Not enough space to center on the screen, center it within the remaining space instead 489 + availableTitleSpace = rendererableScreenWidth - titleMarginLeft - titleMarginRight; 490 + titleMarginLeftAdjusted = titleMarginLeft; 491 + } 492 + while (titleWidth > availableTitleSpace && title.length() > 11) { 481 493 title.replace(title.length() - 8, 8, "..."); 482 494 titleWidth = renderer.getTextWidth(SMALL_FONT_ID, title.c_str()); 483 495 } 484 496 } 485 497 486 - renderer.drawText(SMALL_FONT_ID, titleMarginLeft + (availableTextWidth - titleWidth) / 2, textY, title.c_str()); 498 + renderer.drawText(SMALL_FONT_ID, 499 + titleMarginLeftAdjusted + orientedMarginLeft + (availableTitleSpace - titleWidth) / 2, textY, 500 + title.c_str()); 487 501 } 488 502 }