2021-06-23 19:45:38 +00:00
|
|
|
#include <gui/menus/theme.h>
|
|
|
|
#include <gui/gui.h>
|
|
|
|
#include <options.h>
|
2021-06-29 00:43:04 +00:00
|
|
|
#include <core.h>
|
2021-08-31 16:39:48 +00:00
|
|
|
#include <gui/style.h>
|
2021-06-23 19:45:38 +00: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/");
|
2021-07-09 18:24:07 +00:00
|
|
|
core::configManager.acquire();
|
2021-06-23 19:45:38 +00: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";
|
|
|
|
}
|
|
|
|
themeId = std::distance(themeNames.begin(), it);
|
2022-02-13 16:25:23 +00:00
|
|
|
applyTheme();
|
|
|
|
|
|
|
|
// Apply scaling
|
|
|
|
ImGui::GetStyle().ScaleAllSizes(style::uiScale);
|
2021-06-23 19:45:38 +00:00
|
|
|
|
|
|
|
themeNamesTxt = "";
|
|
|
|
for (auto name : themeNames) {
|
|
|
|
themeNamesTxt += name;
|
|
|
|
themeNamesTxt += '\0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-13 16:25:23 +00:00
|
|
|
void applyTheme() {
|
|
|
|
gui::themeManager.applyTheme(themeNames[themeId]);
|
|
|
|
}
|
|
|
|
|
2021-06-23 19:45:38 +00:00
|
|
|
void draw(void* ctx) {
|
|
|
|
float menuWidth = ImGui::GetContentRegionAvailWidth();
|
2021-08-31 16:39:48 +00:00
|
|
|
ImGui::LeftLabel("Theme");
|
2021-06-23 19:45:38 +00:00
|
|
|
ImGui::SetNextItemWidth(menuWidth - ImGui::GetCursorPosX());
|
|
|
|
if (ImGui::Combo("##theme_select_combo", &themeId, themeNamesTxt.c_str())) {
|
2022-02-13 16:25:23 +00:00
|
|
|
applyTheme();
|
2021-07-09 18:24:07 +00:00
|
|
|
core::configManager.acquire();
|
2021-06-23 19:45:38 +00:00
|
|
|
core::configManager.conf["theme"] = themeNames[themeId];
|
|
|
|
core::configManager.release(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|