mirror of
https://github.com/AlexandreRouma/SDRPlusPlus.git
synced 2025-06-29 22:07:51 +02:00
Added theme system
This commit is contained in:
47
core/src/gui/menus/theme.cpp
Normal file
47
core/src/gui/menus/theme.cpp
Normal file
@ -0,0 +1,47 @@
|
||||
#include <gui/menus/theme.h>
|
||||
#include <gui/gui.h>
|
||||
#include <options.h>
|
||||
#include <core.h>>
|
||||
|
||||
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.aquire();
|
||||
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();
|
||||
ImGui::Text("Theme");
|
||||
ImGui::SameLine();
|
||||
ImGui::SetNextItemWidth(menuWidth - ImGui::GetCursorPosX());
|
||||
if (ImGui::Combo("##theme_select_combo", &themeId, themeNamesTxt.c_str())) {
|
||||
gui::themeManager.applyTheme(themeNames[themeId]);
|
||||
core::configManager.aquire();
|
||||
core::configManager.conf["theme"] = themeNames[themeId];
|
||||
core::configManager.release(true);
|
||||
}
|
||||
}
|
||||
}
|
7
core/src/gui/menus/theme.h
Normal file
7
core/src/gui/menus/theme.h
Normal file
@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
|
||||
namespace thememenu {
|
||||
void init(std::string resDir);
|
||||
void draw(void* ctx);
|
||||
}
|
Reference in New Issue
Block a user