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,26 +30,28 @@ 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) { std::string path = iconName;
// Try to load as bitmap bool isPath = iconName.find('/') != std::string::npos || iconName.find('.') != std::string::npos;
std::string path = iconName;
if (path[0] != '/') {
path = ThemeManager::get().getAssetPath(iconName);
}
const std::vector<uint8_t>* data = ThemeManager::get().getCachedAsset(path); std::string assetPath = path;
if (data && !data->empty()) { if (!isPath) {
Bitmap bmp(data->data(), data->size()); assetPath = ThemeManager::get().getAssetPath(iconName + ".bmp");
if (bmp.parseHeaders() == BmpReaderError::Ok) { } else if (path[0] != '/') {
renderer.drawBitmap(bmp, absX, absY, w, h); assetPath = ThemeManager::get().getAssetPath(iconName);
markClean(); }
return;
} 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") { 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;
} }