mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2025-12-18 15:17:42 +03:00
Revert visible chapter toc
This commit is contained in:
parent
1e8f5b767f
commit
8d2f1de660
@ -13,41 +13,13 @@ void EpubReaderChapterSelectionScreen::taskTrampoline(void* param) {
|
|||||||
self->displayTaskLoop();
|
self->displayTaskLoop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EpubReaderChapterSelectionScreen::rebuildVisibleSpineIndices() {
|
|
||||||
visibleSpineIndices.clear();
|
|
||||||
if (!epub) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const int spineCount = epub->getSpineItemsCount();
|
|
||||||
visibleSpineIndices.reserve(spineCount);
|
|
||||||
for (int i = 0; i < spineCount; i++) {
|
|
||||||
if (epub->getTocIndexForSpineIndex(i) != -1) {
|
|
||||||
visibleSpineIndices.push_back(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void EpubReaderChapterSelectionScreen::onEnter() {
|
void EpubReaderChapterSelectionScreen::onEnter() {
|
||||||
if (!epub) {
|
if (!epub) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
renderingMutex = xSemaphoreCreateMutex();
|
renderingMutex = xSemaphoreCreateMutex();
|
||||||
rebuildVisibleSpineIndices();
|
selectorIndex = currentSpineIndex;
|
||||||
|
|
||||||
selectorIndex = 0;
|
|
||||||
if (!visibleSpineIndices.empty()) {
|
|
||||||
for (size_t i = 0; i < visibleSpineIndices.size(); i++) {
|
|
||||||
if (visibleSpineIndices[i] == currentSpineIndex) {
|
|
||||||
selectorIndex = static_cast<int>(i);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (selectorIndex >= static_cast<int>(visibleSpineIndices.size())) {
|
|
||||||
selectorIndex = static_cast<int>(visibleSpineIndices.size()) - 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Trigger first update
|
// Trigger first update
|
||||||
updateRequired = true;
|
updateRequired = true;
|
||||||
@ -68,7 +40,6 @@ void EpubReaderChapterSelectionScreen::onExit() {
|
|||||||
}
|
}
|
||||||
vSemaphoreDelete(renderingMutex);
|
vSemaphoreDelete(renderingMutex);
|
||||||
renderingMutex = nullptr;
|
renderingMutex = nullptr;
|
||||||
visibleSpineIndices.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EpubReaderChapterSelectionScreen::handleInput() {
|
void EpubReaderChapterSelectionScreen::handleInput() {
|
||||||
@ -80,53 +51,22 @@ void EpubReaderChapterSelectionScreen::handleInput() {
|
|||||||
const bool skipPage = inputManager.getHeldTime() > SKIP_PAGE_MS;
|
const bool skipPage = inputManager.getHeldTime() > SKIP_PAGE_MS;
|
||||||
|
|
||||||
if (inputManager.wasPressed(InputManager::BTN_CONFIRM)) {
|
if (inputManager.wasPressed(InputManager::BTN_CONFIRM)) {
|
||||||
if (!visibleSpineIndices.empty()) {
|
onSelectSpineIndex(selectorIndex);
|
||||||
if (selectorIndex >= static_cast<int>(visibleSpineIndices.size())) {
|
} else if (inputManager.wasPressed(InputManager::BTN_BACK)) {
|
||||||
selectorIndex = static_cast<int>(visibleSpineIndices.size()) - 1;
|
|
||||||
}
|
|
||||||
onSelectSpineIndex(visibleSpineIndices[selectorIndex]);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (inputManager.wasPressed(InputManager::BTN_BACK)) {
|
|
||||||
onGoBack();
|
onGoBack();
|
||||||
return;
|
} else if (prevReleased) {
|
||||||
}
|
|
||||||
|
|
||||||
const int chapterCount = static_cast<int>(visibleSpineIndices.size());
|
|
||||||
if (chapterCount == 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (selectorIndex >= chapterCount) {
|
|
||||||
selectorIndex = chapterCount - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (prevReleased) {
|
|
||||||
if (skipPage) {
|
if (skipPage) {
|
||||||
const int totalPages = (chapterCount + PAGE_ITEMS - 1) / PAGE_ITEMS;
|
selectorIndex =
|
||||||
int currentPage = selectorIndex / PAGE_ITEMS;
|
((selectorIndex / PAGE_ITEMS - 1) * PAGE_ITEMS + epub->getSpineItemsCount()) % epub->getSpineItemsCount();
|
||||||
currentPage = (currentPage + totalPages - 1) % totalPages;
|
|
||||||
selectorIndex = currentPage * PAGE_ITEMS;
|
|
||||||
if (selectorIndex >= chapterCount) {
|
|
||||||
selectorIndex = chapterCount - 1;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
selectorIndex = (selectorIndex + chapterCount - 1) % chapterCount;
|
selectorIndex = (selectorIndex + epub->getSpineItemsCount() - 1) % epub->getSpineItemsCount();
|
||||||
}
|
}
|
||||||
updateRequired = true;
|
updateRequired = true;
|
||||||
} else if (nextReleased) {
|
} else if (nextReleased) {
|
||||||
if (skipPage) {
|
if (skipPage) {
|
||||||
const int totalPages = (chapterCount + PAGE_ITEMS - 1) / PAGE_ITEMS;
|
selectorIndex = ((selectorIndex / PAGE_ITEMS + 1) * PAGE_ITEMS) % epub->getSpineItemsCount();
|
||||||
int currentPage = selectorIndex / PAGE_ITEMS;
|
|
||||||
currentPage = (currentPage + 1) % totalPages;
|
|
||||||
selectorIndex = currentPage * PAGE_ITEMS;
|
|
||||||
if (selectorIndex >= chapterCount) {
|
|
||||||
selectorIndex = chapterCount - 1;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
selectorIndex = (selectorIndex + 1) % chapterCount;
|
selectorIndex = (selectorIndex + 1) % epub->getSpineItemsCount();
|
||||||
}
|
}
|
||||||
updateRequired = true;
|
updateRequired = true;
|
||||||
}
|
}
|
||||||
@ -150,28 +90,17 @@ void EpubReaderChapterSelectionScreen::renderScreen() {
|
|||||||
const auto pageWidth = renderer.getScreenWidth();
|
const auto pageWidth = renderer.getScreenWidth();
|
||||||
renderer.drawCenteredText(READER_FONT_ID, 10, "Select Chapter", true, BOLD);
|
renderer.drawCenteredText(READER_FONT_ID, 10, "Select Chapter", true, BOLD);
|
||||||
|
|
||||||
const int chapterCount = static_cast<int>(visibleSpineIndices.size());
|
|
||||||
if (chapterCount == 0) {
|
|
||||||
renderer.drawText(UI_FONT_ID, 20, 60, "No chapters available");
|
|
||||||
renderer.displayBuffer();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (selectorIndex >= chapterCount) {
|
|
||||||
selectorIndex = chapterCount - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto pageStartIndex = selectorIndex / PAGE_ITEMS * PAGE_ITEMS;
|
const auto pageStartIndex = selectorIndex / PAGE_ITEMS * PAGE_ITEMS;
|
||||||
renderer.fillRect(0, 60 + (selectorIndex % PAGE_ITEMS) * 30 + 2, pageWidth - 1, 30);
|
renderer.fillRect(0, 60 + (selectorIndex % PAGE_ITEMS) * 30 + 2, pageWidth - 1, 30);
|
||||||
for (int i = pageStartIndex; i < chapterCount && i < pageStartIndex + PAGE_ITEMS; i++) {
|
for (int i = pageStartIndex; i < epub->getSpineItemsCount() && i < pageStartIndex + PAGE_ITEMS; i++) {
|
||||||
const int spineIndex = visibleSpineIndices[i];
|
const int tocIndex = epub->getTocIndexForSpineIndex(i);
|
||||||
const int tocIndex = epub->getTocIndexForSpineIndex(spineIndex);
|
|
||||||
if (tocIndex == -1) {
|
if (tocIndex == -1) {
|
||||||
continue; // Filtered chapters should not reach here, but skip defensively.
|
renderer.drawText(UI_FONT_ID, 20, 60 + (i % PAGE_ITEMS) * 30, "Unnamed", i != selectorIndex);
|
||||||
|
} else {
|
||||||
|
auto item = epub->getTocItem(tocIndex);
|
||||||
|
renderer.drawText(UI_FONT_ID, 20 + (item.level - 1) * 15, 60 + (i % PAGE_ITEMS) * 30, item.title.c_str(),
|
||||||
|
i != selectorIndex);
|
||||||
}
|
}
|
||||||
auto item = epub->getTocItem(tocIndex);
|
|
||||||
renderer.drawText(UI_FONT_ID, 20 + (item.level - 1) * 15, 60 + (i % PAGE_ITEMS) * 30, item.title.c_str(),
|
|
||||||
i != selectorIndex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
renderer.displayBuffer();
|
renderer.displayBuffer();
|
||||||
|
|||||||
@ -5,7 +5,6 @@
|
|||||||
#include <freertos/task.h>
|
#include <freertos/task.h>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "Screen.h"
|
#include "Screen.h"
|
||||||
|
|
||||||
@ -16,13 +15,11 @@ class EpubReaderChapterSelectionScreen final : public Screen {
|
|||||||
int currentSpineIndex = 0;
|
int currentSpineIndex = 0;
|
||||||
int selectorIndex = 0;
|
int selectorIndex = 0;
|
||||||
bool updateRequired = false;
|
bool updateRequired = false;
|
||||||
std::vector<int> visibleSpineIndices;
|
|
||||||
const std::function<void()> onGoBack;
|
const std::function<void()> onGoBack;
|
||||||
const std::function<void(int newSpineIndex)> onSelectSpineIndex;
|
const std::function<void(int newSpineIndex)> onSelectSpineIndex;
|
||||||
|
|
||||||
static void taskTrampoline(void* param);
|
static void taskTrampoline(void* param);
|
||||||
[[noreturn]] void displayTaskLoop();
|
[[noreturn]] void displayTaskLoop();
|
||||||
void rebuildVisibleSpineIndices();
|
|
||||||
void renderScreen();
|
void renderScreen();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user