mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-07 08:07:40 +03:00
clang format
This commit is contained in:
parent
2f62c0bcc4
commit
958d1e032d
@ -8,12 +8,11 @@
|
|||||||
#include "Battery.h"
|
#include "Battery.h"
|
||||||
#include "fontIds.h"
|
#include "fontIds.h"
|
||||||
|
|
||||||
void ScreenComponents::drawBattery(const GfxRenderer &renderer, const int left,
|
void ScreenComponents::drawBattery(const GfxRenderer& renderer, const int left, const int top,
|
||||||
const int top, const bool showPercentage) {
|
const bool showPercentage) {
|
||||||
// Left aligned battery icon and percentage
|
// Left aligned battery icon and percentage
|
||||||
const uint16_t percentage = battery.readPercentage();
|
const uint16_t percentage = battery.readPercentage();
|
||||||
const auto percentageText =
|
const auto percentageText = showPercentage ? std::to_string(percentage) + "%" : "";
|
||||||
showPercentage ? std::to_string(percentage) + "%" : "";
|
|
||||||
renderer.drawText(SMALL_FONT_ID, left + 20, top, percentageText.c_str());
|
renderer.drawText(SMALL_FONT_ID, left + 20, top, percentageText.c_str());
|
||||||
|
|
||||||
// 1 column on left, 2 columns on right, 5 columns of battery body
|
// 1 column on left, 2 columns on right, 5 columns of battery body
|
||||||
@ -25,53 +24,46 @@ void ScreenComponents::drawBattery(const GfxRenderer &renderer, const int left,
|
|||||||
// Top line
|
// Top line
|
||||||
renderer.drawLine(x + 1, y, x + batteryWidth - 3, y);
|
renderer.drawLine(x + 1, y, x + batteryWidth - 3, y);
|
||||||
// Bottom line
|
// Bottom line
|
||||||
renderer.drawLine(x + 1, y + batteryHeight - 1, x + batteryWidth - 3,
|
renderer.drawLine(x + 1, y + batteryHeight - 1, x + batteryWidth - 3, y + batteryHeight - 1);
|
||||||
y + batteryHeight - 1);
|
|
||||||
// Left line
|
// Left line
|
||||||
renderer.drawLine(x, y + 1, x, y + batteryHeight - 2);
|
renderer.drawLine(x, y + 1, x, y + batteryHeight - 2);
|
||||||
// Battery end
|
// Battery end
|
||||||
renderer.drawLine(x + batteryWidth - 2, y + 1, x + batteryWidth - 2,
|
renderer.drawLine(x + batteryWidth - 2, y + 1, x + batteryWidth - 2, y + batteryHeight - 2);
|
||||||
y + batteryHeight - 2);
|
|
||||||
renderer.drawPixel(x + batteryWidth - 1, y + 3);
|
renderer.drawPixel(x + batteryWidth - 1, y + 3);
|
||||||
renderer.drawPixel(x + batteryWidth - 1, y + batteryHeight - 4);
|
renderer.drawPixel(x + batteryWidth - 1, y + batteryHeight - 4);
|
||||||
renderer.drawLine(x + batteryWidth - 0, y + 4, x + batteryWidth - 0,
|
renderer.drawLine(x + batteryWidth - 0, y + 4, x + batteryWidth - 0, y + batteryHeight - 5);
|
||||||
y + batteryHeight - 5);
|
|
||||||
|
|
||||||
// The +1 is to round up, so that we always fill at least one pixel
|
// The +1 is to round up, so that we always fill at least one pixel
|
||||||
int filledWidth = percentage * (batteryWidth - 5) / 100 + 1;
|
int filledWidth = percentage * (batteryWidth - 5) / 100 + 1;
|
||||||
if (filledWidth > batteryWidth - 5) {
|
if (filledWidth > batteryWidth - 5) {
|
||||||
filledWidth = batteryWidth - 5; // Ensure we don't overflow
|
filledWidth = batteryWidth - 5; // Ensure we don't overflow
|
||||||
}
|
}
|
||||||
|
|
||||||
renderer.fillRect(x + 2, y + 2, filledWidth, batteryHeight - 4);
|
renderer.fillRect(x + 2, y + 2, filledWidth, batteryHeight - 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ScreenComponents::drawTabBar(const GfxRenderer &renderer, const int y,
|
int ScreenComponents::drawTabBar(const GfxRenderer& renderer, const int y, const std::vector<TabInfo>& tabs) {
|
||||||
const std::vector<TabInfo> &tabs) {
|
constexpr int tabPadding = 20; // Horizontal padding between tabs
|
||||||
constexpr int tabPadding = 20; // Horizontal padding between tabs
|
constexpr int leftMargin = 20; // Left margin for first tab
|
||||||
constexpr int leftMargin = 20; // Left margin for first tab
|
constexpr int underlineHeight = 2; // Height of selection underline
|
||||||
constexpr int underlineHeight = 2; // Height of selection underline
|
constexpr int underlineGap = 4; // Gap between text and underline
|
||||||
constexpr int underlineGap = 4; // Gap between text and underline
|
|
||||||
|
|
||||||
const int lineHeight = renderer.getLineHeight(UI_12_FONT_ID);
|
const int lineHeight = renderer.getLineHeight(UI_12_FONT_ID);
|
||||||
const int tabBarHeight = lineHeight + underlineGap + underlineHeight;
|
const int tabBarHeight = lineHeight + underlineGap + underlineHeight;
|
||||||
|
|
||||||
int currentX = leftMargin;
|
int currentX = leftMargin;
|
||||||
|
|
||||||
for (const auto &tab : tabs) {
|
for (const auto& tab : tabs) {
|
||||||
const int textWidth = renderer.getTextWidth(
|
const int textWidth =
|
||||||
UI_12_FONT_ID, tab.label,
|
renderer.getTextWidth(UI_12_FONT_ID, tab.label, tab.selected ? EpdFontFamily::BOLD : EpdFontFamily::REGULAR);
|
||||||
tab.selected ? EpdFontFamily::BOLD : EpdFontFamily::REGULAR);
|
|
||||||
|
|
||||||
// Draw tab label
|
// Draw tab label
|
||||||
renderer.drawText(UI_12_FONT_ID, currentX, y, tab.label, true,
|
renderer.drawText(UI_12_FONT_ID, currentX, y, tab.label, true,
|
||||||
tab.selected ? EpdFontFamily::BOLD
|
tab.selected ? EpdFontFamily::BOLD : EpdFontFamily::REGULAR);
|
||||||
: EpdFontFamily::REGULAR);
|
|
||||||
|
|
||||||
// Draw underline for selected tab
|
// Draw underline for selected tab
|
||||||
if (tab.selected) {
|
if (tab.selected) {
|
||||||
renderer.fillRect(currentX, y + lineHeight + underlineGap, textWidth,
|
renderer.fillRect(currentX, y + lineHeight + underlineGap, textWidth, underlineHeight);
|
||||||
underlineHeight);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
currentX += textWidth + tabPadding;
|
currentX += textWidth + tabPadding;
|
||||||
@ -80,64 +72,53 @@ int ScreenComponents::drawTabBar(const GfxRenderer &renderer, const int y,
|
|||||||
return tabBarHeight;
|
return tabBarHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenComponents::drawScrollIndicator(const GfxRenderer &renderer,
|
void ScreenComponents::drawScrollIndicator(const GfxRenderer& renderer, const int currentPage, const int totalPages,
|
||||||
const int currentPage,
|
const int contentTop, const int contentHeight) {
|
||||||
const int totalPages,
|
|
||||||
const int contentTop,
|
|
||||||
const int contentHeight) {
|
|
||||||
if (totalPages <= 1) {
|
if (totalPages <= 1) {
|
||||||
return; // No need for indicator if only one page
|
return; // No need for indicator if only one page
|
||||||
}
|
}
|
||||||
|
|
||||||
const int screenWidth = renderer.getScreenWidth();
|
const int screenWidth = renderer.getScreenWidth();
|
||||||
constexpr int indicatorWidth = 20;
|
constexpr int indicatorWidth = 20;
|
||||||
constexpr int arrowSize = 6;
|
constexpr int arrowSize = 6;
|
||||||
constexpr int margin = 15; // Offset from right edge
|
constexpr int margin = 15; // Offset from right edge
|
||||||
|
|
||||||
const int centerX = screenWidth - indicatorWidth / 2 - margin;
|
const int centerX = screenWidth - indicatorWidth / 2 - margin;
|
||||||
const int indicatorTop =
|
const int indicatorTop = contentTop + 60; // Offset to avoid overlapping side button hints
|
||||||
contentTop + 60; // Offset to avoid overlapping side button hints
|
|
||||||
const int indicatorBottom = contentTop + contentHeight - 30;
|
const int indicatorBottom = contentTop + contentHeight - 30;
|
||||||
|
|
||||||
// Draw up arrow at top (^) - narrow point at top, wide base at bottom
|
// Draw up arrow at top (^) - narrow point at top, wide base at bottom
|
||||||
for (int i = 0; i < arrowSize; ++i) {
|
for (int i = 0; i < arrowSize; ++i) {
|
||||||
const int lineWidth = 1 + i * 2;
|
const int lineWidth = 1 + i * 2;
|
||||||
const int startX = centerX - i;
|
const int startX = centerX - i;
|
||||||
renderer.drawLine(startX, indicatorTop + i, startX + lineWidth - 1,
|
renderer.drawLine(startX, indicatorTop + i, startX + lineWidth - 1, indicatorTop + i);
|
||||||
indicatorTop + i);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw down arrow at bottom (v) - wide base at top, narrow point at bottom
|
// Draw down arrow at bottom (v) - wide base at top, narrow point at bottom
|
||||||
for (int i = 0; i < arrowSize; ++i) {
|
for (int i = 0; i < arrowSize; ++i) {
|
||||||
const int lineWidth = 1 + (arrowSize - 1 - i) * 2;
|
const int lineWidth = 1 + (arrowSize - 1 - i) * 2;
|
||||||
const int startX = centerX - (arrowSize - 1 - i);
|
const int startX = centerX - (arrowSize - 1 - i);
|
||||||
renderer.drawLine(startX, indicatorBottom - arrowSize + 1 + i,
|
renderer.drawLine(startX, indicatorBottom - arrowSize + 1 + i, startX + lineWidth - 1,
|
||||||
startX + lineWidth - 1,
|
|
||||||
indicatorBottom - arrowSize + 1 + i);
|
indicatorBottom - arrowSize + 1 + i);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw page fraction in the middle (e.g., "1/3")
|
// Draw page fraction in the middle (e.g., "1/3")
|
||||||
const std::string pageText =
|
const std::string pageText = std::to_string(currentPage) + "/" + std::to_string(totalPages);
|
||||||
std::to_string(currentPage) + "/" + std::to_string(totalPages);
|
|
||||||
const int textWidth = renderer.getTextWidth(SMALL_FONT_ID, pageText.c_str());
|
const int textWidth = renderer.getTextWidth(SMALL_FONT_ID, pageText.c_str());
|
||||||
const int textX = centerX - textWidth / 2;
|
const int textX = centerX - textWidth / 2;
|
||||||
const int textY = (indicatorTop + indicatorBottom) / 2 -
|
const int textY = (indicatorTop + indicatorBottom) / 2 - renderer.getLineHeight(SMALL_FONT_ID) / 2;
|
||||||
renderer.getLineHeight(SMALL_FONT_ID) / 2;
|
|
||||||
|
|
||||||
renderer.drawText(SMALL_FONT_ID, textX, textY, pageText.c_str());
|
renderer.drawText(SMALL_FONT_ID, textX, textY, pageText.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenComponents::drawProgressBar(const GfxRenderer &renderer, const int x,
|
void ScreenComponents::drawProgressBar(const GfxRenderer& renderer, const int x, const int y, const int width,
|
||||||
const int y, const int width,
|
const int height, const size_t current, const size_t total) {
|
||||||
const int height, const size_t current,
|
|
||||||
const size_t total) {
|
|
||||||
if (total == 0) {
|
if (total == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use 64-bit arithmetic to avoid overflow for large files
|
// Use 64-bit arithmetic to avoid overflow for large files
|
||||||
const int percent =
|
const int percent = static_cast<int>((static_cast<uint64_t>(current) * 100) / total);
|
||||||
static_cast<int>((static_cast<uint64_t>(current) * 100) / total);
|
|
||||||
|
|
||||||
// Draw outline
|
// Draw outline
|
||||||
renderer.drawRect(x, y, width, height);
|
renderer.drawRect(x, y, width, height);
|
||||||
@ -150,6 +131,5 @@ void ScreenComponents::drawProgressBar(const GfxRenderer &renderer, const int x,
|
|||||||
|
|
||||||
// Draw percentage text centered below bar
|
// Draw percentage text centered below bar
|
||||||
const std::string percentText = std::to_string(percent) + "%";
|
const std::string percentText = std::to_string(percent) + "%";
|
||||||
renderer.drawCenteredText(UI_10_FONT_ID, y + height + 15,
|
renderer.drawCenteredText(UI_10_FONT_ID, y + height + 15, percentText.c_str());
|
||||||
percentText.c_str());
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,24 +7,21 @@
|
|||||||
class GfxRenderer;
|
class GfxRenderer;
|
||||||
|
|
||||||
struct TabInfo {
|
struct TabInfo {
|
||||||
const char *label;
|
const char* label;
|
||||||
bool selected;
|
bool selected;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ScreenComponents {
|
class ScreenComponents {
|
||||||
public:
|
public:
|
||||||
static void drawBattery(const GfxRenderer &renderer, int left, int top,
|
static void drawBattery(const GfxRenderer& renderer, int left, int top, bool showPercentage = true);
|
||||||
bool showPercentage = true);
|
|
||||||
|
|
||||||
// Draw a horizontal tab bar with underline indicator for selected tab
|
// Draw a horizontal tab bar with underline indicator for selected tab
|
||||||
// Returns the height of the tab bar (for positioning content below)
|
// Returns the height of the tab bar (for positioning content below)
|
||||||
static int drawTabBar(const GfxRenderer &renderer, int y,
|
static int drawTabBar(const GfxRenderer& renderer, int y, const std::vector<TabInfo>& tabs);
|
||||||
const std::vector<TabInfo> &tabs);
|
|
||||||
|
|
||||||
// Draw a scroll/page indicator on the right side of the screen
|
// Draw a scroll/page indicator on the right side of the screen
|
||||||
// Shows up/down arrows and current page fraction (e.g., "1/3")
|
// Shows up/down arrows and current page fraction (e.g., "1/3")
|
||||||
static void drawScrollIndicator(const GfxRenderer &renderer, int currentPage,
|
static void drawScrollIndicator(const GfxRenderer& renderer, int currentPage, int totalPages, int contentTop,
|
||||||
int totalPages, int contentTop,
|
|
||||||
int contentHeight);
|
int contentHeight);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -37,7 +34,6 @@ public:
|
|||||||
* @param current Current progress value
|
* @param current Current progress value
|
||||||
* @param total Total value for 100% progress
|
* @param total Total value for 100% progress
|
||||||
*/
|
*/
|
||||||
static void drawProgressBar(const GfxRenderer &renderer, int x, int y,
|
static void drawProgressBar(const GfxRenderer& renderer, int x, int y, int width, int height, size_t current,
|
||||||
int width, int height, size_t current,
|
|
||||||
size_t total);
|
size_t total);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -16,31 +16,26 @@ 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),
|
std::sort(begin(strs), end(strs), [](const std::string& str1, const std::string& str2) {
|
||||||
[](const std::string &str1, const std::string &str2) {
|
if (str1.back() == '/' && str2.back() != '/') return true;
|
||||||
if (str1.back() == '/' && str2.back() != '/')
|
if (str1.back() != '/' && str2.back() == '/') return false;
|
||||||
return true;
|
return lexicographical_compare(
|
||||||
if (str1.back() != '/' && str2.back() == '/')
|
begin(str1), end(str1), begin(str2), end(str2),
|
||||||
return false;
|
[](const char& char1, const char& char2) { return tolower(char1) < tolower(char2); });
|
||||||
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) {
|
||||||
@ -59,8 +54,7 @@ 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)
|
if (itemCount == 0) return 1;
|
||||||
return 1;
|
|
||||||
return (itemCount + pageItems - 1) / pageItems;
|
return (itemCount + pageItems - 1) / pageItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,11 +68,11 @@ 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(std::min(books.size(), MAX_RECENT_BOOKS));
|
bookTitles.reserve(std::min(books.size(), MAX_RECENT_BOOKS));
|
||||||
bookPaths.reserve(std::min(books.size(), MAX_RECENT_BOOKS));
|
bookPaths.reserve(std::min(books.size(), MAX_RECENT_BOOKS));
|
||||||
|
|
||||||
for (const auto &path : books) {
|
for (const auto& path : books) {
|
||||||
// Limit to maximum number of recent books
|
// Limit to maximum number of recent books
|
||||||
if (bookTitles.size() >= MAX_RECENT_BOOKS) {
|
if (bookTitles.size() >= MAX_RECENT_BOOKS) {
|
||||||
break;
|
break;
|
||||||
@ -106,8 +100,7 @@ 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)
|
if (root) root.close();
|
||||||
root.close();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,10 +118,8 @@ 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 =
|
std::string ext4 = filename.length() >= 4 ? filename.substr(filename.length() - 4) : "";
|
||||||
filename.length() >= 4 ? filename.substr(filename.length() - 4) : "";
|
std::string ext5 = filename.length() >= 5 ? filename.substr(filename.length() - 5) : "";
|
||||||
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 +130,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,10 +148,10 @@ 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
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,8 +178,7 @@ 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 &&
|
if (currentTab == Tab::Files && mappedInput.isPressed(MappedInputManager::Button::Back) &&
|
||||||
mappedInput.isPressed(MappedInputManager::Button::Back) &&
|
|
||||||
mappedInput.getHeldTime() >= GO_HOME_MS) {
|
mappedInput.getHeldTime() >= GO_HOME_MS) {
|
||||||
if (basepath != "/") {
|
if (basepath != "/") {
|
||||||
basepath = "/";
|
basepath = "/";
|
||||||
@ -199,33 +189,26 @@ void MyLibraryActivity::loop() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool upReleased =
|
const bool upReleased = mappedInput.wasReleased(MappedInputManager::Button::Up);
|
||||||
mappedInput.wasReleased(MappedInputManager::Button::Up);
|
const bool downReleased = mappedInput.wasReleased(MappedInputManager::Button::Down);
|
||||||
const bool downReleased =
|
const bool leftReleased = mappedInput.wasReleased(MappedInputManager::Button::Left);
|
||||||
mappedInput.wasReleased(MappedInputManager::Button::Down);
|
const bool rightReleased = mappedInput.wasReleased(MappedInputManager::Button::Right);
|
||||||
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() &&
|
if (!bookPaths.empty() && selectorIndex < static_cast<int>(bookPaths.size())) {
|
||||||
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() != '/')
|
if (basepath.back() != '/') basepath += "/";
|
||||||
basepath += "/";
|
|
||||||
if (files[selectorIndex].back() == '/') {
|
if (files[selectorIndex].back() == '/') {
|
||||||
// Enter directory
|
// Enter directory
|
||||||
basepath +=
|
basepath += files[selectorIndex].substr(0, files[selectorIndex].length() - 1);
|
||||||
files[selectorIndex].substr(0, files[selectorIndex].length() - 1);
|
|
||||||
loadFiles();
|
loadFiles();
|
||||||
selectorIndex = 0;
|
selectorIndex = 0;
|
||||||
updateRequired = true;
|
updateRequired = true;
|
||||||
@ -244,8 +227,7 @@ 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())
|
if (basepath.empty()) basepath = "/";
|
||||||
basepath = "/";
|
|
||||||
loadFiles();
|
loadFiles();
|
||||||
selectorIndex = 0;
|
selectorIndex = 0;
|
||||||
updateRequired = true;
|
updateRequired = true;
|
||||||
@ -277,8 +259,7 @@ void MyLibraryActivity::loop() {
|
|||||||
|
|
||||||
if (prevReleased && itemCount > 0) {
|
if (prevReleased && itemCount > 0) {
|
||||||
if (skipPage) {
|
if (skipPage) {
|
||||||
selectorIndex =
|
selectorIndex = ((selectorIndex / pageItems - 1) * pageItems + itemCount) % itemCount;
|
||||||
((selectorIndex / pageItems - 1) * pageItems + itemCount) % itemCount;
|
|
||||||
} else {
|
} else {
|
||||||
selectorIndex = (selectorIndex + itemCount - 1) % itemCount;
|
selectorIndex = (selectorIndex + itemCount - 1) % itemCount;
|
||||||
}
|
}
|
||||||
@ -309,8 +290,7 @@ void MyLibraryActivity::render() const {
|
|||||||
renderer.clearScreen();
|
renderer.clearScreen();
|
||||||
|
|
||||||
// Draw tab bar
|
// Draw tab bar
|
||||||
std::vector<TabInfo> tabs = {{"Recent", currentTab == Tab::Recent},
|
std::vector<TabInfo> tabs = {{"Recent", currentTab == Tab::Recent}, {"Files", currentTab == Tab::Files}};
|
||||||
{"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
|
||||||
@ -322,11 +302,8 @@ void MyLibraryActivity::render() const {
|
|||||||
|
|
||||||
// Draw scroll indicator
|
// Draw scroll indicator
|
||||||
const int screenHeight = renderer.getScreenHeight();
|
const int screenHeight = renderer.getScreenHeight();
|
||||||
const int contentHeight =
|
const int contentHeight = screenHeight - CONTENT_START_Y - 60; // 60 for bottom bar
|
||||||
screenHeight - CONTENT_START_Y - 60; // 60 for bottom bar
|
ScreenComponents::drawScrollIndicator(renderer, getCurrentPage(), getTotalPages(), CONTENT_START_Y, contentHeight);
|
||||||
ScreenComponents::drawScrollIndicator(renderer, getCurrentPage(),
|
|
||||||
getTotalPages(), CONTENT_START_Y,
|
|
||||||
contentHeight);
|
|
||||||
|
|
||||||
// Draw side button hints (up/down navigation on right side)
|
// Draw side button hints (up/down navigation on right side)
|
||||||
// Note: text is rotated 90° CW, so ">" appears as "^" and "<" appears as "v"
|
// Note: text is rotated 90° CW, so ">" appears as "^" and "<" appears as "v"
|
||||||
@ -334,11 +311,9 @@ void MyLibraryActivity::render() const {
|
|||||||
|
|
||||||
// Draw bottom button hints
|
// Draw bottom button hints
|
||||||
// In Files tab, show "BACK" when in subdirectory, "HOME" when at root
|
// In Files tab, show "BACK" when in subdirectory, "HOME" when at root
|
||||||
const char *backLabel =
|
const char* backLabel = (currentTab == Tab::Files && basepath != "/") ? "BACK" : "HOME";
|
||||||
(currentTab == Tab::Files && basepath != "/") ? "BACK" : "HOME";
|
|
||||||
const auto labels = mappedInput.mapLabels(backLabel, "OPEN", "<", ">");
|
const auto labels = mappedInput.mapLabels(backLabel, "OPEN", "<", ">");
|
||||||
renderer.drawButtonHints(UI_10_FONT_ID, labels.btn1, labels.btn2, labels.btn3,
|
renderer.drawButtonHints(UI_10_FONT_ID, labels.btn1, labels.btn2, labels.btn3, labels.btn4);
|
||||||
labels.btn4);
|
|
||||||
|
|
||||||
renderer.displayBuffer();
|
renderer.displayBuffer();
|
||||||
}
|
}
|
||||||
@ -349,26 +324,21 @@ 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,
|
renderer.drawText(UI_10_FONT_ID, LEFT_MARGIN, CONTENT_START_Y, "No recent books");
|
||||||
"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(
|
renderer.fillRect(0, CONTENT_START_Y + (selectorIndex % pageItems) * LINE_HEIGHT - 2, pageWidth - RIGHT_MARGIN,
|
||||||
0, CONTENT_START_Y + (selectorIndex % pageItems) * LINE_HEIGHT - 2,
|
LINE_HEIGHT);
|
||||||
pageWidth - RIGHT_MARGIN, LINE_HEIGHT);
|
|
||||||
|
|
||||||
// Draw items
|
// Draw items
|
||||||
for (int i = pageStartIndex; i < bookCount && i < pageStartIndex + pageItems;
|
for (int i = pageStartIndex; i < bookCount && i < pageStartIndex + pageItems; i++) {
|
||||||
i++) {
|
auto item = renderer.truncatedText(UI_10_FONT_ID, bookTitles[i].c_str(), pageWidth - LEFT_MARGIN - RIGHT_MARGIN);
|
||||||
auto item = renderer.truncatedText(UI_10_FONT_ID, bookTitles[i].c_str(),
|
renderer.drawText(UI_10_FONT_ID, LEFT_MARGIN, CONTENT_START_Y + (i % pageItems) * LINE_HEIGHT, item.c_str(),
|
||||||
pageWidth - LEFT_MARGIN - RIGHT_MARGIN);
|
i != selectorIndex);
|
||||||
renderer.drawText(UI_10_FONT_ID, LEFT_MARGIN,
|
|
||||||
CONTENT_START_Y + (i % pageItems) * LINE_HEIGHT,
|
|
||||||
item.c_str(), i != selectorIndex);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -378,25 +348,20 @@ 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,
|
renderer.drawText(UI_10_FONT_ID, LEFT_MARGIN, CONTENT_START_Y, "No books found");
|
||||||
"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(
|
renderer.fillRect(0, CONTENT_START_Y + (selectorIndex % pageItems) * LINE_HEIGHT - 2, pageWidth - RIGHT_MARGIN,
|
||||||
0, CONTENT_START_Y + (selectorIndex % pageItems) * LINE_HEIGHT - 2,
|
LINE_HEIGHT);
|
||||||
pageWidth - RIGHT_MARGIN, LINE_HEIGHT);
|
|
||||||
|
|
||||||
// Draw items
|
// Draw items
|
||||||
for (int i = pageStartIndex; i < fileCount && i < pageStartIndex + pageItems;
|
for (int i = pageStartIndex; i < fileCount && i < pageStartIndex + pageItems; i++) {
|
||||||
i++) {
|
auto item = renderer.truncatedText(UI_10_FONT_ID, files[i].c_str(), pageWidth - LEFT_MARGIN - RIGHT_MARGIN);
|
||||||
auto item = renderer.truncatedText(UI_10_FONT_ID, files[i].c_str(),
|
renderer.drawText(UI_10_FONT_ID, LEFT_MARGIN, CONTENT_START_Y + (i % pageItems) * LINE_HEIGHT, item.c_str(),
|
||||||
pageWidth - LEFT_MARGIN - RIGHT_MARGIN);
|
i != selectorIndex);
|
||||||
renderer.drawText(UI_10_FONT_ID, LEFT_MARGIN,
|
|
||||||
CONTENT_START_Y + (i % pageItems) * LINE_HEIGHT,
|
|
||||||
item.c_str(), i != selectorIndex);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,10 +10,10 @@
|
|||||||
#include "../Activity.h"
|
#include "../Activity.h"
|
||||||
|
|
||||||
class MyLibraryActivity final : public Activity {
|
class MyLibraryActivity final : public Activity {
|
||||||
public:
|
public:
|
||||||
enum class Tab { Recent, Files };
|
enum class Tab { Recent, Files };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TaskHandle_t displayTaskHandle = nullptr;
|
TaskHandle_t displayTaskHandle = nullptr;
|
||||||
SemaphoreHandle_t renderingMutex = nullptr;
|
SemaphoreHandle_t renderingMutex = nullptr;
|
||||||
|
|
||||||
@ -22,9 +22,8 @@ private:
|
|||||||
bool updateRequired = false;
|
bool updateRequired = false;
|
||||||
|
|
||||||
// Recent tab state
|
// Recent tab state
|
||||||
std::vector<std::string> bookTitles; // Display titles for each book
|
std::vector<std::string> bookTitles; // Display titles for each book
|
||||||
std::vector<std::string>
|
std::vector<std::string> bookPaths; // Paths for each visible book (excludes missing)
|
||||||
bookPaths; // Paths for each visible book (excludes missing)
|
|
||||||
|
|
||||||
// Files tab state (from FileSelectionActivity)
|
// Files tab state (from FileSelectionActivity)
|
||||||
std::string basepath = "/";
|
std::string basepath = "/";
|
||||||
@ -32,7 +31,7 @@ private:
|
|||||||
|
|
||||||
// Callbacks
|
// Callbacks
|
||||||
const std::function<void()> onGoHome;
|
const std::function<void()> onGoHome;
|
||||||
const std::function<void(const std::string &path)> onSelectBook;
|
const std::function<void(const std::string& path)> onSelectBook;
|
||||||
|
|
||||||
// Number of items that fit on a page
|
// Number of items that fit on a page
|
||||||
int getPageItems() const;
|
int getPageItems() const;
|
||||||
@ -45,20 +44,21 @@ private:
|
|||||||
void loadFiles();
|
void loadFiles();
|
||||||
|
|
||||||
// Rendering
|
// Rendering
|
||||||
static void taskTrampoline(void *param);
|
static void taskTrampoline(void* param);
|
||||||
[[noreturn]] void displayTaskLoop();
|
[[noreturn]] void displayTaskLoop();
|
||||||
void render() const;
|
void render() const;
|
||||||
void renderRecentTab() const;
|
void renderRecentTab() const;
|
||||||
void renderFilesTab() const;
|
void renderFilesTab() const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit MyLibraryActivity(
|
explicit MyLibraryActivity(GfxRenderer& renderer, MappedInputManager& mappedInput,
|
||||||
GfxRenderer &renderer, MappedInputManager &mappedInput,
|
const std::function<void()>& onGoHome,
|
||||||
const std::function<void()> &onGoHome,
|
const std::function<void(const std::string& path)>& onSelectBook,
|
||||||
const std::function<void(const std::string &path)> &onSelectBook,
|
Tab initialTab = Tab::Recent)
|
||||||
Tab initialTab = Tab::Recent)
|
: Activity("MyLibrary", renderer, mappedInput),
|
||||||
: Activity("MyLibrary", renderer, mappedInput), currentTab(initialTab),
|
currentTab(initialTab),
|
||||||
onGoHome(onGoHome), onSelectBook(onSelectBook) {}
|
onGoHome(onGoHome),
|
||||||
|
onSelectBook(onSelectBook) {}
|
||||||
void onEnter() override;
|
void onEnter() override;
|
||||||
void onExit() override;
|
void onExit() override;
|
||||||
void loop() override;
|
void loop() override;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user