mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-04 14:47:37 +03:00
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>
This commit is contained in:
parent
c9b5462370
commit
87d6c032a5
@ -463,9 +463,16 @@ void EpubReaderActivity::renderStatusBar(const int orientedMarginRight, const in
|
|||||||
if (showChapterTitle) {
|
if (showChapterTitle) {
|
||||||
// Centered chatper title text
|
// Centered chatper title text
|
||||||
// Page width minus existing content with 30px padding on each side
|
// Page width minus existing content with 30px padding on each side
|
||||||
const int titleMarginLeft = 50 + 30 + orientedMarginLeft; // 50px for battery
|
const int rendererableScreenWidth = renderer.getScreenWidth() - orientedMarginLeft - orientedMarginRight;
|
||||||
const int titleMarginRight = progressTextWidth + 30 + orientedMarginRight;
|
|
||||||
const int availableTextWidth = renderer.getScreenWidth() - titleMarginLeft - titleMarginRight;
|
const int batterySize = showBattery ? (showBatteryPercentage ? 50 : 20) : 0;
|
||||||
|
const int titleMarginLeft = batterySize + 30;
|
||||||
|
const int titleMarginRight = progressTextWidth + 30;
|
||||||
|
|
||||||
|
// Attempt to center title on the screen, but if title is too wide then later we will center it within the
|
||||||
|
// available space.
|
||||||
|
int titleMarginLeftAdjusted = std::max(titleMarginLeft, titleMarginRight);
|
||||||
|
int availableTitleSpace = rendererableScreenWidth - 2 * titleMarginLeftAdjusted;
|
||||||
const int tocIndex = epub->getTocIndexForSpineIndex(currentSpineIndex);
|
const int tocIndex = epub->getTocIndexForSpineIndex(currentSpineIndex);
|
||||||
|
|
||||||
std::string title;
|
std::string title;
|
||||||
@ -477,12 +484,19 @@ void EpubReaderActivity::renderStatusBar(const int orientedMarginRight, const in
|
|||||||
const auto tocItem = epub->getTocItem(tocIndex);
|
const auto tocItem = epub->getTocItem(tocIndex);
|
||||||
title = tocItem.title;
|
title = tocItem.title;
|
||||||
titleWidth = renderer.getTextWidth(SMALL_FONT_ID, title.c_str());
|
titleWidth = renderer.getTextWidth(SMALL_FONT_ID, title.c_str());
|
||||||
while (titleWidth > availableTextWidth && title.length() > 11) {
|
if (titleWidth > availableTitleSpace) {
|
||||||
|
// Not enough space to center on the screen, center it within the remaining space instead
|
||||||
|
availableTitleSpace = rendererableScreenWidth - titleMarginLeft - titleMarginRight;
|
||||||
|
titleMarginLeftAdjusted = titleMarginLeft;
|
||||||
|
}
|
||||||
|
while (titleWidth > availableTitleSpace && title.length() > 11) {
|
||||||
title.replace(title.length() - 8, 8, "...");
|
title.replace(title.length() - 8, 8, "...");
|
||||||
titleWidth = renderer.getTextWidth(SMALL_FONT_ID, title.c_str());
|
titleWidth = renderer.getTextWidth(SMALL_FONT_ID, title.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
renderer.drawText(SMALL_FONT_ID, titleMarginLeft + (availableTextWidth - titleWidth) / 2, textY, title.c_str());
|
renderer.drawText(SMALL_FONT_ID,
|
||||||
|
titleMarginLeftAdjusted + orientedMarginLeft + (availableTitleSpace - titleWidth) / 2, textY,
|
||||||
|
title.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user