| 45 | } |
| 46 | |
| 47 | void ThemesMenuLayout::Reload() { |
| 48 | this->themes_menu->ClearItems(); |
| 49 | this->loaded_themes.clear(); |
| 50 | |
| 51 | this->loaded_themes = cfg::FindThemes(); |
| 52 | this->loaded_themes.insert(this->loaded_themes.begin(), cfg::Theme{}); // For the "default theme" entry |
| 53 | |
| 54 | // Move active theme to top |
| 55 | for(u32 i = 0; i < this->loaded_themes.size(); i++) { |
| 56 | const auto theme = this->loaded_themes.at(i); |
| 57 | if(theme.IsSame(g_GlobalSettings.active_theme)) { |
| 58 | this->loaded_themes.erase(this->loaded_themes.begin() + i); |
| 59 | this->loaded_themes.insert(this->loaded_themes.begin(), theme); |
| 60 | break; |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | for(const auto &theme: this->loaded_themes) { |
| 65 | if(theme.IsValid()) { |
| 66 | std::string theme_icon_path; |
| 67 | const auto rc = cfg::TryCacheLoadThemeIcon(theme, theme_icon_path); |
| 68 | if(R_FAILED(rc)) { |
| 69 | UL_LOG_WARN("Theme '%s' unable to load image: %s", theme.name.c_str(), util::FormatResultDisplay(rc).c_str()); |
| 70 | } |
| 71 | |
| 72 | auto theme_icon = pu::sdl2::TextureHandle::New(pu::ui::render::LoadImageFromFile(theme_icon_path)); |
| 73 | this->loaded_theme_icons.push_back(theme_icon); |
| 74 | |
| 75 | auto theme_item = pu::ui::elm::MenuItem::New(theme.manifest.name + " (v" + theme.manifest.release + ", " + theme.manifest.author + ")"); |
| 76 | theme_item->AddOnKey(std::bind(&ThemesMenuLayout::theme_DefaultKey, this)); |
| 77 | theme_item->SetColor(g_MenuApplication->GetTextColor()); |
| 78 | theme_item->SetIcon(theme_icon); |
| 79 | this->themes_menu->AddItem(theme_item); |
| 80 | } |
| 81 | else { |
| 82 | this->loaded_theme_icons.emplace_back(); |
| 83 | auto theme_reset_item = pu::ui::elm::MenuItem::New(GetLanguageString("theme_reset")); |
| 84 | theme_reset_item->AddOnKey(std::bind(&ThemesMenuLayout::theme_DefaultKey, this)); |
| 85 | theme_reset_item->SetColor(g_MenuApplication->GetTextColor()); |
| 86 | theme_reset_item->SetIcon(GetLogoTexture()); |
| 87 | this->themes_menu->AddItem(theme_reset_item); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | this->themes_menu->SetSelectedIndex(0); |
| 92 | } |
| 93 | |
| 94 | void ThemesMenuLayout::theme_DefaultKey() { |
| 95 | const auto idx = this->themes_menu->GetSelectedIndex(); |
nothing calls this directly
no test coverage detected