2022-12-29 19:26:00 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <hex.hpp>
|
|
|
|
#include <hex/helpers/fs.hpp>
|
|
|
|
|
|
|
|
#include <string>
|
2023-02-16 18:06:40 +01:00
|
|
|
#include <variant>
|
2022-12-29 19:26:00 +01:00
|
|
|
|
|
|
|
#include <nlohmann/json_fwd.hpp>
|
|
|
|
#include <imgui.h>
|
|
|
|
|
|
|
|
namespace hex::api {
|
|
|
|
|
|
|
|
class ThemeManager {
|
|
|
|
public:
|
|
|
|
constexpr static auto NativeTheme = "Native";
|
|
|
|
|
2023-02-16 18:06:40 +01:00
|
|
|
using ColorMap = std::map<std::string, u32>;
|
|
|
|
|
|
|
|
struct Style {
|
|
|
|
std::variant<ImVec2*, float*> value;
|
|
|
|
float min;
|
|
|
|
float max;
|
2023-03-18 10:52:50 +01:00
|
|
|
bool needsScaling;
|
2023-02-16 18:06:40 +01:00
|
|
|
};
|
|
|
|
using StyleMap = std::map<std::string, Style>;
|
|
|
|
|
2022-12-29 19:26:00 +01:00
|
|
|
static void changeTheme(std::string name);
|
|
|
|
|
|
|
|
static void addTheme(const std::string &content);
|
2023-02-16 18:06:40 +01:00
|
|
|
static void addThemeHandler(const std::string &name, const ColorMap &colorMap, const std::function<ImColor(u32)> &getFunction, const std::function<void(u32, ImColor)> &setFunction);
|
|
|
|
static void addStyleHandler(const std::string &name, const StyleMap &styleMap);
|
2022-12-29 19:26:00 +01:00
|
|
|
|
|
|
|
static std::vector<std::string> getThemeNames();
|
|
|
|
static const std::string &getThemeImagePostfix();
|
|
|
|
|
|
|
|
static std::optional<ImColor> parseColorString(const std::string &colorString);
|
2023-01-05 09:29:16 +01:00
|
|
|
|
2023-02-16 18:06:40 +01:00
|
|
|
static nlohmann::json exportCurrentTheme(const std::string &name);
|
|
|
|
|
2023-01-05 09:29:16 +01:00
|
|
|
static void reset();
|
2023-02-16 18:06:40 +01:00
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
struct ThemeHandler {
|
|
|
|
ColorMap colorMap;
|
|
|
|
std::function<ImColor(u32)> getFunction;
|
|
|
|
std::function<void(u32, ImColor)> setFunction;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct StyleHandler {
|
|
|
|
StyleMap styleMap;
|
|
|
|
};
|
|
|
|
|
|
|
|
static std::map<std::string, ThemeHandler>& getThemeHandlers() { return s_themeHandlers; }
|
|
|
|
static std::map<std::string, StyleHandler>& getStyleHandlers() { return s_styleHandlers; }
|
|
|
|
|
2022-12-29 19:26:00 +01:00
|
|
|
private:
|
|
|
|
ThemeManager() = default;
|
|
|
|
|
2023-02-16 18:06:40 +01:00
|
|
|
|
2022-12-29 19:26:00 +01:00
|
|
|
static std::map<std::string, nlohmann::json> s_themes;
|
2023-02-16 18:06:40 +01:00
|
|
|
static std::map<std::string, ThemeHandler> s_themeHandlers;
|
|
|
|
static std::map<std::string, StyleHandler> s_styleHandlers;
|
2022-12-29 19:26:00 +01:00
|
|
|
static std::string s_imagePostfix;
|
2023-02-16 18:06:40 +01:00
|
|
|
static std::string s_currTheme;
|
2022-12-29 19:26:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|