feat: Recents view improvements with badges, removal, and clearing
- Add pill badge system for displaying file type and suffix tags - Add "Remove from Recents" option to remove individual books - Add "Clear All Recents" option to clear entire recents list - Add clearThumbExistsCache() for cache invalidation - Create BadgeConfig.h for customizable badge mappings - Add extractBookTags() utility for parsing filename badges - Add drawPillBadge() component for rendering badges
This commit is contained in:
@@ -31,8 +31,6 @@ std::string getMicroThumbPathForBook(const std::string& bookPath) {
|
||||
|
||||
if (StringUtils::checkFileExtension(bookPath, ".epub")) {
|
||||
return "/.crosspoint/epub_" + std::to_string(hash) + "/micro_thumb.bmp";
|
||||
} else if (StringUtils::checkFileExtension(bookPath, ".xtc") || StringUtils::checkFileExtension(bookPath, ".xtch")) {
|
||||
return "/.crosspoint/xtc_" + std::to_string(hash) + "/micro_thumb.bmp";
|
||||
} else if (StringUtils::checkFileExtension(bookPath, ".txt") || StringUtils::checkFileExtension(bookPath, ".TXT")) {
|
||||
return "/.crosspoint/txt_" + std::to_string(hash) + "/micro_thumb.bmp";
|
||||
}
|
||||
@@ -234,7 +232,7 @@ void ListViewActivity::render() const {
|
||||
}
|
||||
|
||||
// Use full width if no thumbnail
|
||||
const int availableWidth = hasThumb ? textMaxWidth : (pageWidth - LEFT_MARGIN - RIGHT_MARGIN);
|
||||
const int baseAvailableWidth = hasThumb ? textMaxWidth : (pageWidth - LEFT_MARGIN - RIGHT_MARGIN);
|
||||
|
||||
// Line 1: Title
|
||||
std::string title = book.title;
|
||||
@@ -250,12 +248,60 @@ void ListViewActivity::render() const {
|
||||
title.resize(dot);
|
||||
}
|
||||
}
|
||||
|
||||
// Extract tags for badges (only if we'll show them - when NOT selected)
|
||||
constexpr int badgeSpacing = 4; // Gap between badges
|
||||
constexpr int badgePadding = 10; // Horizontal padding inside badge (5 each side)
|
||||
constexpr int badgeToThumbGap = 8; // Gap between rightmost badge and cover art
|
||||
int totalBadgeWidth = 0;
|
||||
BookTags tags;
|
||||
|
||||
if (!isSelected) {
|
||||
tags = StringUtils::extractBookTags(book.path);
|
||||
if (!tags.extensionTag.empty()) {
|
||||
totalBadgeWidth += renderer.getTextWidth(SMALL_FONT_ID, tags.extensionTag.c_str()) + badgePadding;
|
||||
}
|
||||
if (!tags.suffixTag.empty()) {
|
||||
if (totalBadgeWidth > 0) {
|
||||
totalBadgeWidth += badgeSpacing;
|
||||
}
|
||||
totalBadgeWidth += renderer.getTextWidth(SMALL_FONT_ID, tags.suffixTag.c_str()) + badgePadding;
|
||||
}
|
||||
}
|
||||
|
||||
// When selected, use full width (no badges shown)
|
||||
// When not selected, reserve space for badges at the right edge (plus gap to thumbnail)
|
||||
const int badgeReservedWidth = totalBadgeWidth > 0 ? (totalBadgeWidth + badgeSpacing + badgeToThumbGap) : 0;
|
||||
const int availableWidth = isSelected ? baseAvailableWidth : (baseAvailableWidth - badgeReservedWidth);
|
||||
auto truncatedBookTitle = renderer.truncatedText(UI_12_FONT_ID, title.c_str(), availableWidth);
|
||||
renderer.drawText(UI_12_FONT_ID, LEFT_MARGIN, y + 2, truncatedBookTitle.c_str(), !isSelected);
|
||||
|
||||
// Draw badges right-aligned (near thumbnail or right edge) - only when NOT selected
|
||||
if (!isSelected && totalBadgeWidth > 0) {
|
||||
// Position badges at the right edge of the available text area (with gap to thumbnail)
|
||||
const int badgeAreaRight = LEFT_MARGIN + baseAvailableWidth - badgeToThumbGap;
|
||||
int badgeX = badgeAreaRight - totalBadgeWidth;
|
||||
|
||||
// Center badge vertically within title line height
|
||||
const int titleLineHeight = renderer.getLineHeight(UI_12_FONT_ID);
|
||||
const int badgeLineHeight = renderer.getLineHeight(SMALL_FONT_ID);
|
||||
const int badgeVerticalPadding = 4; // 2px padding top + bottom in badge
|
||||
const int badgeHeight = badgeLineHeight + badgeVerticalPadding;
|
||||
const int badgeY = y + 2 + (titleLineHeight - badgeHeight) / 2;
|
||||
|
||||
if (!tags.extensionTag.empty()) {
|
||||
int badgeWidth = ScreenComponents::drawPillBadge(renderer, badgeX, badgeY, tags.extensionTag.c_str(),
|
||||
SMALL_FONT_ID, false);
|
||||
badgeX += badgeWidth + badgeSpacing;
|
||||
}
|
||||
if (!tags.suffixTag.empty()) {
|
||||
ScreenComponents::drawPillBadge(renderer, badgeX, badgeY, tags.suffixTag.c_str(), SMALL_FONT_ID, false);
|
||||
}
|
||||
}
|
||||
|
||||
// Line 2: Author
|
||||
if (!book.author.empty()) {
|
||||
auto truncatedAuthor = renderer.truncatedText(UI_10_FONT_ID, book.author.c_str(), availableWidth);
|
||||
auto truncatedAuthor = renderer.truncatedText(UI_10_FONT_ID, book.author.c_str(), baseAvailableWidth);
|
||||
renderer.drawText(UI_10_FONT_ID, LEFT_MARGIN, y + 32, truncatedAuthor.c_str(), !isSelected);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user