47 lines
1.6 KiB
C++
Raw Normal View History

2021-06-23 21:45:38 +02:00
#include <gui/menus/theme.h>
#include <gui/gui.h>
#include <options.h>
#include <core.h>
2021-08-31 18:39:48 +02:00
#include <gui/style.h>
2021-06-23 21:45:38 +02:00
namespace thememenu {
int themeId;
std::vector<std::string> themeNames;
std::string themeNamesTxt;
void init(std::string resDir) {
// TODO: Not hardcode theme directory
gui::themeManager.loadThemesFromDir(resDir + "/themes/");
core::configManager.acquire();
2021-06-23 21:45:38 +02:00
std::string selectedThemeName = core::configManager.conf["theme"];
core::configManager.release();
// Select theme by name, if not available, apply Dark theme
themeNames = gui::themeManager.getThemeNames();
auto it = std::find(themeNames.begin(), themeNames.end(), selectedThemeName);
if (it == themeNames.end()) {
it = std::find(themeNames.begin(), themeNames.end(), "Dark");
selectedThemeName = "Dark";
}
gui::themeManager.applyTheme(selectedThemeName);
themeId = std::distance(themeNames.begin(), it);
themeNamesTxt = "";
for (auto name : themeNames) {
themeNamesTxt += name;
themeNamesTxt += '\0';
}
}
void draw(void* ctx) {
float menuWidth = ImGui::GetContentRegionAvailWidth();
2021-08-31 18:39:48 +02:00
ImGui::LeftLabel("Theme");
2021-06-23 21:45:38 +02:00
ImGui::SetNextItemWidth(menuWidth - ImGui::GetCursorPosX());
if (ImGui::Combo("##theme_select_combo", &themeId, themeNamesTxt.c_str())) {
gui::themeManager.applyTheme(themeNames[themeId]);
core::configManager.acquire();
2021-06-23 21:45:38 +02:00
core::configManager.conf["theme"] = themeNames[themeId];
core::configManager.release(true);
}
}
}