feat: better icon loading for themes

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

View File

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

View File

@ -22,7 +22,11 @@ std::string ThemeManager::getAssetPath(const std::string& assetName) {
// Check if absolute path // Check if absolute path
if (!assetName.empty() && assetName[0] == '/') return assetName; 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; return "/themes/" + currentThemeName + "/assets/" + assetName;
} }