Show end of book screen when navigating past last page

This commit is contained in:
Dave Allie 2025-12-13 20:10:38 +11:00
parent 5bae283838
commit f69fc90b5c
No known key found for this signature in database
GPG Key ID: F2FDDB3AD8D0276F

View File

@ -79,6 +79,14 @@ void EpubReaderScreen::handleInput() {
return;
}
// any botton press when at end of the book goes back to the last page
if (currentSpineIndex > 0 && currentSpineIndex >= epub->getSpineItemsCount()) {
currentSpineIndex = epub->getSpineItemsCount() - 1;
nextPageNumber = UINT16_MAX;
updateRequired = true;
return;
}
const bool skipChapter = inputManager.getHeldTime() > SKIP_CHAPTER_MS;
if (skipChapter) {
@ -143,9 +151,22 @@ void EpubReaderScreen::renderScreen() {
return;
}
if (currentSpineIndex >= epub->getSpineItemsCount() || currentSpineIndex < 0) {
// edge case handling for sub-zero spine index
if (currentSpineIndex < 0) {
currentSpineIndex = 0;
}
// based bounds of book, show end of book screen
if (currentSpineIndex > epub->getSpineItemsCount()) {
currentSpineIndex = epub->getSpineItemsCount();
}
// Show end of book screen
if (currentSpineIndex == epub->getSpineItemsCount()) {
renderer.clearScreen();
renderer.drawCenteredText(READER_FONT_ID, 300, "End of book", true, BOLD);
renderer.displayBuffer();
return;
}
if (!section) {
const auto filepath = epub->getSpineItem(currentSpineIndex);