From ed3ecfb3afbdf588e8835b4a62952d98eb3e9e96 Mon Sep 17 00:00:00 2001 From: Brackyt <60280126+Brackyt@users.noreply.github.com> Date: Sun, 25 Jan 2026 18:19:23 +0100 Subject: [PATCH] feat: better icon loading for themes --- lib/ThemeEngine/src/LayoutElements.cpp | 34 ++++++++++++++------------ lib/ThemeEngine/src/ThemeManager.cpp | 6 ++++- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/lib/ThemeEngine/src/LayoutElements.cpp b/lib/ThemeEngine/src/LayoutElements.cpp index 5b08af92..e1c8dca8 100644 --- a/lib/ThemeEngine/src/LayoutElements.cpp +++ b/lib/ThemeEngine/src/LayoutElements.cpp @@ -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* 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* 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; diff --git a/lib/ThemeEngine/src/ThemeManager.cpp b/lib/ThemeEngine/src/ThemeManager.cpp index 6e706bc4..a5f5d2c9 100644 --- a/lib/ThemeEngine/src/ThemeManager.cpp +++ b/lib/ThemeEngine/src/ThemeManager.cpp @@ -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; }