mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-06 23:57:39 +03:00
Improvements to button labels and navigation
This commit is contained in:
parent
e0c4648fdb
commit
7a4d2b377d
@ -17,25 +17,31 @@ constexpr int TAB_BAR_Y = 15;
|
|||||||
constexpr int CONTENT_START_Y = 60;
|
constexpr int CONTENT_START_Y = 60;
|
||||||
constexpr int LINE_HEIGHT = 30;
|
constexpr int LINE_HEIGHT = 30;
|
||||||
constexpr int LEFT_MARGIN = 20;
|
constexpr int LEFT_MARGIN = 20;
|
||||||
constexpr int RIGHT_MARGIN = 40; // Extra space for scroll indicator
|
constexpr int RIGHT_MARGIN = 40; // Extra space for scroll indicator
|
||||||
|
|
||||||
// Timing thresholds
|
// Timing thresholds
|
||||||
constexpr int SKIP_PAGE_MS = 700;
|
constexpr int SKIP_PAGE_MS = 700;
|
||||||
constexpr unsigned long GO_HOME_MS = 1000;
|
constexpr unsigned long GO_HOME_MS = 1000;
|
||||||
|
|
||||||
void sortFileList(std::vector<std::string>& strs) {
|
void sortFileList(std::vector<std::string> &strs) {
|
||||||
std::sort(begin(strs), end(strs), [](const std::string& str1, const std::string& str2) {
|
std::sort(begin(strs), end(strs),
|
||||||
if (str1.back() == '/' && str2.back() != '/') return true;
|
[](const std::string &str1, const std::string &str2) {
|
||||||
if (str1.back() != '/' && str2.back() == '/') return false;
|
if (str1.back() == '/' && str2.back() != '/')
|
||||||
return lexicographical_compare(begin(str1), end(str1), begin(str2), end(str2),
|
return true;
|
||||||
[](const char& char1, const char& char2) { return tolower(char1) < tolower(char2); });
|
if (str1.back() != '/' && str2.back() == '/')
|
||||||
});
|
return false;
|
||||||
|
return lexicographical_compare(
|
||||||
|
begin(str1), end(str1), begin(str2), end(str2),
|
||||||
|
[](const char &char1, const char &char2) {
|
||||||
|
return tolower(char1) < tolower(char2);
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
int MyLibraryActivity::getPageItems() const {
|
int MyLibraryActivity::getPageItems() const {
|
||||||
const int screenHeight = renderer.getScreenHeight();
|
const int screenHeight = renderer.getScreenHeight();
|
||||||
const int bottomBarHeight = 60; // Space for button hints
|
const int bottomBarHeight = 60; // Space for button hints
|
||||||
const int availableHeight = screenHeight - CONTENT_START_Y - bottomBarHeight;
|
const int availableHeight = screenHeight - CONTENT_START_Y - bottomBarHeight;
|
||||||
int items = availableHeight / LINE_HEIGHT;
|
int items = availableHeight / LINE_HEIGHT;
|
||||||
if (items < 1) {
|
if (items < 1) {
|
||||||
@ -54,7 +60,8 @@ int MyLibraryActivity::getCurrentItemCount() const {
|
|||||||
int MyLibraryActivity::getTotalPages() const {
|
int MyLibraryActivity::getTotalPages() const {
|
||||||
const int itemCount = getCurrentItemCount();
|
const int itemCount = getCurrentItemCount();
|
||||||
const int pageItems = getPageItems();
|
const int pageItems = getPageItems();
|
||||||
if (itemCount == 0) return 1;
|
if (itemCount == 0)
|
||||||
|
return 1;
|
||||||
return (itemCount + pageItems - 1) / pageItems;
|
return (itemCount + pageItems - 1) / pageItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,11 +73,11 @@ int MyLibraryActivity::getCurrentPage() const {
|
|||||||
void MyLibraryActivity::loadRecentBooks() {
|
void MyLibraryActivity::loadRecentBooks() {
|
||||||
bookTitles.clear();
|
bookTitles.clear();
|
||||||
bookPaths.clear();
|
bookPaths.clear();
|
||||||
const auto& books = RECENT_BOOKS.getBooks();
|
const auto &books = RECENT_BOOKS.getBooks();
|
||||||
bookTitles.reserve(books.size());
|
bookTitles.reserve(books.size());
|
||||||
bookPaths.reserve(books.size());
|
bookPaths.reserve(books.size());
|
||||||
|
|
||||||
for (const auto& path : books) {
|
for (const auto &path : books) {
|
||||||
// Skip if file no longer exists
|
// Skip if file no longer exists
|
||||||
if (!SdMan.exists(path.c_str())) {
|
if (!SdMan.exists(path.c_str())) {
|
||||||
continue;
|
continue;
|
||||||
@ -83,8 +90,10 @@ void MyLibraryActivity::loadRecentBooks() {
|
|||||||
title = title.substr(lastSlash + 1);
|
title = title.substr(lastSlash + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string ext5 = title.length() >= 5 ? title.substr(title.length() - 5) : "";
|
const std::string ext5 =
|
||||||
const std::string ext4 = title.length() >= 4 ? title.substr(title.length() - 4) : "";
|
title.length() >= 5 ? title.substr(title.length() - 5) : "";
|
||||||
|
const std::string ext4 =
|
||||||
|
title.length() >= 4 ? title.substr(title.length() - 4) : "";
|
||||||
|
|
||||||
// If epub, try to load the metadata for title
|
// If epub, try to load the metadata for title
|
||||||
if (ext5 == ".epub") {
|
if (ext5 == ".epub") {
|
||||||
@ -109,7 +118,8 @@ void MyLibraryActivity::loadFiles() {
|
|||||||
|
|
||||||
auto root = SdMan.open(basepath.c_str());
|
auto root = SdMan.open(basepath.c_str());
|
||||||
if (!root || !root.isDirectory()) {
|
if (!root || !root.isDirectory()) {
|
||||||
if (root) root.close();
|
if (root)
|
||||||
|
root.close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,8 +137,10 @@ void MyLibraryActivity::loadFiles() {
|
|||||||
files.emplace_back(std::string(name) + "/");
|
files.emplace_back(std::string(name) + "/");
|
||||||
} else {
|
} else {
|
||||||
auto filename = std::string(name);
|
auto filename = std::string(name);
|
||||||
std::string ext4 = filename.length() >= 4 ? filename.substr(filename.length() - 4) : "";
|
std::string ext4 =
|
||||||
std::string ext5 = filename.length() >= 5 ? filename.substr(filename.length() - 5) : "";
|
filename.length() >= 4 ? filename.substr(filename.length() - 4) : "";
|
||||||
|
std::string ext5 =
|
||||||
|
filename.length() >= 5 ? filename.substr(filename.length() - 5) : "";
|
||||||
if (ext5 == ".epub" || ext5 == ".xtch" || ext4 == ".xtc") {
|
if (ext5 == ".epub" || ext5 == ".xtch" || ext4 == ".xtc") {
|
||||||
files.emplace_back(filename);
|
files.emplace_back(filename);
|
||||||
}
|
}
|
||||||
@ -139,8 +151,8 @@ void MyLibraryActivity::loadFiles() {
|
|||||||
sortFileList(files);
|
sortFileList(files);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyLibraryActivity::taskTrampoline(void* param) {
|
void MyLibraryActivity::taskTrampoline(void *param) {
|
||||||
auto* self = static_cast<MyLibraryActivity*>(param);
|
auto *self = static_cast<MyLibraryActivity *>(param);
|
||||||
self->displayTaskLoop();
|
self->displayTaskLoop();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,17 +169,18 @@ void MyLibraryActivity::onEnter() {
|
|||||||
updateRequired = true;
|
updateRequired = true;
|
||||||
|
|
||||||
xTaskCreate(&MyLibraryActivity::taskTrampoline, "MyLibraryActivityTask",
|
xTaskCreate(&MyLibraryActivity::taskTrampoline, "MyLibraryActivityTask",
|
||||||
4096, // Stack size (increased for epub metadata loading)
|
4096, // Stack size (increased for epub metadata loading)
|
||||||
this, // Parameters
|
this, // Parameters
|
||||||
1, // Priority
|
1, // Priority
|
||||||
&displayTaskHandle // Task handle
|
&displayTaskHandle // Task handle
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyLibraryActivity::onExit() {
|
void MyLibraryActivity::onExit() {
|
||||||
Activity::onExit();
|
Activity::onExit();
|
||||||
|
|
||||||
// Wait until not rendering to delete task to avoid killing mid-instruction to EPD
|
// Wait until not rendering to delete task to avoid killing mid-instruction to
|
||||||
|
// EPD
|
||||||
xSemaphoreTake(renderingMutex, portMAX_DELAY);
|
xSemaphoreTake(renderingMutex, portMAX_DELAY);
|
||||||
if (displayTaskHandle) {
|
if (displayTaskHandle) {
|
||||||
vTaskDelete(displayTaskHandle);
|
vTaskDelete(displayTaskHandle);
|
||||||
@ -186,7 +199,8 @@ void MyLibraryActivity::loop() {
|
|||||||
const int pageItems = getPageItems();
|
const int pageItems = getPageItems();
|
||||||
|
|
||||||
// Long press BACK (1s+) in Files tab goes to root folder
|
// Long press BACK (1s+) in Files tab goes to root folder
|
||||||
if (currentTab == Tab::Files && mappedInput.isPressed(MappedInputManager::Button::Back) &&
|
if (currentTab == Tab::Files &&
|
||||||
|
mappedInput.isPressed(MappedInputManager::Button::Back) &&
|
||||||
mappedInput.getHeldTime() >= GO_HOME_MS) {
|
mappedInput.getHeldTime() >= GO_HOME_MS) {
|
||||||
if (basepath != "/") {
|
if (basepath != "/") {
|
||||||
basepath = "/";
|
basepath = "/";
|
||||||
@ -197,26 +211,33 @@ void MyLibraryActivity::loop() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool upReleased = mappedInput.wasReleased(MappedInputManager::Button::Up);
|
const bool upReleased =
|
||||||
const bool downReleased = mappedInput.wasReleased(MappedInputManager::Button::Down);
|
mappedInput.wasReleased(MappedInputManager::Button::Up);
|
||||||
const bool leftReleased = mappedInput.wasReleased(MappedInputManager::Button::Left);
|
const bool downReleased =
|
||||||
const bool rightReleased = mappedInput.wasReleased(MappedInputManager::Button::Right);
|
mappedInput.wasReleased(MappedInputManager::Button::Down);
|
||||||
|
const bool leftReleased =
|
||||||
|
mappedInput.wasReleased(MappedInputManager::Button::Left);
|
||||||
|
const bool rightReleased =
|
||||||
|
mappedInput.wasReleased(MappedInputManager::Button::Right);
|
||||||
|
|
||||||
const bool skipPage = mappedInput.getHeldTime() > SKIP_PAGE_MS;
|
const bool skipPage = mappedInput.getHeldTime() > SKIP_PAGE_MS;
|
||||||
|
|
||||||
// Confirm button - open selected item
|
// Confirm button - open selected item
|
||||||
if (mappedInput.wasReleased(MappedInputManager::Button::Confirm)) {
|
if (mappedInput.wasReleased(MappedInputManager::Button::Confirm)) {
|
||||||
if (currentTab == Tab::Recent) {
|
if (currentTab == Tab::Recent) {
|
||||||
if (!bookPaths.empty() && selectorIndex < static_cast<int>(bookPaths.size())) {
|
if (!bookPaths.empty() &&
|
||||||
|
selectorIndex < static_cast<int>(bookPaths.size())) {
|
||||||
onSelectBook(bookPaths[selectorIndex]);
|
onSelectBook(bookPaths[selectorIndex]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Files tab
|
// Files tab
|
||||||
if (!files.empty() && selectorIndex < static_cast<int>(files.size())) {
|
if (!files.empty() && selectorIndex < static_cast<int>(files.size())) {
|
||||||
if (basepath.back() != '/') basepath += "/";
|
if (basepath.back() != '/')
|
||||||
|
basepath += "/";
|
||||||
if (files[selectorIndex].back() == '/') {
|
if (files[selectorIndex].back() == '/') {
|
||||||
// Enter directory
|
// Enter directory
|
||||||
basepath += files[selectorIndex].substr(0, files[selectorIndex].length() - 1);
|
basepath +=
|
||||||
|
files[selectorIndex].substr(0, files[selectorIndex].length() - 1);
|
||||||
loadFiles();
|
loadFiles();
|
||||||
selectorIndex = 0;
|
selectorIndex = 0;
|
||||||
updateRequired = true;
|
updateRequired = true;
|
||||||
@ -235,7 +256,8 @@ void MyLibraryActivity::loop() {
|
|||||||
if (currentTab == Tab::Files && basepath != "/") {
|
if (currentTab == Tab::Files && basepath != "/") {
|
||||||
// Go up one directory
|
// Go up one directory
|
||||||
basepath.replace(basepath.find_last_of('/'), std::string::npos, "");
|
basepath.replace(basepath.find_last_of('/'), std::string::npos, "");
|
||||||
if (basepath.empty()) basepath = "/";
|
if (basepath.empty())
|
||||||
|
basepath = "/";
|
||||||
loadFiles();
|
loadFiles();
|
||||||
selectorIndex = 0;
|
selectorIndex = 0;
|
||||||
updateRequired = true;
|
updateRequired = true;
|
||||||
@ -269,7 +291,8 @@ void MyLibraryActivity::loop() {
|
|||||||
|
|
||||||
if (prevReleased && itemCount > 0) {
|
if (prevReleased && itemCount > 0) {
|
||||||
if (skipPage) {
|
if (skipPage) {
|
||||||
selectorIndex = ((selectorIndex / pageItems - 1) * pageItems + itemCount) % itemCount;
|
selectorIndex =
|
||||||
|
((selectorIndex / pageItems - 1) * pageItems + itemCount) % itemCount;
|
||||||
} else {
|
} else {
|
||||||
selectorIndex = (selectorIndex + itemCount - 1) % itemCount;
|
selectorIndex = (selectorIndex + itemCount - 1) % itemCount;
|
||||||
}
|
}
|
||||||
@ -300,7 +323,8 @@ void MyLibraryActivity::render() const {
|
|||||||
renderer.clearScreen();
|
renderer.clearScreen();
|
||||||
|
|
||||||
// Draw tab bar
|
// Draw tab bar
|
||||||
std::vector<TabInfo> tabs = {{"Recent", currentTab == Tab::Recent}, {"Files", currentTab == Tab::Files}};
|
std::vector<TabInfo> tabs = {{"Recent", currentTab == Tab::Recent},
|
||||||
|
{"Files", currentTab == Tab::Files}};
|
||||||
ScreenComponents::drawTabBar(renderer, TAB_BAR_Y, tabs);
|
ScreenComponents::drawTabBar(renderer, TAB_BAR_Y, tabs);
|
||||||
|
|
||||||
// Draw content based on current tab
|
// Draw content based on current tab
|
||||||
@ -312,12 +336,23 @@ void MyLibraryActivity::render() const {
|
|||||||
|
|
||||||
// Draw scroll indicator
|
// Draw scroll indicator
|
||||||
const int screenHeight = renderer.getScreenHeight();
|
const int screenHeight = renderer.getScreenHeight();
|
||||||
const int contentHeight = screenHeight - CONTENT_START_Y - 60; // 60 for bottom bar
|
const int contentHeight =
|
||||||
ScreenComponents::drawScrollIndicator(renderer, getCurrentPage(), getTotalPages(), CONTENT_START_Y, contentHeight);
|
screenHeight - CONTENT_START_Y - 60; // 60 for bottom bar
|
||||||
|
ScreenComponents::drawScrollIndicator(renderer, getCurrentPage(),
|
||||||
|
getTotalPages(), CONTENT_START_Y,
|
||||||
|
contentHeight);
|
||||||
|
|
||||||
|
// Draw side button hints (up/down navigation on right side)
|
||||||
|
// Note: text is rotated 90° CW, so ">" appears as "^" and "<" appears as "v"
|
||||||
|
renderer.drawSideButtonHints(UI_10_FONT_ID, ">", "<");
|
||||||
|
|
||||||
// Draw bottom button hints
|
// Draw bottom button hints
|
||||||
const auto labels = mappedInput.mapLabels("HOME", "OPEN", "<", ">");
|
// In Files tab, show "BACK" when in subdirectory, "HOME" when at root
|
||||||
renderer.drawButtonHints(UI_10_FONT_ID, labels.btn1, labels.btn2, labels.btn3, labels.btn4);
|
const char *backLabel =
|
||||||
|
(currentTab == Tab::Files && basepath != "/") ? "BACK" : "HOME";
|
||||||
|
const auto labels = mappedInput.mapLabels(backLabel, "OPEN", "<", ">");
|
||||||
|
renderer.drawButtonHints(UI_10_FONT_ID, labels.btn1, labels.btn2, labels.btn3,
|
||||||
|
labels.btn4);
|
||||||
|
|
||||||
renderer.displayBuffer();
|
renderer.displayBuffer();
|
||||||
}
|
}
|
||||||
@ -328,21 +363,26 @@ void MyLibraryActivity::renderRecentTab() const {
|
|||||||
const int bookCount = static_cast<int>(bookTitles.size());
|
const int bookCount = static_cast<int>(bookTitles.size());
|
||||||
|
|
||||||
if (bookCount == 0) {
|
if (bookCount == 0) {
|
||||||
renderer.drawText(UI_10_FONT_ID, LEFT_MARGIN, CONTENT_START_Y, "No recent books");
|
renderer.drawText(UI_10_FONT_ID, LEFT_MARGIN, CONTENT_START_Y,
|
||||||
|
"No recent books");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto pageStartIndex = selectorIndex / pageItems * pageItems;
|
const auto pageStartIndex = selectorIndex / pageItems * pageItems;
|
||||||
|
|
||||||
// Draw selection highlight
|
// Draw selection highlight
|
||||||
renderer.fillRect(0, CONTENT_START_Y + (selectorIndex % pageItems) * LINE_HEIGHT - 2, pageWidth - RIGHT_MARGIN,
|
renderer.fillRect(
|
||||||
LINE_HEIGHT);
|
0, CONTENT_START_Y + (selectorIndex % pageItems) * LINE_HEIGHT - 2,
|
||||||
|
pageWidth - RIGHT_MARGIN, LINE_HEIGHT);
|
||||||
|
|
||||||
// Draw items
|
// Draw items
|
||||||
for (int i = pageStartIndex; i < bookCount && i < pageStartIndex + pageItems; i++) {
|
for (int i = pageStartIndex; i < bookCount && i < pageStartIndex + pageItems;
|
||||||
auto item = renderer.truncatedText(UI_10_FONT_ID, bookTitles[i].c_str(), pageWidth - LEFT_MARGIN - RIGHT_MARGIN);
|
i++) {
|
||||||
renderer.drawText(UI_10_FONT_ID, LEFT_MARGIN, CONTENT_START_Y + (i % pageItems) * LINE_HEIGHT, item.c_str(),
|
auto item = renderer.truncatedText(UI_10_FONT_ID, bookTitles[i].c_str(),
|
||||||
i != selectorIndex);
|
pageWidth - LEFT_MARGIN - RIGHT_MARGIN);
|
||||||
|
renderer.drawText(UI_10_FONT_ID, LEFT_MARGIN,
|
||||||
|
CONTENT_START_Y + (i % pageItems) * LINE_HEIGHT,
|
||||||
|
item.c_str(), i != selectorIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -352,20 +392,25 @@ void MyLibraryActivity::renderFilesTab() const {
|
|||||||
const int fileCount = static_cast<int>(files.size());
|
const int fileCount = static_cast<int>(files.size());
|
||||||
|
|
||||||
if (fileCount == 0) {
|
if (fileCount == 0) {
|
||||||
renderer.drawText(UI_10_FONT_ID, LEFT_MARGIN, CONTENT_START_Y, "No books found");
|
renderer.drawText(UI_10_FONT_ID, LEFT_MARGIN, CONTENT_START_Y,
|
||||||
|
"No books found");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto pageStartIndex = selectorIndex / pageItems * pageItems;
|
const auto pageStartIndex = selectorIndex / pageItems * pageItems;
|
||||||
|
|
||||||
// Draw selection highlight
|
// Draw selection highlight
|
||||||
renderer.fillRect(0, CONTENT_START_Y + (selectorIndex % pageItems) * LINE_HEIGHT - 2, pageWidth - RIGHT_MARGIN,
|
renderer.fillRect(
|
||||||
LINE_HEIGHT);
|
0, CONTENT_START_Y + (selectorIndex % pageItems) * LINE_HEIGHT - 2,
|
||||||
|
pageWidth - RIGHT_MARGIN, LINE_HEIGHT);
|
||||||
|
|
||||||
// Draw items
|
// Draw items
|
||||||
for (int i = pageStartIndex; i < fileCount && i < pageStartIndex + pageItems; i++) {
|
for (int i = pageStartIndex; i < fileCount && i < pageStartIndex + pageItems;
|
||||||
auto item = renderer.truncatedText(UI_10_FONT_ID, files[i].c_str(), pageWidth - LEFT_MARGIN - RIGHT_MARGIN);
|
i++) {
|
||||||
renderer.drawText(UI_10_FONT_ID, LEFT_MARGIN, CONTENT_START_Y + (i % pageItems) * LINE_HEIGHT, item.c_str(),
|
auto item = renderer.truncatedText(UI_10_FONT_ID, files[i].c_str(),
|
||||||
i != selectorIndex);
|
pageWidth - LEFT_MARGIN - RIGHT_MARGIN);
|
||||||
|
renderer.drawText(UI_10_FONT_ID, LEFT_MARGIN,
|
||||||
|
CONTENT_START_Y + (i % pageItems) * LINE_HEIGHT,
|
||||||
|
item.c_str(), i != selectorIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user