roll home screen performance tweaks to library screens
This commit is contained in:
parent
7fce5b347d
commit
c87a06edb8
@ -13,6 +13,9 @@
|
||||
#include "fontIds.h"
|
||||
#include "util/StringUtils.h"
|
||||
|
||||
// Static thumbnail existence cache definition
|
||||
ThumbExistsCache MyLibraryActivity::thumbExistsCache[MyLibraryActivity::MAX_THUMB_CACHE];
|
||||
|
||||
namespace {
|
||||
// Layout constants
|
||||
constexpr int TAB_BAR_Y = 15;
|
||||
@ -510,15 +513,45 @@ void MyLibraryActivity::renderRecentTab() const {
|
||||
const int y = CONTENT_START_Y + (i % pageItems) * RECENTS_LINE_HEIGHT;
|
||||
const bool isSelected = (i == selectorIndex);
|
||||
|
||||
// Try to load and draw micro-thumbnail
|
||||
const std::string microThumbPath = getMicroThumbPathForBook(book.path);
|
||||
// Try to load and draw micro-thumbnail (with existence caching)
|
||||
bool hasThumb = false;
|
||||
if (!microThumbPath.empty() && SdMan.exists(microThumbPath.c_str())) {
|
||||
|
||||
// Check if we have cached existence info for this book
|
||||
ThumbExistsCache* existsCache = nullptr;
|
||||
std::string microThumbPath;
|
||||
bool thumbExists = false;
|
||||
bool existsCacheHit = false;
|
||||
|
||||
if (i < MAX_THUMB_CACHE) {
|
||||
existsCache = &thumbExistsCache[i];
|
||||
if (existsCache->checked && existsCache->bookPath == book.path) {
|
||||
// Use cached existence info
|
||||
existsCacheHit = true;
|
||||
thumbExists = existsCache->exists;
|
||||
microThumbPath = existsCache->thumbPath;
|
||||
}
|
||||
}
|
||||
|
||||
// If not cached, check existence and cache the result
|
||||
if (!existsCacheHit) {
|
||||
microThumbPath = getMicroThumbPathForBook(book.path);
|
||||
thumbExists = !microThumbPath.empty() && SdMan.exists(microThumbPath.c_str());
|
||||
|
||||
// Cache the result
|
||||
if (existsCache != nullptr) {
|
||||
existsCache->bookPath = book.path;
|
||||
existsCache->thumbPath = microThumbPath;
|
||||
existsCache->exists = thumbExists;
|
||||
existsCache->checked = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Load and render thumbnail if it exists
|
||||
if (thumbExists) {
|
||||
FsFile thumbFile;
|
||||
if (SdMan.openFileForRead("MYL", microThumbPath, thumbFile)) {
|
||||
Bitmap bitmap(thumbFile);
|
||||
if (bitmap.parseHeaders() == BmpReaderError::Ok) {
|
||||
// Calculate actual drawn size (scaled to fit within max dimensions, preserving aspect ratio)
|
||||
const int bmpW = bitmap.getWidth();
|
||||
const int bmpH = bitmap.getHeight();
|
||||
const float scaleX = static_cast<float>(MICRO_THUMB_WIDTH) / static_cast<float>(bmpW);
|
||||
@ -527,10 +560,7 @@ void MyLibraryActivity::renderRecentTab() const {
|
||||
const int drawnW = static_cast<int>(bmpW * scale);
|
||||
const int drawnH = static_cast<int>(bmpH * scale);
|
||||
|
||||
// Center thumbnail vertically within the row using actual drawn height
|
||||
const int thumbY = y + (RECENTS_LINE_HEIGHT - drawnH) / 2;
|
||||
// When selected, clear only the actual drawn area to white first
|
||||
// (drawBitmap1Bit only draws pixels, it doesn't clear, so we need the white background)
|
||||
if (isSelected) {
|
||||
renderer.fillRect(thumbX, thumbY, drawnW, drawnH, false);
|
||||
}
|
||||
|
||||
@ -10,6 +10,14 @@
|
||||
#include "../Activity.h"
|
||||
#include "RecentBooksStore.h"
|
||||
|
||||
// Cached thumbnail existence info for Recent tab
|
||||
struct ThumbExistsCache {
|
||||
std::string bookPath; // Book path this cache entry belongs to
|
||||
std::string thumbPath; // Path to micro-thumbnail (if exists)
|
||||
bool checked = false; // Whether we've checked for this book
|
||||
bool exists = false; // Whether thumbnail exists
|
||||
};
|
||||
|
||||
class MyLibraryActivity final : public Activity {
|
||||
public:
|
||||
enum class Tab { Recent, Files };
|
||||
@ -35,6 +43,10 @@ class MyLibraryActivity final : public Activity {
|
||||
// Recent tab state
|
||||
std::vector<RecentBook> recentBooks;
|
||||
|
||||
// Static thumbnail existence cache - persists across activity enter/exit
|
||||
static constexpr int MAX_THUMB_CACHE = 10;
|
||||
static ThumbExistsCache thumbExistsCache[MAX_THUMB_CACHE];
|
||||
|
||||
// Files tab state (from FileSelectionActivity)
|
||||
std::string basepath = "/";
|
||||
std::vector<std::string> files;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user