feat: better icon loading for themes

This commit is contained in:
Brackyt 2026-01-25 18:19:23 +01:00
parent dccd200b86
commit 40b5420e11
2 changed files with 23 additions and 17 deletions

View File

@ -30,26 +30,28 @@ void Icon::draw(const GfxRenderer& renderer, const ThemeContext& context) {
int cx = absX + w / 2;
int cy = absY + h / 2;
// Check if it's a path to a BMP file
if (iconName.find('/') != std::string::npos || iconName.find('.') != std::string::npos) {
// Try to load as bitmap
std::string path = iconName;
if (path[0] != '/') {
path = ThemeManager::get().getAssetPath(iconName);
}
// 1. Try to load as a theme asset (exact match or .bmp extension)
std::string path = iconName;
bool isPath = iconName.find('/') != std::string::npos || iconName.find('.') != std::string::npos;
const std::vector<uint8_t>* data = ThemeManager::get().getCachedAsset(path);
if (data && !data->empty()) {
Bitmap bmp(data->data(), data->size());
if (bmp.parseHeaders() == BmpReaderError::Ok) {
renderer.drawBitmap(bmp, absX, absY, w, h);
markClean();
return;
}
std::string assetPath = path;
if (!isPath) {
assetPath = ThemeManager::get().getAssetPath(iconName + ".bmp");
} else if (path[0] != '/') {
assetPath = ThemeManager::get().getAssetPath(iconName);
}
const std::vector<uint8_t>* data = ThemeManager::get().getCachedAsset(assetPath);
if (data && !data->empty()) {
Bitmap bmp(data->data(), data->size());
if (bmp.parseHeaders() == BmpReaderError::Ok) {
renderer.drawBitmap(bmp, absX, absY, w, h);
markClean();
return;
}
}
// Built-in icons (simple geometric shapes)
// 2. Built-in icons (simple geometric shapes) as fallback
if (iconName == "heart" || iconName == "favorite") {
// Simple heart shape approximation
int s = w / 4;

View File

@ -22,7 +22,11 @@ std::string ThemeManager::getAssetPath(const std::string& assetName) {
// Check if absolute path
if (!assetName.empty() && assetName[0] == '/') return assetName;
// Otherwise relative to theme assets
// Otherwise relative to theme root
std::string rootPath = "/themes/" + currentThemeName + "/" + assetName;
if (SdMan.exists(rootPath.c_str())) return rootPath;
// Fallback to assets/ subfolder
return "/themes/" + currentThemeName + "/assets/" + assetName;
}