mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2025-12-18 15:17:42 +03:00
Return -1 from getTocIndexForSpineIndex if TOC item does not exist
This commit is contained in:
parent
5a7381a0eb
commit
ead39fd04b
@ -299,6 +299,5 @@ int Epub::getTocIndexForSpineIndex(const int spineIndex) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Serial.printf("[%lu] [EBP] TOC item not found\n", millis());
|
Serial.printf("[%lu] [EBP] TOC item not found\n", millis());
|
||||||
// not found - default to first item
|
return -1;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -328,12 +328,21 @@ void EpubReaderScreen::renderStatusBar() const {
|
|||||||
const int titleMarginLeft = 20 + percentageTextWidth + 30 + marginLeft;
|
const int titleMarginLeft = 20 + percentageTextWidth + 30 + marginLeft;
|
||||||
const int titleMarginRight = progressTextWidth + 30 + marginRight;
|
const int titleMarginRight = progressTextWidth + 30 + marginRight;
|
||||||
const int availableTextWidth = GfxRenderer::getScreenWidth() - titleMarginLeft - titleMarginRight;
|
const int availableTextWidth = GfxRenderer::getScreenWidth() - titleMarginLeft - titleMarginRight;
|
||||||
const auto tocItem = epub->getTocItem(epub->getTocIndexForSpineIndex(currentSpineIndex));
|
const int tocIndex = epub->getTocIndexForSpineIndex(currentSpineIndex);
|
||||||
auto title = tocItem.title;
|
|
||||||
int titleWidth = renderer.getTextWidth(SMALL_FONT_ID, title.c_str());
|
std::string title;
|
||||||
while (titleWidth > availableTextWidth) {
|
int titleWidth;
|
||||||
title = title.substr(0, title.length() - 8) + "...";
|
if (tocIndex == -1) {
|
||||||
|
title = "Unnamed";
|
||||||
|
titleWidth = renderer.getTextWidth(SMALL_FONT_ID, "Unnamed");
|
||||||
|
} else {
|
||||||
|
const auto tocItem = epub->getTocItem(tocIndex);
|
||||||
|
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 = title.substr(0, title.length() - 8) + "...";
|
||||||
|
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, titleMarginLeft + (availableTextWidth - titleWidth) / 2, textY, title.c_str());
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user